mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
refactor file structure
This commit is contained in:
38
browser/lib/markdown.js
Normal file
38
browser/lib/markdown.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import markdownit from 'markdown-it'
|
||||
import hljs from 'highlight.js'
|
||||
import emoji from 'markdown-it-emoji'
|
||||
|
||||
var md = markdownit({
|
||||
typographer: true,
|
||||
linkify: true,
|
||||
highlight: function (str, lang) {
|
||||
if (lang && hljs.getLanguage(lang)) {
|
||||
try {
|
||||
return hljs.highlight(lang, str).value
|
||||
} catch (__) {}
|
||||
}
|
||||
|
||||
try {
|
||||
return hljs.highlightAuto(str).value
|
||||
} catch (__) {}
|
||||
|
||||
return ''
|
||||
}
|
||||
})
|
||||
md.use(emoji)
|
||||
|
||||
let originalRenderToken = md.renderer.renderToken
|
||||
md.renderer.renderToken = function renderToken (tokens, idx, options) {
|
||||
let token = tokens[idx]
|
||||
let result = originalRenderToken.call(md.renderer, tokens, idx, options)
|
||||
if (token.map != null) {
|
||||
return result + '<a class=\'lineAnchor\' data-key=\'' + token.map[0] + '\'></a>'
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export default function markdown (content) {
|
||||
if (content == null) content = ''
|
||||
|
||||
return md.render(content.toString())
|
||||
}
|
||||
Reference in New Issue
Block a user