~robin_jadoul/blog

7076a94c747f5646a6364db0725ec8858dcdecb3 — Robin Jadoul 8 months ago 96afc47
Fallback to pandoc's mathml when no js or katex available
3 files changed, 9 insertions(+), 4 deletions(-)

M site.py
M static/css/style.css
M templates/base.html
M site.py => site.py +1 -2
@@ 15,7 15,6 @@
#      * https://indielogin.com/setup
#    + CV?
#  - minimalist/gemini/text-only version??
#  - prerender KaTeX
import os, datetime, collections, pathlib, typing
os.chdir(os.path.abspath(os.path.dirname(__file__)))



@@ 63,7 62,7 @@ def gather_tags(target: dict[str, list[Page]]) -> t_Transformer:
is_draft = meta_p("draft", False)
is_encrypted = meta_p("encrypted", False)

mdrenderer = PandocRenderer.markdown_to_html(options=["--mathjax", "--no-highlight"])
mdrenderer = PandocRenderer.markdown_to_html(options=["--mathml", "--no-highlight"])

with Site(
        output_directory = curdir / "output",

M static/css/style.css => static/css/style.css +1 -1
@@ 205,7 205,7 @@ blockquote{
}

blockquote,figure,.katex-html {
    overflow: auto;
    overflow: auto hidden;
}

code {

M templates/base.html => templates/base.html +7 -1
@@ 21,7 21,7 @@
        <link rel="stylesheet" href="/static/vendor/copy-tex.min.css" type="text/css" media="all">
        <script type="text/javascript" defer src="/static/vendor/katex.min.js"></script>
        <script type="text/javascript" defer src="/static/vendor/copy-tex.min.js"></script>
        <script type="text/javascript" defer src="/static/vendor/auto-render.min.js" onload="renderMathInElement(document.body, katex_options)"></script>
        <script type="text/javascript" defer src="/static/vendor/auto-render.min.js"></script>

        <link rel="stylesheet" href="/static/vendor/hljs-nord.min.css">
        <script src="/static/vendor/highlight.min.js"></script>


@@ 29,6 29,12 @@
        hljs.registerAliases("sage", {languageName: "python"});
        document.addEventListener('DOMContentLoaded', (event) => {
            document.querySelectorAll('pre code').forEach((block) => hljs.highlightBlock(block));
            document.querySelectorAll('math>semantics>annotation').forEach((node) => {
                node.parentNode.parentNode.outerHTML = katex.renderToString(node.textContent, {
                    displayMode: node.parentNode.parentNode.attributes.display.value === 'block',
                });
            });
            renderMathInElement(document.body, katex_options);
        });
        </script>
        {% block head %}{% endblock %}