question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

empty paragraph in richtext renders as 0px height content on page

See original GitHub issue

It looks like the template for paragraphs in the richtextfield render as <p></p> rather than as <p>&nbsp;</p>, which makes the empty paragraph show up in the richtextfield in the admin, but does not get reflected in the page content, as <p></p> is considered a kind of “non-content” by the DOM, and is rendered as if it’s not even there. The template for this block probably needs a fix that injects &nbsp; if the block’s value is empty.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
thibaudcolascommented, Mar 31, 2018

My idea is to allow control over this with CSS, and an :empty selector. Would that work for you, eg. setting a height for those blocks? This way your writers would get what they expect.

Of course having some control over the HTML itself would be even better, but we’re not there yet.

0reactions
Pomaxcommented, Aug 18, 2022

Note that <br> isn’t any better than just leaving the <p></p>, as the br element is intended for introducing a line break inside of text content, rather than being used between paragraph elements. Leaving the empty paragraph is actually semantically preferred, and then folks can still make it look however they want by adding custom CSS for .richtext p:empty.

But, it would be even better if there was a post-processing step that added a class that effects extra spacing below the preceding paragraph while removing the <p></p> altogether, so that:

<p>p with no content</p>
<p></p>
<p>p with nbsp:</p>

becomes something like:

<p class="gap-after">p with no content</p>
<p>p with nbsp:</p>

With default styling along the lines of:

.root {
  /* ... */
  --paragraph-margin-top: ...;
  --paragraph-margin-bottom: ...;
  /* ... */
}

...

.richtext p.gap-after {
  --t: var(--paragraph-margin-top);
  --b: var(--paragraph-margin-bottom);
  margin-bottom: calc(var(--t) + 2 * var(--b));
}

Essentially making sure that the paragraph uses the bottom margin it’s supposed to plus an extra paragraph worth or top and bottom margin.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Visualforce rich text input area spacing
Everything appears correct except the paragraph spacing is double spaced. Does anyone know how to control the vertical spacing? Is it a style ......
Read more >
How to set an empty paragraph element to the minimum ...
If a paragraph element is empty it has no height. How to set the minimum height to the text height (font-size)?. I know...
Read more >
How To Use Document Fields - Keystone 6 Documentation
Learn how to configure Keystone's highly customizable Rich Text editor. The Document field is built with Slate and stores your content as JSON-structured ......
Read more >
Safari Technology Preview Release Notes - Apple Developer
Rendering. Added width and height content attributes to <model> (257294@main) ... Implemented support for the Clear-Site-Data HTTP header (254745@main) ...
Read more >
Change line space in a rich text editor - Oracle Communities
I thought it will display it with the same line height but that did not happen. It was still displayed with a large...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found