Don't highlight very short code blocks

This commit is contained in:
Cadence Ember 2020-11-05 17:57:27 +13:00
parent 1aebc2c100
commit b74f0cc0dd
Signed by: cadence
GPG key ID: BC1C2C61CF521B17

View file

@ -12,7 +12,19 @@ class HighlightedCode extends ElemJS {
this.element.appendChild(child) this.element.appendChild(child)
} }
} }
lazyLoad("./static/hljs.js").then(hljs => hljs.highlightBlock(this.element)) if (this.element.textContent.length > 80) {
/*
no need to highlight very short code blocks:
- content inside might not be code, some users still use code blocks
for plaintext quotes
- language detection will almost certainly be incorrect
- even if it's code and the language is detected, the user will
be able to mentally format small amounts of code themselves
feel free to change the threshold number
*/
lazyLoad("./static/hljs.js").then(hljs => hljs.highlightBlock(this.element))
}
} }
} }