strapi / blocks-react-renderer

A React renderer for the Strapi's Blocks rich text editor
Other
107 stars 15 forks source link

[feat]: Support for Interpreting \n as Line Breaks #37

Open ringm opened 1 month ago

ringm commented 1 month ago

A clear and concise description of what the feature is

It would be incredibly helpful if blocks-react-renderer could support interpreting \n characters as line breaks in text strings.

Why should this feature be included?

This feature is essential for rendering multiline text more intuitively, especially when dealing with user-generated content or preformatted text blocks. This lack of line break support necessitates additional string manipulation and mapping in the component code, which complicates the rendering process and adds extra overhead.

Please provide an example for how this would work

Currently, when a text string containing \n characters is rendered, the \n characters are not converted into HTML line breaks (
). For example, a text string like "This is a heading and \n\n I want this to be on a new line" is rendered as a single continuous line rather than as:

This is a heading and I want this to be on a new line

Handling line breaks natively in blocks-react-renderer aligns with common text rendering practices and enhances the library's usability in more diverse text formatting scenarios.

Thank you for considering this feature request.

larswittenberg commented 1 week ago

Is there any news about this bug?

Strapi 4.25.1 Next. js 14.2.4 @strapi/blocks-react-renderer 1.0.1

My data

console.log data

was rendered as <p>Line 1 at this parapraph Next Line after line-break</p>