check for code-blocks before loading highlight-js

This commit is contained in:
Joe
2021-12-30 05:00:12 +08:00
committed by Robin Ward
parent c5c216563e
commit 20de49c872

View File

@@ -11,6 +11,13 @@ export default function highlightSyntax(elem, siteSettings, session) {
const selector = siteSettings.autohighlight_all_code
? "pre code"
: "pre code[class]";
const codeblocks = elem.querySelectorAll(selector);
if (!codeblocks.length) {
return;
}
const path = session.highlightJsPath;
if (!path) {
@@ -20,7 +27,7 @@ export default function highlightSyntax(elem, siteSettings, session) {
return loadScript(path).then(() => {
customHighlightJSLanguages();
elem.querySelectorAll(selector).forEach((e) => {
codeblocks.forEach((e) => {
// Large code blocks can cause crashes or slowdowns
if (e.innerHTML.length > 30000) {
return;