rich-text
rich-text copied to clipboard
richTextFromMarkdown() doesn't include line breaks
richTextFromMarkdown doesn't seem to recognize line breaks. Markdown with two spaces and a line break should generate a \n in the text node in contentful rich text, but it just gets stripped. In the meantime, finding and replacing markdown linebreaks with \n before running richTextFromMarkdown is working for me:
let markdown = `test
test
test`
markdown = markdown.replace(/\s\s\n/g, '\n') //add line breaks
//returns 'test\ntest\ntest\n'
const content = await richTextFromMarkdown(markdown);
//includes \ns in the rich text nodes
This worked for me:
import { documentToReactComponents } from "@contentful/rich-text-react-renderer";
const options = {
renderNode: {
[BLOCKS.PARAGRAPH]: (node, children) => (
<>
<p>{children}</p>
<br />
</>
),
},
};
{documentToReactComponents(post.fields.content, options)}
You can add white-space: pre-wrap;
to the CSS of the parent element.
You can add
white-space: pre-wrap;
to the CSS of the parent element.
This worked, thank you!