GitHub
· Extracted in 1714 ms
🐛 Fix HTML block start conditions per CommonMark 0.31.2 (#440) · executablebooks/markdown-it-py@2542e66
Source: https://github.com/executablebooks/markdown-it-py/commit/2542e66f123f4f23f0156b353c53c2fddc536719
Repository navigation
Commit 2542e66
Browse files
rupayon123
authored
🐛 Fix HTML block start conditions per CommonMark 0.31.2 ( #440 )
Lowercase declarations such as `<!doctype html>` now start an HTML block
and interrupt a paragraph (CommonMark 0.31.2 start condition 4, as in
upstream markdown-it 15.0.0).
Block tag names for types 1 and 6 now match case-insensitively in ASCII
only, so Unicode lookalikes that Python case-folds to ASCII, such as
U+017F, U+0130, U+0131 and U+212A, no longer open or close an HTML block.
A Unicode space such as a no-break space after the tag name still starts
one, as in markdown-it and commonmark.js.
Fixes #437 , reported by @p5ych0 .
1 parent cb36d3a commit 2542e66
3 files changed
Lines changed: 119 additions & 4 deletions
File tree
-
markdown_it/rules_block
-
tests/test_port/fixtures
Lines changed: 6 additions & 4 deletions
| Original file line number | Diff line number | Diff line change |
@@ -14,16 +14,18 @@
|
14 | 14 | # last argument defines whether it can terminate a paragraph or not
|
15 | 15 | HTML_SEQUENCES: list[tuple[re.Pattern[str], re.Pattern[str], bool]] = [
|
16 | 16 | (
|
17 | | - re.compile(r"^<(script|pre|style|textarea)(?=(\s|>|$))", re.IGNORECASE),
|
18 | | - re.compile(r"<\/(script|pre|style|textarea)>", re.IGNORECASE),
|
| 17 | + re.compile(r"^<(?a:(script|pre|style|textarea))(?=(\s|>|$))", re.IGNORECASE),
|
| 18 | + re.compile(r"<\/(?a:(script|pre|style|textarea))>", re.IGNORECASE),
|
19 | 19 | True,
|
20 | 20 | ),
|
21 | 21 | (re.compile(r"^<!--"), re.compile(r"-->"), True),
|
22 | 22 | (re.compile(r"^<\?"), re.compile(r"\?>"), True),
|
23 | | - (re.compile(r"^<![A-Z]"), re.compile(r">"), True),
|
| 23 | + (re.compile(r"^<![A-Za-z]"), re.compile(r">"), True),
|
24 | 24 | (re.compile(r"^<!\[CDATA\["), re.compile(r"\]\]>"), True),
|
25 | 25 | (
|
26 | | - re.compile("^</?(" + "|".join(block_names) + ")(?=(\\s|/?>|$))", re.IGNORECASE),
|
| 26 | + re.compile(
|
| 27 | + "^</?(?a:(" + "|".join(block_names) + "))(?=(\\s|/?>|$))", re.IGNORECASE
|
| 28 | + ),
|
27 | 29 | re.compile(r"^$"),
|
28 | 30 | True,
|
29 | 31 | ),
|
|
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
@@ -871,3 +871,12 @@ b
|
871 | 871 | <p>c</p>
|
872 | 872 | </blockquote>
|
873 | 873 | .
|
| 874 | +
|
| 875 | +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.
|
| 876 | +.
|
| 877 | +foo
|
| 878 | +<!bar baz>
|
| 879 | +.
|
| 880 | +<p>foo</p>
|
| 881 | +<!bar baz>
|
| 882 | +.
|
Lines changed: 104 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
@@ -140,3 +140,107 @@ foo
|
140 | 140 | <p>foo
|
141 | 141 | --></p>
|
142 | 142 | .
|
| 143 | +
|
| 144 | +#437 a lowercase declaration interrupts a paragraph, as an uppercase one does
|
| 145 | +.
|
| 146 | +para
|
| 147 | +<!doctype html>
|
| 148 | +
|
| 149 | +para
|
| 150 | +<!DOCTYPE html>
|
| 151 | +.
|
| 152 | +<p>para</p>
|
| 153 | +<!doctype html>
|
| 154 | +<p>para</p>
|
| 155 | +<!DOCTYPE html>
|
| 156 | +.
|
| 157 | +
|
| 158 | +#437 Unicode lookalikes that case-fold to ASCII (U+017F, U+0130, U+0131) do not start an HTML block
|
| 159 | +.
|
| 160 | +para
|
| 161 | +<ſcript>
|
| 162 | +text
|
| 163 | +
|
| 164 | +para
|
| 165 | +<ſtyle>
|
| 166 | +text
|
| 167 | +
|
| 168 | +para
|
| 169 | +<dİv>
|
| 170 | +text
|
| 171 | +
|
| 172 | +para
|
| 173 | +<dıv>
|
| 174 | +text
|
| 175 | +.
|
| 176 | +<p>para
|
| 177 | +<ſcript>
|
| 178 | +text</p>
|
| 179 | +<p>para
|
| 180 | +<ſtyle>
|
| 181 | +text</p>
|
| 182 | +<p>para
|
| 183 | +<dİv>
|
| 184 | +text</p>
|
| 185 | +<p>para
|
| 186 | +<dıv>
|
| 187 | +text</p>
|
| 188 | +.
|
| 189 | +
|
| 190 | +#437 a Unicode lookalike does not close a type 1 HTML block
|
| 191 | +.
|
| 192 | +<script>
|
| 193 | +x
|
| 194 | +</ſcript>
|
| 195 | +after
|
| 196 | +
|
| 197 | +more
|
| 198 | +.
|
| 199 | +<script>
|
| 200 | +x
|
| 201 | +</ſcript>
|
| 202 | +after
|
| 203 | +
|
| 204 | +more
|
| 205 | +.
|
| 206 | +
|
| 207 | +#437 an ASCII mixed-case tag name still starts and closes an HTML block
|
| 208 | +.
|
| 209 | +para
|
| 210 | +<ScRiPt>
|
| 211 | +text
|
| 212 | +</sCrIpT>
|
| 213 | +after
|
| 214 | +.
|
| 215 | +<p>para</p>
|
| 216 | +<ScRiPt>
|
| 217 | +text
|
| 218 | +</sCrIpT>
|
| 219 | +<p>after</p>
|
| 220 | +.
|
| 221 | +
|
| 222 | +#437 a no-break space (U+00A0) after a type 6 tag name still starts an HTML block
|
| 223 | +.
|
| 224 | +para
|
| 225 | +<div class="x">
|
| 226 | +text
|
| 227 | +.
|
| 228 | +<p>para</p>
|
| 229 | +<div class="x">
|
| 230 | +text
|
| 231 | +.
|
| 232 | +
|
| 233 | +#437 a no-break space (U+00A0) after a type 1 tag name still starts an HTML block
|
| 234 | +.
|
| 235 | +para
|
| 236 | +<pre >
|
| 237 | +
|
| 238 | +*a*
|
| 239 | +</pre>
|
| 240 | +.
|
| 241 | +<p>para</p>
|
| 242 | +<pre >
|
| 243 | +
|
| 244 | +*a*
|
| 245 | +</pre>
|
| 246 | +.
|
|
|