Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle line breaks #42

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

r-o-b-o-t-o
Copy link

What does it do?

Transforms \n, \r\n and \r into <br /> tags in <Text />

Why is it needed?

Fixes #37

How to test it?

  • Create rich text blocks with line returns in them (⇧+⏎ in the rich text editor)
  • Render them with <BlocksRenderer />
  • Make sure the newline characters are replaced by <br /> tags

@r-o-b-o-t-o r-o-b-o-t-o changed the title Fix/lf to br fix: handle line breaks Jul 5, 2024
@leelawtondesign
Copy link

This worked perfectly for me, thanks!

@antoine-roux
Copy link

It would be nice to merge :)

@pbozyk
Copy link

pbozyk commented Oct 25, 2024

we need this in production pack! that would be nice.

@r-o-b-o-t-o
Copy link
Author

r-o-b-o-t-o commented Oct 28, 2024

In the meantime, my fork is available on npm: @roboto_/strapi-blocks-react

Copy link
Contributor

@remidej remidej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, could you just add a unit test too?

And sorry I wasn't aware of this PR, it's been a while so if you don't want to get back to it we can make another PR internally

Comment on lines +24 to +25
<React.Fragment key={idx}>
{!!idx && <br />}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!!idx isn't very readable, could you instead check if it's > 0?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feat]: Support for Interpreting \n as Line Breaks
5 participants