-
Notifications
You must be signed in to change notification settings - Fork 25
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
base: main
Are you sure you want to change the base?
Conversation
This worked perfectly for me, thanks! |
It would be nice to merge :) |
we need this in production pack! that would be nice. |
In the meantime, my fork is available on npm: @roboto_/strapi-blocks-react |
There was a problem hiding this 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
Please roll out your own PR if it's ready. It’s kinda hard to work without line breaks 😞 |
Here's a tmp workaround: const replaceNewlines = (line: string) => {
const text = line.split(/\r?\n|\r/g);
return (
<>
{
text.map((part, index) => (
<React.Fragment key={index}>
{index > 0 && <br/>} {part}
</React.Fragment>
))
}
</>
);
}; <BlocksRenderer content={children}
blocks={{
paragraph: ({children}) => {
return (
React.Children.map(children, (child) => {
if (React.isValidElement(child)) {
const {props = {text}, ...rest} = child as Child;
/** @fix https://github.com/strapi/blocks-react-renderer/pull/42/files */
if (typeof text === 'string') {
return {
...rest,
props: {
...child.props,
text: replaceNewlines(text)
}
};
}
}
return child;
})
)
}
/> |
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?
<BlocksRenderer />
<br />
tags