mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
check for code-blocks before loading highlight-js
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user