From 9c40c27561172a943295963ff631c7b6b6539d7b Mon Sep 17 00:00:00 2001 From: Shreeyash Pandey Date: Tue, 14 Oct 2025 00:36:34 +0530 Subject: [PATCH] add l2m4m extension for math rendering Signed-off-by: Shreeyash Pandey --- blag/markdown.py | 3 +++ pyproject.toml | 1 + tests/test_markdown.py | 14 ++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/blag/markdown.py b/blag/markdown.py index ee4c573..8230e4b 100644 --- a/blag/markdown.py +++ b/blag/markdown.py @@ -13,6 +13,8 @@ from markdown import Markdown from markdown.extensions import Extension from markdown.treeprocessors import Treeprocessor +from l2m4m import LaTeX2MathMLExtension + logger = logging.getLogger(__name__) @@ -35,6 +37,7 @@ def markdown_factory() -> Markdown: "codehilite", "smarty", MarkdownLinkExtension(), + LaTeX2MathMLExtension(), ], output_format="html", ) diff --git a/pyproject.toml b/pyproject.toml index 0a2aa14..d1ee353 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,6 +18,7 @@ dependencies = [ "jinja2", "markdown", "pygments", + "l2m4m", ] [project.scripts] diff --git a/tests/test_markdown.py b/tests/test_markdown.py index 5e393d2..4b2d246 100644 --- a/tests/test_markdown.py +++ b/tests/test_markdown.py @@ -111,3 +111,17 @@ def test_smarty_code() -> None: assert "mdash" not in html assert "ndash" not in html assert "hellip" not in html + +def test_l2m4m_extension() -> None: + """Test LaTeX math rendering via l2m4m extension.""" + md = markdown_factory() + markdown_input = ( + "Quick math: $E = mc^2$\n" + ) + expected_output_fragments = [ + 'math display="inline"', + ] + html, _ = convert_markdown(md, markdown_input) + + for fragment in expected_output_fragments: + assert fragment in html