Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mdit_py_plugins/amsmath/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def amsmath_plugin(md: MarkdownIt, *, renderer: Optional[Callable[[str], str]] =
{"alt": ["paragraph", "reference", "blockquote", "list", "footnote_def"]},
)

_renderer = lambda content: escapeHtml(content) if renderer is None else renderer
_renderer = (lambda content: escapeHtml(content)) if renderer is None else renderer

def render_amsmath_block(self, tokens, idx, options, env):
content = _renderer(str(tokens[idx].content))
Expand Down
17 changes: 17 additions & 0 deletions tests/test_amsmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ def test_plugin_parse(data_regression):
data_regression.check([t.as_dict() for t in tokens])


def test_custom_renderer(data_regression):
md = MarkdownIt().use(amsmath_plugin, renderer=lambda x: x + "!")
output = md.render("\\begin{equation}\na\n\\end{equation}")
assert (
output.strip()
== dedent(
"""\
<div class="math amsmath">
\\begin{equation}
a
\\end{equation}!
</div>
"""
).strip()
)


@pytest.mark.parametrize(
"line,title,input,expected",
read_fixture_file(FIXTURE_PATH.joinpath("fixtures", "amsmath.md")),
Expand Down