Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Math rendering in Markdown #443

Closed
tchamelot opened this issue Feb 23, 2024 · 0 comments · Fixed by #444
Closed

Math rendering in Markdown #443

tchamelot opened this issue Feb 23, 2024 · 0 comments · Fixed by #444

Comments

@tchamelot
Copy link
Contributor

Hello and thank you for this nice tool,

While testing markdown with math support, I noticed that math equations are not rendered properly.
The generated html looks like

<div class="katex">\Delta</div>

instead of

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi mathvariant="normal">Δ</mi></mrow><annotation encoding="application/x-tex">
 \Delta
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height: 0.6833em;"></span><span class="mord">Δ</span></span></span></span></span>

Which allow to render the $\Delta$ correctly.

On flexmark-java wiki, it is indicated to add the following script at the end of the generated html page to convert math elements when the DOM is loaded..

<script>
    (function () {
      document.addEventListener("DOMContentLoaded", function () {
        var mathElems = document.getElementsByClassName("katex");
        var elems = [];
        for (const i in mathElems) {
            if (mathElems.hasOwnProperty(i)) elems.push(mathElems[i]);
        }

        elems.forEach(elem => {
            katex.render(elem.textContent, elem, { throwOnError: false, displayMode: elem.nodeName !== 'SPAN', });
        });
    });
})();
</script>

I don't exactly understand how to fix the issue. Extending MarkdownExtension.kt and Page.kt should be enough. I'll try to provide a PR this week-end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant