Skip to content

Commit

Permalink
Tweaked list paragraph interruption. Only interrupt in nested list.
Browse files Browse the repository at this point in the history
  • Loading branch information
FritsvanCampen committed Sep 21, 2021
1 parent 4bc1ac2 commit f47a6c2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,13 @@ are two small differences with Pandoc's syntax:
* This plugin does not support list numbers enclosed in parentheses,
as the Commonmark spec does not support these either for lists
numbered with Arabic numerals.
* Pandoc and Commonmark do not agree whether a list is allowed to
interrupt a paragraph. It also depends on if that list is nested or not.
This plugin always allows a paragraph to be interrupted.
* Pandoc does not allow any list to interrupt a paragraph. In the
spirit of the Commonmark spec (which allows only lists starting
with 1 to interrupt a paragraph), this plugins allows lists that
start with "A", "a", "I" or "i" (i.e. all 'first numerals') to
interrupt a paragraph. The same holds for the "#" generic numbered
list item marker.
For nested lists, any start number can interrupt a paragraph.

Configuration
-------------
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ const createFancyList = (options: MarkdownItFancyListPluginOptions) => {
return false;
}

// do not allow subsequent numbers to interrupt paragraphs in non-nested lists
const isNestedList = state.listIndent !== -1;
if (isTerminatingParagraph && marker.start !== 1 && isNestedList === false) {
return false;
}

// If we're starting a new unordered list right after
// a paragraph, first line should not be empty.
if (isTerminatingParagraph) {
Expand Down
23 changes: 9 additions & 14 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ iii. a plane ticket
await assertHTML(expectedHtml, markdown);
});

it("allows subsequent numbers to interrupt paragraphs", async () => {
it("does not allow subsequent numbers to interrupt paragraphs", async () => {
const markdown = `
I need to buy
b. new shoes
Expand All @@ -302,19 +302,14 @@ iii. a coat
iv. a plane ticket
`;
const expectedHtml = `
<p>I need to buy</p>
<ol type="a" start="2">
<li>new shoes</li>
<li>a coat</li>
<li>a plane ticket</li>
</ol>
<p>I also need to buy</p>
<ol type="i" start="2">
<li>new shoes</li>
<li>a coat</li>
<li>a plane ticket</li>
</ol>
<p>I need to buy
b. new shoes
c. a coat
d. a plane ticket</p>
<p>I also need to buy
ii. new shoes
iii. a coat
iv. a plane ticket</p>
`;
await assertHTML(expectedHtml, markdown);
});
Expand Down

0 comments on commit f47a6c2

Please sign in to comment.