Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/angry-lights-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-email/markdown": patch
---

fix nested lists not working
5 changes: 5 additions & 0 deletions .changeset/silent-maps-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-email/components": patch
---

markdown: fix nested lists not working
18 changes: 18 additions & 0 deletions packages/markdown/src/__snapshots__/markdown.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ exports[`<Markdown> component renders correctly > renders lists in the correct f
</div><!--/$-->"
`;

exports[`<Markdown> component renders correctly > renders nested lists in the correct format for browsers 1`] = `
"<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><!--$--><div data-id="react-email-markdown"><ul>
<li><p>parent list item</p>
<ul>
<li>nested list item 1</li>
<li>nested list item 2</li>
</ul>
</li>
<li><p>another parent item</p>
<ol>
<li>nested ordered item 1</li>
<li>nested ordered item 2</li>
</ol>
</li>
</ul>
</div><!--/$-->"
`;

exports[`<Markdown> component renders correctly > renders text in the correct format for browsers 1`] = `
"<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><!--$--><div data-id="react-email-markdown"><p><strong style="font:700 23px / 32px &#x27;Roobert PRO&#x27;, system-ui, sans-serif;background:url(&#x27;path/to/image&#x27;)">This is sample bold text in markdown</strong> and <em style="font-style:italic">this is italic text</em></p>
</div><!--/$-->"
Expand Down
16 changes: 16 additions & 0 deletions packages/markdown/src/markdown.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,20 @@ console.log(\`Hello, $\{name}!\`);
);
expect(actualOutput).toMatchSnapshot();
});

it('renders nested lists in the correct format for browsers', async () => {
const actualOutput = await render(
<Markdown>
{`
- parent list item
- nested list item 1
- nested list item 2
- another parent item
1. nested ordered item 1
2. nested ordered item 2
`}
</Markdown>,
);
expect(actualOutput).toMatchSnapshot();
});
});
5 changes: 4 additions & 1 deletion packages/markdown/src/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ export const Markdown = React.forwardRef<HTMLDivElement, MarkdownProps>(
};

renderer.listitem = ({ tokens }) => {
const text = renderer.parser.parseInline(tokens);
const hasNestedList = tokens.some((token) => token.type === 'list');
const text = hasNestedList
? renderer.parser.parse(tokens)
: renderer.parser.parseInline(tokens);

return `<li${
parseCssInJsToInlineCss(finalStyles.li) !== ''
Expand Down
Loading