Empty p tags is being generated
See original GitHub issueI read that rich text would remove the unnecessary empty <p></p>
tags generated from the text editor. But for some reason, I’m still getting p tags.
Here’s what my sample code looks like
const options = {
renderNode: {
[BLOCKS.HEADING_1]: (node, children) => <h1>{children}</h1>,
[BLOCKS.HEADING_5]: (node, children) => <h5>{children}</h5>,
[BLOCKS.EMBEDDED_ASSET]: (node) => {
const fileUrl = node.data.target.fields.file['en-US'].url
return (
<ContentfulFixedAsset
fileUrl={fileUrl}
/>
)
}
}
}
documentToReactComponents(richText, options)
What am i doing wrong?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:16
Top Results From Across the Web
An empty <p> tag is automatically getting inserted, how do I ...
Here is the code which renders the HTML block: The <p></p> tag gets generated dynamically, but not sure, how it is getting generated...
Read more >Wrapping drupal-media image in a link produces empty P tags ...
There's an issue when linking a media item in the editor whereby it adds empty P tags. It seems to happen when the...
Read more >How to Remove Empty Paragraph Tags from Shortcodes in ...
Easily learn how to remove empty paragraph (p) tags from shortcodes in WordPress with this simple code snippet. The fix takes seconds!
Read more >Empty P tags. Grr. | ExpressionEngine 2 Tech Support
I'm not sure I'm being clear… here's essentially what I'm entering into the XHTML-ized field: some text that gets wrapped in a P...
Read more >Showing empty p tags in views on the front end. - Toolset
This support ticket is created 3 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Honestly the easiest work-around is CSS, and what I use is simple. CSS:
p:empty { display: none; }
Any paragraph tag that is empty, hide it. You can use this universally like the above. Or more specifically wrap your displayed Contentful richtext entries in a div classed as such..richtext > p:empty { display:none; }
This can be problematic for clients who like to add vertical space with p tags but it’s better than having my layout wrecked by either the content editor or the CMS.
This is a bit of a nuisance problem, so I understand why it’s not high on the priorities, hope the above workaround helps!
Wondering how this has not been fixed with the issue being open since 2019