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..7293180d --- /dev/null +++ b/tests/test_html_block_ascii.py @@ -0,0 +1,24 @@ +"""CommonMark HTML block starts use ASCII letters for tag and declarations.""" + +from markdown_it import MarkdownIt + + +def test_ascii_declaration_ends_paragraph() -> None: + md = MarkdownIt("commonmark") + for declaration in ("", ""): + assert md.render(f"para\n{declaration}\n") == f"
para
\n{declaration}\n" + + +def test_unicode_casefold_does_not_start_html_block() -> None: + md = MarkdownIt("commonmark") + 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: + md = MarkdownIt("commonmark") + assert md.render("para\n\n") == ( + "para
\n\n" + )