From 13f28fb67551f78333aa465daef3b59d645e0f21 Mon Sep 17 00:00:00 2001 From: Rupayon Haldar <80724680+rupayon123@users.noreply.github.com> Date: Sat, 26 Sep 2026 02:50:27 -0400 Subject: [PATCH 1/2] Fix ASCII HTML block start matching --- markdown_it/rules_block/html_block.py | 13 +++++++++---- tests/test_html_block_ascii.py | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 tests/test_html_block_ascii.py diff --git a/markdown_it/rules_block/html_block.py b/markdown_it/rules_block/html_block.py index fe7e464e..8b195933 100644 --- a/markdown_it/rules_block/html_block.py +++ b/markdown_it/rules_block/html_block.py @@ -14,16 +14,21 @@ # last argument defines whether it can terminate a paragraph or not HTML_SEQUENCES: list[tuple[re.Pattern[str], re.Pattern[str], bool]] = [ ( - re.compile(r"^<(script|pre|style|textarea)(?=(\s|>|$))", re.IGNORECASE), - re.compile(r"<\/(script|pre|style|textarea)>", re.IGNORECASE), + re.compile( + r"^<(script|pre|style|textarea)(?=(\s|>|$))", re.IGNORECASE | re.ASCII + ), + re.compile(r"<\/(script|pre|style|textarea)>", re.IGNORECASE | re.ASCII), True, ), (re.compile(r"^"), True), (re.compile(r"^<\?"), re.compile(r"\?>"), True), - (re.compile(r"^"), True), + (re.compile(r"^"), True), (re.compile(r"^"), True), ( - re.compile("^?(" + "|".join(block_names) + ")(?=(\\s|/?>|$))", re.IGNORECASE), + re.compile( + "^?(" + "|".join(block_names) + ")(?=(\\s|/?>|$))", + re.IGNORECASE | re.ASCII, + ), re.compile(r"^$"), True, ), diff --git a/tests/test_html_block_ascii.py b/tests/test_html_block_ascii.py new file mode 100644 index 00000000..4f388739 --- /dev/null +++ b/tests/test_html_block_ascii.py @@ -0,0 +1,26 @@ +"""CommonMark HTML block starts use ASCII letters for tag and declarations.""" + +import pytest + +from markdown_it import MarkdownIt + + +@pytest.mark.parametrize("declaration", ["", ""]) +def test_ascii_declaration_ends_paragraph(declaration: str) -> None: + md = MarkdownIt("commonmark") + assert md.render(f"para\n{declaration}\n") == f"
para
\n{declaration}\n" + + +@pytest.mark.parametrize("tag", ["\u017fcript", "\u017ftyle", "d\u0130v", "d\u0131v"]) +def test_unicode_casefold_does_not_start_html_block(tag: str) -> None: + md = MarkdownIt("commonmark") + assert md.render(f"para\n<{tag}>\ntext\n") == ( + f"para\n<{tag}>\ntext
\n" + ) + + +def test_ascii_mixed_case_tag_still_starts_html_block() -> None: + md = MarkdownIt("commonmark") + assert md.render("para\n\n") == ( + "para
\n\n" + ) From 3650b270365bc7f0fcaa6fbc22c734a4df5ca5ec Mon Sep 17 00:00:00 2001 From: Rupayon Haldar <80724680+rupayon123@users.noreply.github.com> Date: Sat, 26 Sep 2026 02:57:15 -0400 Subject: [PATCH 2/2] Keep HTML block regressions compatible with strict mypy --- tests/test_html_block_ascii.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/test_html_block_ascii.py b/tests/test_html_block_ascii.py index 4f388739..7293180d 100644 --- a/tests/test_html_block_ascii.py +++ b/tests/test_html_block_ascii.py @@ -1,22 +1,20 @@ """CommonMark HTML block starts use ASCII letters for tag and declarations.""" -import pytest - from markdown_it import MarkdownIt -@pytest.mark.parametrize("declaration", ["", ""]) -def test_ascii_declaration_ends_paragraph(declaration: str) -> None: +def test_ascii_declaration_ends_paragraph() -> None: md = MarkdownIt("commonmark") - assert md.render(f"para\n{declaration}\n") == f"para
\n{declaration}\n" + for declaration in ("", ""): + assert md.render(f"para\n{declaration}\n") == f"para
\n{declaration}\n" -@pytest.mark.parametrize("tag", ["\u017fcript", "\u017ftyle", "d\u0130v", "d\u0131v"]) -def test_unicode_casefold_does_not_start_html_block(tag: str) -> None: +def test_unicode_casefold_does_not_start_html_block() -> None: md = MarkdownIt("commonmark") - assert md.render(f"para\n<{tag}>\ntext\n") == ( - f"para\n<{tag}>\ntext
\n" - ) + for tag in ("\u017fcript", "\u017ftyle", "d\u0130v", "d\u0131v"): + assert md.render(f"para\n<{tag}>\ntext\n") == ( + f"para\n<{tag}>\ntext
\n" + ) def test_ascii_mixed_case_tag_still_starts_html_block() -> None: