Currently I'm using React and have content in my rich text in strapi CMS that is spaced out the way I want it in my markdown version, but as soon as I switch to preview, or view the content in my browser, the spaces go away. I have tried adding <br/> tags, but there was still no line breaks.
This is the content in my strapi markdown:
](https://i.sstatic.net/EpF2z.png)
But this is the output on my webpage:
](https://i.sstatic.net/vr5ZH.png)
This is my current code:
import ReactMarkdown from "react-markdown";
import rehypeRaw from "rehype-raw";
export default function name({ posts }) {
return (
<>
<div>
{posts.Title}
</div>
<div>
<ReactMarkdown children={posts.Content} rehypePlugins={[rehypeRaw]} />
</div>
</>
);
}
use remark-breaks
and replace \n with \n. if one \n doesn't work, try adding one more
import remarkBreaks from "remark-breaks";
//...
<ReactMarkdown
remarkPlugins={[remarkBreaks]}
rehypePlugins={[rehypeRaw]}
children={posts.Content.replace(/\n/gi, " \n")}
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With