Skip to content

Commit 4cc3b96

Browse files
committed
Remove DOMContentLoaded defer for Highlight.js
1 parent 91a69ea commit 4cc3b96

File tree

1 file changed

+17
-27
lines changed

1 file changed

+17
-27
lines changed

assets/ntdoc.js

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,21 @@
3030
console.error(e);
3131
}
3232

33-
// Highlight.js is deferred to run after DOMContentLoaded. Wait for it
34-
// to make sure it runs synchronously, so that tooltips can be added to
35-
// code elements after they are highlighted.
36-
if (document.readyState === 'loading') {
37-
window.addEventListener('DOMContentLoaded', highlightCodeAndAddTooltips);
38-
} else {
39-
highlightCodeAndAddTooltips();
33+
// Highlight.js, must run before tippy to allow tooltips in code.
34+
try {
35+
if (typeof hljs !== 'undefined') {
36+
highlightCode();
37+
}
38+
} catch (e) {
39+
console.error(e);
40+
}
41+
42+
try {
43+
if (typeof tippy !== 'undefined') {
44+
addTooltips();
45+
}
46+
} catch (e) {
47+
console.error(e);
4048
}
4149
}
4250

@@ -263,25 +271,6 @@
263271
descriptionsContainer.prepend(selectElement);
264272
}
265273

266-
function highlightCodeAndAddTooltips() {
267-
// Highlight.js, must run before tippy to allow tooltips in code.
268-
try {
269-
if (typeof hljs !== 'undefined') {
270-
highlightCode();
271-
}
272-
} catch (e) {
273-
console.error(e);
274-
}
275-
276-
try {
277-
if (typeof tippy !== 'undefined') {
278-
addTooltips();
279-
}
280-
} catch (e) {
281-
console.error(e);
282-
}
283-
}
284-
285274
function highlightCode() {
286275
const cssSelector = [
287276
'pre code[class^="language-"]',
@@ -299,7 +288,8 @@
299288

300289
hljs.addPlugin(hljsMergeHTMLPlugin());
301290

302-
hljs.highlightAll();
291+
const blocks = document.querySelectorAll(cssSelector);
292+
blocks.forEach(hljs.highlightElement);
303293
}
304294

305295
function addTooltips() {

0 commit comments

Comments
 (0)