mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
Render codefence by codemirror rather than by hljs
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import markdownit from 'markdown-it'
|
||||
import emoji from 'markdown-it-emoji'
|
||||
import math from '@rokt33r/markdown-it-math'
|
||||
import hljs from 'highlight.js'
|
||||
import _ from 'lodash'
|
||||
|
||||
const katex = window.katex
|
||||
@@ -10,9 +9,9 @@ function createGutter (str) {
|
||||
let lc = (str.match(/\n/g) || []).length
|
||||
let lines = []
|
||||
for (let i = 1; i <= lc; i++) {
|
||||
lines.push('<span>' + i + '</span>')
|
||||
lines.push('<span class="CodeMirror-linenumber">' + i + '</span>')
|
||||
}
|
||||
return '<span class="lineNumber">' + lines.join('') + '</span>'
|
||||
return '<span class="lineNumber CodeMirror-gutters">' + lines.join('') + '</span>'
|
||||
}
|
||||
|
||||
var md = markdownit({
|
||||
@@ -21,19 +20,10 @@ var md = markdownit({
|
||||
html: true,
|
||||
xhtmlOut: true,
|
||||
highlight: function (str, lang) {
|
||||
if (lang && hljs.getLanguage(lang)) {
|
||||
try {
|
||||
return '<pre class="hljs">' +
|
||||
createGutter(str) +
|
||||
'<code>' +
|
||||
hljs.highlight(lang, str).value +
|
||||
'</code></pre>'
|
||||
} catch (e) {}
|
||||
}
|
||||
return '<pre class="hljs">' +
|
||||
return '<pre class="code">' +
|
||||
createGutter(str) +
|
||||
'<code>' +
|
||||
str.replace(/\&/g, '&').replace(/\</g, '<').replace(/\>/g, '>').replace(/\"/g, '"') +
|
||||
'<code class="' + lang + '">' +
|
||||
str +
|
||||
'</code></pre>'
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user