feat: html code highlighter

This commit is contained in:
Nicolas Giard
2018-09-16 00:35:03 -04:00
parent 2c6a95f900
commit 578ea577f0
15 changed files with 190 additions and 22 deletions

View 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')
})
}
}