When passing markdown to the Markdown component, avoid writing markdown directly inside JSX tags, as JSX collapses whitespace and line endings, which breaks markdown formatting.
To ensure correct rendering, use one of the following patterns:
- Use a variable: Store your markdown in a variable and pass it as an expression. Do not indent the markdown content inside the variable.
- Use a template literal expression: Pass a template literal as an expression. Be careful with indentation inside template literals, as leading whitespace will be interpreted as an indented code block rather than markdown syntax (like headings).
Avoid this (JSX collapses whitespace):
<Markdown>
# Hi
</Markdown>
Avoid this (Indentation creates code blocks):
<Markdown>{`
# This is an indented code block, not a heading
`}</Markdown>
// Recommended: Use a variable without indentation
const markdown = `
# This is perfect!
`
const result = <Markdown>{markdown}</Markdown>
// Alternative: Use a template literal expression
<Markdown>{`
# Hi
This is a paragraph.
`}</Markdown>