mirror of
https://github.com/danbulant/Nertivia-Client
synced 2026-06-24 17:11:43 +00:00
highlight.js highlighting
This commit is contained in:
parent
48d8ab41f1
commit
d60c998716
3 changed files with 15 additions and 14 deletions
|
|
@ -11,6 +11,7 @@
|
||||||
"axios": "^0.18.0",
|
"axios": "^0.18.0",
|
||||||
"filesize": "^4.1.2",
|
"filesize": "^4.1.2",
|
||||||
"futoji": "^0.5.0",
|
"futoji": "^0.5.0",
|
||||||
|
"highlight.js": "^9.15.8",
|
||||||
"jquery": "^3.4.0",
|
"jquery": "^3.4.0",
|
||||||
"match-sorter": "^2.3.0",
|
"match-sorter": "^2.3.0",
|
||||||
"particles.js": "^2.0.0",
|
"particles.js": "^2.0.0",
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ import Formatter from 'futoji'
|
||||||
import twemoji from 'twemoji'
|
import twemoji from 'twemoji'
|
||||||
import emojiParser from '@/utils/emojiParser';
|
import emojiParser from '@/utils/emojiParser';
|
||||||
import config from "@/config.js";
|
import config from "@/config.js";
|
||||||
|
import hljs from 'highlight.js'
|
||||||
|
|
||||||
|
|
||||||
const futoji = new Formatter();
|
const futoji = new Formatter();
|
||||||
const emojiFormatter = new Formatter();
|
const emojiFormatter = new Formatter();
|
||||||
|
|
@ -22,7 +24,6 @@ function owo (text) {
|
||||||
return `<img class="emoji" draggable="false" alt=":${split[0]}:" src="${config.domain + "/files/" + url}">`
|
return `<img class="emoji" draggable="false" alt=":${split[0]}:" src="${config.domain + "/files/" + url}">`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
futoji.addTransformer({
|
futoji.addTransformer({
|
||||||
name: 'custom emoji',
|
name: 'custom emoji',
|
||||||
symbol: ':',
|
symbol: ':',
|
||||||
|
|
@ -36,8 +37,6 @@ futoji.addTransformer({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
futoji.addTransformer({
|
futoji.addTransformer({
|
||||||
name: 'url',
|
name: 'url',
|
||||||
open: 'http',
|
open: 'http',
|
||||||
|
|
@ -47,7 +46,6 @@ futoji.addTransformer({
|
||||||
transformer: text => '<a class="msg-link" target="_blank" href="http' + text + '">http' + text + '</a> '
|
transformer: text => '<a class="msg-link" target="_blank" href="http' + text + '">http' + text + '</a> '
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
futoji.addTransformer({
|
futoji.addTransformer({
|
||||||
name: 'bold-and-italic',
|
name: 'bold-and-italic',
|
||||||
symbol: '***',
|
symbol: '***',
|
||||||
|
|
@ -86,7 +84,7 @@ futoji.addTransformer({
|
||||||
name: 'code-block',
|
name: 'code-block',
|
||||||
symbol: '```',
|
symbol: '```',
|
||||||
recursive: false,
|
recursive: false,
|
||||||
transformer: text => `<div class="codeblock"><code>${formatCode(text).trim()}</code></div>`,
|
transformer: (text) => `<div class="codeblock"><code>${hljs.highlightAuto(formatCode(text).code).value}</code></div>`
|
||||||
})
|
})
|
||||||
|
|
||||||
futoji.addTransformer({
|
futoji.addTransformer({
|
||||||
|
|
@ -105,11 +103,8 @@ export default (message) => {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* format code to add syntax highlighting
|
* format code to get language and code
|
||||||
*/
|
*/
|
||||||
function formatCode(text) {
|
function formatCode(text) {
|
||||||
// matches if word until newline
|
// matches if word until newline
|
||||||
|
|
@ -120,14 +115,19 @@ function formatCode(text) {
|
||||||
let language = nameRegex.exec(text)[1]
|
let language = nameRegex.exec(text)[1]
|
||||||
let newText = text.replace(nameRegex, '')
|
let newText = text.replace(nameRegex, '')
|
||||||
|
|
||||||
// TODO: format newText with language
|
return {
|
||||||
|
lang: language,
|
||||||
return newText
|
code: newText
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return text
|
return {
|
||||||
|
lang: '',
|
||||||
|
code: text
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: replace with well tested / faster method
|
||||||
function escapeHtml(unsafe) {
|
function escapeHtml(unsafe) {
|
||||||
return unsafe
|
return unsafe
|
||||||
.replace(/&/g, "&")
|
.replace(/&/g, "&")
|
||||||
|
|
|
||||||
|
|
@ -4014,7 +4014,7 @@ hex-color-regex@^1.1.0:
|
||||||
resolved "https://registry.yarnpkg.com/hex-color-regex/-/hex-color-regex-1.1.0.tgz#4c06fccb4602fe2602b3c93df82d7e7dbf1a8a8e"
|
resolved "https://registry.yarnpkg.com/hex-color-regex/-/hex-color-regex-1.1.0.tgz#4c06fccb4602fe2602b3c93df82d7e7dbf1a8a8e"
|
||||||
integrity sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ==
|
integrity sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ==
|
||||||
|
|
||||||
highlight.js@^9.6.0:
|
highlight.js@^9.15.8, highlight.js@^9.6.0:
|
||||||
version "9.15.8"
|
version "9.15.8"
|
||||||
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.15.8.tgz#f344fda123f36f1a65490e932cf90569e4999971"
|
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.15.8.tgz#f344fda123f36f1a65490e932cf90569e4999971"
|
||||||
integrity sha512-RrapkKQWwE+wKdF73VsOa2RQdIoO3mxwJ4P8mhbI6KYJUraUHRKM5w5zQQKXNk0xNL4UVRdulV9SBJcmzJNzVA==
|
integrity sha512-RrapkKQWwE+wKdF73VsOa2RQdIoO3mxwJ4P8mhbI6KYJUraUHRKM5w5zQQKXNk0xNL4UVRdulV9SBJcmzJNzVA==
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue