Skip to content

Commit 1bbda68

Browse files
authoredDec 23, 2022
fix: fix paragraph continuation after block element (#2686)
1 parent 26e2942 commit 1bbda68

File tree

3 files changed

+64
-12
lines changed

3 files changed

+64
-12
lines changed
 

‎src/Tokenizer.js

+30-12
Original file line numberDiff line numberDiff line change
@@ -233,25 +233,25 @@ export class Tokenizer {
233233
// Check if following lines should be included in List Item
234234
while (src) {
235235
rawLine = src.split('\n', 1)[0];
236-
line = rawLine;
236+
nextLine = rawLine;
237237

238238
// Re-align to follow commonmark nesting rules
239239
if (this.options.pedantic) {
240-
line = line.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
240+
nextLine = nextLine.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
241241
}
242242

243243
// End list item if found code fences
244-
if (fencesBeginRegex.test(line)) {
244+
if (fencesBeginRegex.test(nextLine)) {
245245
break;
246246
}
247247

248248
// End list item if found start of new heading
249-
if (headingBeginRegex.test(line)) {
249+
if (headingBeginRegex.test(nextLine)) {
250250
break;
251251
}
252252

253253
// End list item if found start of new bullet
254-
if (nextBulletRegex.test(line)) {
254+
if (nextBulletRegex.test(nextLine)) {
255255
break;
256256
}
257257

@@ -260,20 +260,38 @@ export class Tokenizer {
260260
break;
261261
}
262262

263-
if (line.search(/[^ ]/) >= indent || !line.trim()) { // Dedent if possible
264-
itemContents += '\n' + line.slice(indent);
265-
} else if (!blankLine) { // Until blank line, item doesn't need indentation
266-
itemContents += '\n' + line;
267-
} else { // Otherwise, improper indentation ends this item
268-
break;
263+
if (nextLine.search(/[^ ]/) >= indent || !nextLine.trim()) { // Dedent if possible
264+
itemContents += '\n' + nextLine.slice(indent);
265+
} else {
266+
// not enough indentation
267+
if (blankLine) {
268+
break;
269+
}
270+
271+
// paragraph continuation unless last line was a different block level element
272+
if (line.search(/[^ ]/) >= 4) { // indented code block
273+
break;
274+
}
275+
if (fencesBeginRegex.test(line)) {
276+
break;
277+
}
278+
if (headingBeginRegex.test(line)) {
279+
break;
280+
}
281+
if (hrRegex.test(line)) {
282+
break;
283+
}
284+
285+
itemContents += '\n' + nextLine;
269286
}
270287

271-
if (!blankLine && !line.trim()) { // Check if current line is blank
288+
if (!blankLine && !nextLine.trim()) { // Check if current line is blank
272289
blankLine = true;
273290
}
274291

275292
raw += rawLine + '\n';
276293
src = src.substring(rawLine.length + 1);
294+
line = nextLine.slice(indent);
277295
}
278296
}
279297

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<ul>
2+
<li>
3+
<hr />
4+
</li>
5+
</ul>
6+
<p>paragraph</p>
7+
<ul>
8+
<li>
9+
<h1 id="heading">heading</h1>
10+
</li>
11+
</ul>
12+
<p>paragraph</p>
13+
<ul>
14+
<li>
15+
<pre><code>indented code</code></pre>
16+
</li>
17+
</ul>
18+
<p>paragraph</p>
19+
<ul>
20+
<li>
21+
<pre><code>fenced code</code></pre>
22+
</li>
23+
</ul>
24+
<p>paragraph</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- ***
2+
paragraph
3+
- # heading
4+
paragraph
5+
- indented code
6+
paragraph
7+
- ```
8+
fenced code
9+
```
10+
paragraph

1 commit comments

Comments
 (1)

vercel[bot] commented on Dec 23, 2022

@vercel[bot]
Please sign in to comment.