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

[bug]: The code function isn't called. #54

Open
monolithed opened this issue Nov 20, 2024 · 1 comment
Open

[bug]: The code function isn't called. #54

monolithed opened this issue Nov 20, 2024 · 1 comment
Labels
issue: bug Issue reporting a bug

Comments

@monolithed
Copy link

monolithed commented Nov 20, 2024

What version of @strapi/blocks-react-renderer are you using?

npm, node, react, strapi-* - the latest versions

What's Wrong?

The code below is likely working, but Strapi returns the data in a different format. The API returns the Code block inside a Paragraph, and the function code is never called.

it('parses code blocks to plain text', () => {

 <BlocksRenderer
          content={[
            {
              type: 'code',
              children: [
                {
                  type: 'text',
                  text: 'const a = 1;',
                },
                {
                  type: 'link',
                  url: 'https://test.com',
                  children: [{ type: 'text', text: 'const b = 2;', bold: true }],
                },
              ],
            },
          ]}
</>

Below, I have attached a screenshot of the server's response:

Screenshot 2024-11-20 at 13 33 05

Here is my workaround:

            <BlocksRenderer content={children}
                            blocks={{
                                paragraph: ({children}) => {
                                    return (
                                        <p>
                                            {
                                                React.Children.map(children, (item) => {
                                                    const {props: {code, text}} = item;

                                                    if (code) {
                                                        return <span className={styles.highlight}>{text}</span>;
                                                    }
                                                    return item;
                                                })
                                            }
                                        </p>
                                    )
                                },

To Reproduce

Open DevTools...

Expected Behaviour

The code function should be called.

@monolithed monolithed added the issue: bug Issue reporting a bug label Nov 20, 2024
@monolithed
Copy link
Author

Also, I'd like to point out that in the current implementation, ther're no types for the children property.

Screenshot 2024-11-20 at 19 20 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug Issue reporting a bug
Projects
None yet
Development

No branches or pull requests

1 participant