feat: code highlighting client-side
This commit is contained in:
1 parent
1bc98068e9
commit
d393a95495
6 files changed
+32
-81
No files matched your search
@@ -1,6 +1,6 @@
|
||||
key: htmlCodehighlighter
|
||||
title: Code Highlighting
|
||||
description: Syntax highlighter for programming code
|
||||
title: Code Highlighting Post-Processor
|
||||
description: Syntax detector for programming code
|
||||
author: requarks.io
|
||||
icon: palette
|
||||
enabledDefault: true
|
||||
|
||||
@@ -3,15 +3,12 @@ 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 codeClasses = $(elm).attr('class') || ''
|
||||
if (codeClasses.indexOf('language-') < 0) {
|
||||
const result = hljs.highlightAuto($(elm).text())
|
||||
$(elm).html(result.value)
|
||||
$(elm).attr('lang', result.language)
|
||||
$(elm).addClass('language-', result.language)
|
||||
}
|
||||
$(elm).parent().addClass('hljs')
|
||||
$(elm).parent().addClass('prismjs line-numbers')
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user