From bb67d1036a7c29ed77206348f78ca87db2a1285c Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Sun, 19 Feb 2023 13:06:06 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20regression=20in=20amsmath?= =?UTF-8?q?=20(#70)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mdit_py_plugins/amsmath/__init__.py | 2 +- tests/test_amsmath.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/mdit_py_plugins/amsmath/__init__.py b/mdit_py_plugins/amsmath/__init__.py index 197f1cc..5aa82bb 100644 --- a/mdit_py_plugins/amsmath/__init__.py +++ b/mdit_py_plugins/amsmath/__init__.py @@ -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)) diff --git a/tests/test_amsmath.py b/tests/test_amsmath.py index 55b4987..fe48cf1 100644 --- a/tests/test_amsmath.py +++ b/tests/test_amsmath.py @@ -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( + """\ +
+ \\begin{equation} + a + \\end{equation}! +
+ """ + ).strip() + ) + + @pytest.mark.parametrize( "line,title,input,expected", read_fixture_file(FIXTURE_PATH.joinpath("fixtures", "amsmath.md")),