From 99b049fa96490877af7ec5dc982e6d702b29ae9b Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Fri, 16 Oct 2026 16:58:43 +0200 Subject: [PATCH] fix: catch indented hashes in wiki sources --- tests/test_site_validation.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/test_site_validation.py b/tests/test_site_validation.py index 53dc2263..b2f3f940 100644 --- a/tests/test_site_validation.py +++ b/tests/test_site_validation.py @@ -64,14 +64,29 @@ class WikiSourceHeadings(unittest.TestCase): for number, line in enumerate( page.read_text(encoding="utf-8").splitlines(), start=1 ): - if line.lstrip().startswith("```"): + if line.lstrip().startswith(("```", "~~~")): fenced = not fenced elif not fenced and line.startswith("#") and not line.startswith( ("# ", "## ", "### ", "#### ", "##### ", "###### ") ): offenders.append(f"{page.name}:{number}") + elif not fenced and line[:1].isspace() and line.lstrip().startswith("#"): + # Inside a list item or an admonition an indented hash is + # a heading too; code that needs one goes in a fence. + offenders.append(f"{page.name}:{number}") self.assertEqual(offenders, []) + def test_an_indented_hash_renders_as_a_heading(self): + """What the check above guards: a wrapped `#79)` inside a list item.""" + try: + import markdown + except ImportError: + self.skipTest("rendering needs markdown") + html = markdown.markdown( + "1. First paragraph.\n\n Second paragraph (see issue\n #79). More." + ) + self.assertIn("