diff --git a/python/tests/integration/markdown/test_render.py b/python/tests/integration/markdown/test_render.py index cffb27b..75f430d 100644 --- a/python/tests/integration/markdown/test_render.py +++ b/python/tests/integration/markdown/test_render.py @@ -104,3 +104,41 @@ class TestTocCleanup: # The child heading must preserve the abbreviation text. child = result["toc"][0]["children"][0] assert child["content"] == "Using CSS" + + def test_images_stripped_from_toc_content(self) -> None: + """Images defined in the page must not appear as in TOC.""" + result = render( + content="# ![icon](../../images/system-32.png) System\n", + path="index.md", + url="/", + ) + + # Sanity-check: the rendered page body must contain . + assert " tags. + assert " None: + """Image stripping must apply at every nesting level.""" + result = render( + content=( + "# Top level\n\n## ![icon](../../images/system-32.png) System\n" + ), + path="index.md", + url="/", + ) + + # The rendered page body must contain . + assert ". + assert all("', + "", + id="img_tag", + ), + pytest.param( + 'ImageText', + "Text", + id="img_tag_with_text_after", + ), + pytest.param( + 'TextImage', + "Text", + id="img_tag_with_text_before", + ), # Combined and passthrough ------------------------------------ pytest.param( 'Intro to ' 'HTML' + 'Image' "", "Intro to HTML", - id="links_and_abbreviations", + id="combined_and_passthrough", ), pytest.param( "Just plain text", diff --git a/python/zensical/markdown/render.py b/python/zensical/markdown/render.py index dfe0f71..25f3179 100644 --- a/python/zensical/markdown/render.py +++ b/python/zensical/markdown/render.py @@ -180,4 +180,6 @@ def _cleanup_toc_label(html: str) -> str: html = re.sub(r"]+>(.*?)", r"\1", html, flags=re.DOTALL) # Remove abbreviations html = re.sub(r"]+>(.*?)", r"\1", html, flags=re.DOTALL) + # Remove images + html = re.sub(r"]+>", "", html, flags=re.DOTALL) return html # noqa: RET504