-
Notifications
You must be signed in to change notification settings - Fork 41
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
[StoryblokRichText] Nested <p> tag inside of lists. #1351
Comments
Hi @christopher-ha thanks for opening this ticket. So the reason why the
Having a resolvers: {
[BlockTypes.LIST_ITEM]: (node: StoryblokRichTextNode<string>) => {
const text = node.content[0].content[0].text; // Gets the text inside of the p tag
return `<li>${text}</li>`;
},
}, By overwriting the resolver, you now skip the p tag, be aware that if you want to show some mark types like bold, or italic, you might need to tweak it further. Hope that helps |
Update: since the workaround above covers usage with the vanilla const { render } = richTextResolver({
renderFn: React.createElement,
keyedResolvers: true,
});
const options: StoryblokRichTextOptions<ReactElement> = {
renderFn: React.createElement,
resolvers: {
[BlockTypes.LIST_ITEM]: (node: StoryblokRichTextNode<string>) => {
return render(node.content?.[0]);
},
},
keyedResolvers: true,
};
const html = richTextResolver(
options,
).render(story.content.richtext); Here we can use the render function returned by the [BlockTypes.LIST_ITEM]: (node: StoryblokRichTextNode<string>, render) => {
return render(node.content?.[0]);
}, I will work on it. |
A workaround I'm using is, when using tailwind is, in my case I only need to reset the margin: [BlockTypes.LIST_ITEM]: (node: StoryblokRichTextNode<ReactElement>) => {
const uniqueKey = `li-${elementCounter++}`;
return (
// We need this because <Paragraph> adds margin and
// Storyblok adds a <p> in list items
<li key={uniqueKey} className={"*:m-0!"}>
{node.children}
</li>
);
} The |
Describe the issue you're facing
You can see here that typing on a list element generates a new paragraph tag, when the resolver should skip over rendering this. This is causing issues in my blog where if I have styling specifically for paragraphs like how much width it will take up, it gets applied inside of the list element and really messes up the layout.
The ideal behaviour of this is that the resolver does not render the nested paragraph tag and just places the content of it inside of the ul, ol, etc.
Apparently the Astro library doesn't do this?
No reproduction link since it's on my client's repository.
Reproduction
https://localhost:3000
Steps to reproduce
Create an ordered list an unordered list on Storyblok and render it using the rich text resolver. You will see in the console log, it's rendering the nested structure.
It happens on both the richTextResolver and also the new component.
System Info
Used Package Manager
npm
Error logs (Optional)
No response
Validations
The text was updated successfully, but these errors were encountered: