Skip to content

Commit 357c47f

Browse files
committed
Don't emit code highlighting spans for things we don't style
1 parent c8a6c54 commit 357c47f

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

‎src/render_html.mjs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,14 @@ const parsers = {
5555
http: StreamLanguage.define(http).parser
5656
}
5757

58+
const styled = "keyword atom number definition variableName2 typeName comment string string2 invalid meta"
59+
.split(" ").map(n => "tok-" + n)
60+
5861
function highlight(lang, text) {
5962
let result = "", parser = parsers[lang], tree = parser ? parser.parse(text) : Tree.empty
6063
highlightCode(text, tree, classHighlighter, (code, cls) => {
6164
let esc = escape(code)
65+
cls = cls.replace(/([\w-]+)\s*/g, (m, style) => styled.includes(style) ? m : "")
6266
result += cls ? `<span class="${cls}">${esc}</span>` : esc
6367
}, () => result += "\n")
6468
return result

0 commit comments

Comments
 (0)