feat: html code highlighter
This commit is contained in:
1 parent
2c6a95f900
commit
578ea577f0
15 files changed
+186
-22
No files matched your search
@@ -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