Skip to content
10 changes: 6 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,18 @@
# 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"^<(?a:(script|pre|style|textarea))(?=(\s|>|$))", re.IGNORECASE),
re.compile(r"<\/(?a:(script|pre|style|textarea))>", re.IGNORECASE),
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(
"^</?(?a:(" + "|".join(block_names) + "))(?=(\\s|/?>|$))", re.IGNORECASE
),
re.compile(r"^$"),
True,
),
Expand Down
9 changes: 9 additions & 0 deletions tests/test_port/fixtures/commonmark_extras.md
Original file line number Diff line number Diff line change
Expand Up @@ -871,3 +871,12 @@ b
<p>c</p>
</blockquote>
.

HTML block type 4 (declaration) starts with `<!` plus any ASCII letter, not only uppercase (CommonMark 4.6, start condition 4). A lowercase declaration must interrupt a paragraph.
.
foo
<!bar baz>
.
<p>foo</p>
<!bar baz>
.
104 changes: 104 additions & 0 deletions tests/test_port/fixtures/issue-fixes.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,107 @@ foo
<p>foo
--&gt;</p>
.

#437 a lowercase declaration interrupts a paragraph, as an uppercase one does
.
para
<!doctype html>

para
<!DOCTYPE html>
.
<p>para</p>
<!doctype html>
<p>para</p>
<!DOCTYPE html>
.

#437 Unicode lookalikes that case-fold to ASCII (U+017F, U+0130, U+0131) do not start an HTML block
.
para
<ſcript>
text

para
<ſtyle>
text

para
<dİv>
text

para
<dıv>
text
.
<p>para
&lt;ſcript&gt;
text</p>
<p>para
&lt;ſtyle&gt;
text</p>
<p>para
&lt;dİv&gt;
text</p>
<p>para
&lt;dıv&gt;
text</p>
.

#437 a Unicode lookalike does not close a type 1 HTML block
.
<script>
x
</ſcript>
after

more
.
<script>
x
</ſcript>
after

more
.

#437 an ASCII mixed-case tag name still starts and closes an HTML block
.
para
<ScRiPt>
text
</sCrIpT>
after
.
<p>para</p>
<ScRiPt>
text
</sCrIpT>
<p>after</p>
.

#437 a no-break space (U+00A0) after a type 6 tag name still starts an HTML block
.
para
<div class="x">
text
.
<p>para</p>
<div class="x">
text
.

#437 a no-break space (U+00A0) after a type 1 tag name still starts an HTML block
.
para
<pre >

*a*
</pre>
.
<p>para</p>
<pre >

*a*
</pre>
.
Loading