Skip to content

Commit

Permalink
🐛 Fix regression in amsmath (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell authored Feb 19, 2023
1 parent de7f783 commit bb67d10
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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

0 comments on commit bb67d10

Please sign in to comment.