Skip to content

Commit f47a6c2

Browse files
Tweaked list paragraph interruption. Only interrupt in nested list.
1 parent 4bc1ac2 commit f47a6c2

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,13 @@ are two small differences with Pandoc's syntax:
109109
* This plugin does not support list numbers enclosed in parentheses,
110110
as the Commonmark spec does not support these either for lists
111111
numbered with Arabic numerals.
112-
* Pandoc and Commonmark do not agree whether a list is allowed to
113-
interrupt a paragraph. It also depends on if that list is nested or not.
114-
This plugin always allows a paragraph to be interrupted.
112+
* Pandoc does not allow any list to interrupt a paragraph. In the
113+
spirit of the Commonmark spec (which allows only lists starting
114+
with 1 to interrupt a paragraph), this plugins allows lists that
115+
start with "A", "a", "I" or "i" (i.e. all 'first numerals') to
116+
interrupt a paragraph. The same holds for the "#" generic numbered
117+
list item marker.
118+
For nested lists, any start number can interrupt a paragraph.
115119

116120
Configuration
117121
-------------

src/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,12 @@ const createFancyList = (options: MarkdownItFancyListPluginOptions) => {
276276
return false;
277277
}
278278

279+
// do not allow subsequent numbers to interrupt paragraphs in non-nested lists
280+
const isNestedList = state.listIndent !== -1;
281+
if (isTerminatingParagraph && marker.start !== 1 && isNestedList === false) {
282+
return false;
283+
}
284+
279285
// If we're starting a new unordered list right after
280286
// a paragraph, first line should not be empty.
281287
if (isTerminatingParagraph) {

test/index.ts

+9-14
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ iii. a plane ticket
289289
await assertHTML(expectedHtml, markdown);
290290
});
291291

292-
it("allows subsequent numbers to interrupt paragraphs", async () => {
292+
it("does not allow subsequent numbers to interrupt paragraphs", async () => {
293293
const markdown = `
294294
I need to buy
295295
b. new shoes
@@ -302,19 +302,14 @@ iii. a coat
302302
iv. a plane ticket
303303
`;
304304
const expectedHtml = `
305-
<p>I need to buy</p>
306-
<ol type="a" start="2">
307-
<li>new shoes</li>
308-
<li>a coat</li>
309-
<li>a plane ticket</li>
310-
</ol>
311-
<p>I also need to buy</p>
312-
<ol type="i" start="2">
313-
<li>new shoes</li>
314-
<li>a coat</li>
315-
<li>a plane ticket</li>
316-
</ol>
317-
305+
<p>I need to buy
306+
b. new shoes
307+
c. a coat
308+
d. a plane ticket</p>
309+
<p>I also need to buy
310+
ii. new shoes
311+
iii. a coat
312+
iv. a plane ticket</p>
318313
`;
319314
await assertHTML(expectedHtml, markdown);
320315
});

0 commit comments

Comments
 (0)