Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions markdown_it/rules_block/html_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"^<!--"), re.compile(r"-->"), True),
(re.compile(r"^<\?"), re.compile(r"\?>"), True),
(re.compile(r"^<![A-Z]"), re.compile(r">"), True),
(re.compile(r"^<![A-Za-z]"), re.compile(r">"), True),
(re.compile(r"^<!\[CDATA\["), 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,
),
Expand Down
24 changes: 24 additions & 0 deletions tests/test_html_block_ascii.py
Original file line number Diff line number Diff line change
@@ -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 ("<!doctype html>", "<!DOCTYPE html>"):
assert md.render(f"para\n{declaration}\n") == f"<p>para</p>\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"<p>para\n&lt;{tag}&gt;\ntext</p>\n"
)


def test_ascii_mixed_case_tag_still_starts_html_block() -> None:
md = MarkdownIt("commonmark")
assert md.render("para\n<ScRiPt>\ntext\n</sCrIpT>\n") == (
"<p>para</p>\n<ScRiPt>\ntext\n</sCrIpT>\n"
)