FIX: bypass highlighths for long code in auto mode (#28399)

Long code is considered 1000 characters atm. 10000+ characters would take seconds due to how highlightjs will consider every installed lang before choosing the best candidate.
This commit is contained in:
Joffrey JAFFEUX 2024-08-16 14:25:19 +02:00 committed by GitHub
parent 6cc100abe0
commit a59c89211b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 0 deletions

View File

@ -42,6 +42,10 @@ export default async function highlightSyntax(elem, siteSettings, session) {
}
}
if (lang === "auto" && e.innerHTML.length > 1000) {
return;
}
const canHighlight = lang && (lang === "auto" || hljs.getLanguage(lang));
if (canHighlight) {