question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing converted line breaks in rich-text-html-renderer

See original GitHub issue

When I’m using the rich-text-html-renderer I expect that also the line breaks are converted to HTML
also. Currently when I’ve some manual line breaks in a paragraph they are ignored completely.

Line1
Line2

should be converted to

<p>
Line1<br />
Line2
</p>

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:17

github_iconTop GitHub Comments

55reactions
DanweDEcommented, Jul 13, 2019

@quinnmyers The above comments and examples are mainly referring to using rich-text-html-renderer, not rich-text-react-renderer. That’s why these examples use next rather than children.

The documentation for rich-text-react-renderer actually gives an example for how to use the renderText option to replace \n line breaks with <br />.

Try using this options definition:

const options = {
  renderText: text => text.split('\n').flatMap((text, i) => [i > 0 && <br />, text])
}

You can see a working example on codesandbox.io.

20reactions
aalibaabaacommented, Jun 27, 2019

Thank you, @sbezludny for your code snipped above. It helped us allot See

renderNode: {
    [BLOCKS.PARAGRAPH]: (node, next) => next(node.content).replace('\n', '<br/>')
  }

I enhenced it a little bit, because your example stripped away the <p /> and only converted the first \n' into <br />

Maybe this is helpful for others as well

renderNode: {
  [BLOCKS.PARAGRAPH]: (node, next) => `<p>${next(node.content).replace(/\n/g, '<br/>')}</p>`,
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

[LEX] Rich Text Area in Merge Field Fails to Render Line ...
Notice that the line breaks are missing. Workaround Enter the text in Salesforce Classic in order to render the line breaks. Reported By...
Read more >
How do I preserve line breaks when getting text from a textarea?
Line breaks actually are preserved, the target element is just set to ignore them while displaying the text but if you inspect it...
Read more >
How to insert line break into Rich Text field from Field Update
I've tried using BR() to insert line breaks but I don't see that line break when viewing the standard detail page for the...
Read more >
Line breaks on the Rich Text editor - Contentful Community
I'm using contentful with Next.js. My first attempt was using a long text field with markdown, then converting the markdown to HTML with...
Read more >
Line breaks in Text(64000) fields not recognized in html block ...
As a workaround, we can use a Formula field in our table to replace the string line breaks with HTMl <br> tag so...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found