mirror of
https://github.com/danbulant/Nertivia-Client
synced 2026-05-22 05:38:47 +00:00
added support for future syntax highlighting of code-blocks
This commit is contained in:
parent
7d4df3fd5d
commit
0945ede8d1
1 changed files with 21 additions and 1 deletions
|
|
@ -41,7 +41,7 @@ export default (message) => {
|
|||
name: 'code-block',
|
||||
symbol: '``\`',
|
||||
recursive: false,
|
||||
transformer: text => `<div class="codeblock"><code>${text.trim()}</code></div>`,
|
||||
transformer: text => `<div class="codeblock"><code>${formatCode(text.trim())}</code></div>`,
|
||||
})
|
||||
|
||||
futoji.addTransformer({
|
||||
|
|
@ -53,6 +53,26 @@ export default (message) => {
|
|||
return futoji.format(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* format code to add syntax highlighting
|
||||
*/
|
||||
function formatCode(text) {
|
||||
// matches if word until newline
|
||||
// if spaces then it won't match
|
||||
let nameRegex = new RegExp('^(\\w+)\\n')
|
||||
|
||||
if(nameRegex.test(text)) {
|
||||
let language = nameRegex.exec(text)[1]
|
||||
let newText = text.replace(nameRegex, '')
|
||||
|
||||
// TODO: format newText with language
|
||||
|
||||
return newText
|
||||
}
|
||||
|
||||
return text
|
||||
}
|
||||
|
||||
function escapeHtml(unsafe) {
|
||||
return unsafe
|
||||
.replace(/&/g, "&")
|
||||
|
|
|
|||
Loading…
Reference in a new issue