wikijs-fork/server/modules/rendering/html-codehighlighter/renderer.js

15 lines
414 B
JavaScript
Raw Normal View History

2018-09-16 04:35:03 +00:00
const hljs = require('highlight.js')
module.exports = {
async init($, config) {
$('pre > code').each((idx, elm) => {
2018-09-17 02:30:24 +00:00
const codeClasses = $(elm).attr('class') || ''
if (codeClasses.indexOf('language-') < 0) {
2018-09-16 04:35:03 +00:00
const result = hljs.highlightAuto($(elm).text())
2018-09-17 02:30:24 +00:00
$(elm).addClass('language-', result.language)
2018-09-16 04:35:03 +00:00
}
2018-09-17 02:30:24 +00:00
$(elm).parent().addClass('prismjs line-numbers')
2018-09-16 04:35:03 +00:00
})
}
}