Skip to content

Commit b66cc43

Browse files
authored
Fix math init logic (#2106)
1 parent e0a6c83 commit b66cc43

File tree

1 file changed

+9
-1
lines changed
  • src/Elastic.Documentation.Site/Assets

1 file changed

+9
-1
lines changed

src/Elastic.Documentation.Site/Assets/main.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const isLazyLoadNavigationEnabled =
2323
* Initialize KaTeX math rendering for elements with class 'math'
2424
*/
2525
function initMath() {
26-
const mathElements = $$('.math')
26+
const mathElements = $$('.math:not([data-katex-processed])')
2727
mathElements.forEach((element) => {
2828
try {
2929
const content = element.textContent?.trim()
@@ -56,6 +56,9 @@ function initMath() {
5656
// Add common macros if needed
5757
},
5858
})
59+
60+
// Mark as processed to prevent double processing
61+
element.setAttribute('data-katex-processed', 'true')
5962
} catch (error) {
6063
console.warn('KaTeX rendering error:', error)
6164
// Fallback: keep the original content
@@ -64,6 +67,11 @@ function initMath() {
6467
})
6568
}
6669

70+
// Initialize math on initial page load
71+
document.addEventListener('DOMContentLoaded', function () {
72+
initMath()
73+
})
74+
6775
document.addEventListener('htmx:load', function (event) {
6876
initTocNav()
6977
initHighlight()

0 commit comments

Comments
 (0)