Skip to content

Commit

Permalink
fix: Empty list items returns incorrectly formatted Markdown (#874)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfgamaral authored Aug 16, 2024
1 parent b63e92b commit 9c8bcb5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
36 changes: 36 additions & 0 deletions src/serializers/markdown/markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ const HTML_INPUT_ORDERED_LISTS = `<ol>
<li>Fourth item</li>
</ol>
<hr>
<ol>
<li>First item</li>
<li></li>
<li>Third item</li>
</ol>
<hr>
<ol start="5">
<li>First item</li>
<li>Second item</li>
Expand Down Expand Up @@ -91,6 +97,12 @@ const HTML_INPUT_UNORDERED_LISTS = `<ul>
<hr>
<ul>
<li>First item</li>
<li></li>
<li>Third item</li>
</ul>
<hr>
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item<ul>
<li>Indented item</li>
Expand Down Expand Up @@ -447,6 +459,12 @@ Strikethrough uses two tildes: ~~scratch this~~`,
---
1. First item
2.
3. Third item
---
5. First item
6. Second item
7. Third item
Expand All @@ -471,6 +489,12 @@ Strikethrough uses two tildes: ~~scratch this~~`,
---
- First item
-
- Third item
---
- First item
- Second item
- Third item
Expand Down Expand Up @@ -725,6 +749,12 @@ See the section on [\`code\`](#code).`,
---
1. First item
2.
3. Third item
---
5. First item
6. Second item
7. Third item
Expand All @@ -749,6 +779,12 @@ See the section on [\`code\`](#code).`,
---
- First item
-
- Third item
---
- First item
- Second item
- Third item
Expand Down
4 changes: 2 additions & 2 deletions src/serializers/markdown/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const INITIAL_TURNDOWN_OPTIONS: Turndown.Options = {

// Return the list marker for empty bullet list items
if (node.nodeName === 'UL' || (parentNode?.nodeName === 'UL' && node.nodeName === 'LI')) {
return `${BULLET_LIST_MARKER} `
return `${BULLET_LIST_MARKER} \n`
}

// Return the list marker for empty ordered list items
Expand All @@ -73,7 +73,7 @@ const INITIAL_TURNDOWN_OPTIONS: Turndown.Options = {
: (node as HTMLElement).getAttribute('start')
const index = Array.prototype.indexOf.call(parentNode.children, node)

return `${start ? Number(start) + index : index + 1}. `
return `${start ? Number(start) + index : index + 1}. \n`
}

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down

0 comments on commit 9c8bcb5

Please sign in to comment.