feat: html code highlighter
This commit is contained in:
17
server/modules/rendering/html-codehighlighter/renderer.js
Normal file
17
server/modules/rendering/html-codehighlighter/renderer.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const hljs = require('highlight.js')
|
||||
|
||||
module.exports = {
|
||||
async init($, config) {
|
||||
$('pre > code').each((idx, elm) => {
|
||||
const lang = $(elm).attr('lang')
|
||||
if (lang) {
|
||||
$(elm).html(hljs.highlight(lang, $(elm).text(), true).value)
|
||||
} else {
|
||||
const result = hljs.highlightAuto($(elm).text())
|
||||
$(elm).html(result.value)
|
||||
$(elm).attr('lang', result.language)
|
||||
}
|
||||
$(elm).parent().addClass('hljs')
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user