From 99e430aba3864005561b83e0071bcf49cc6f5256 Mon Sep 17 00:00:00 2001 From: Fabrizio Ferri Benedetti Date: Fri, 24 Oct 2025 08:20:50 +0200 Subject: [PATCH] Fix math init logic --- src/Elastic.Documentation.Site/Assets/main.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Elastic.Documentation.Site/Assets/main.ts b/src/Elastic.Documentation.Site/Assets/main.ts index cfc432cf4..460bdb2fd 100644 --- a/src/Elastic.Documentation.Site/Assets/main.ts +++ b/src/Elastic.Documentation.Site/Assets/main.ts @@ -23,7 +23,7 @@ const isLazyLoadNavigationEnabled = * Initialize KaTeX math rendering for elements with class 'math' */ function initMath() { - const mathElements = $$('.math') + const mathElements = $$('.math:not([data-katex-processed])') mathElements.forEach((element) => { try { const content = element.textContent?.trim() @@ -56,6 +56,9 @@ function initMath() { // Add common macros if needed }, }) + + // Mark as processed to prevent double processing + element.setAttribute('data-katex-processed', 'true') } catch (error) { console.warn('KaTeX rendering error:', error) // Fallback: keep the original content @@ -64,6 +67,11 @@ function initMath() { }) } +// Initialize math on initial page load +document.addEventListener('DOMContentLoaded', function () { + initMath() +}) + document.addEventListener('htmx:load', function (event) { initTocNav() initHighlight()