Page MenuHomePhabricator

When using multiple paragraphs in AW the whitespace is double
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

What happens?:
Too much white space between the various paragraph() functions

Screenshot 2026-04-21 at 15.17.28.png (3,044×1,586 px, 658 KB)

What should have happened instead?:
Less whitesace , default wiki behaviour of the margins.

This is because of the <span>&nbsp;</span>. which works great on inline elements but not for paragraphs

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

Event Timeline

Root cause

Every AbstractPreviewFragment component appends a <span>&nbsp;</span> after its output. This acts as a word separator between inline fragments, but when a fragment renders a block-level element (e.g. paragraph()<p>…</p>), the &nbsp; adds extra whitespace on top of the paragraph's own CSS margins — causing the double spacing.

Two possible fixes

Option A: suppress &nbsp; when the last child is a block element

Parse the rendered HTML and check whether the last top-level element is block-level (p, div, h1h6, etc.). If so, omit the &nbsp;.

We check the last child because the &nbsp; follows the fragment output, so only the trailing element's display context matters.

This can be done with DOMParser at computed-property time. However, this is not great: DOMParser does not apply stylesheets, so if any CSS overrides the display of a tag (e.g. p { display: inline }), the check gives the wrong answer. The only fully reliable solution would be to call window.getComputedStyle() on the real DOM node after render — which adds significant reactivity complexity for a theoretical edge case.

Option B: remove the &nbsp; entirely

Remove <span>&nbsp;</span> and rely on function authors to insert correct whitespace in their output. Inline fragments that need a space between them would include it; block-level fragments like paragraph() handle their own spacing via CSS margins. This is simpler and unambiguously correct — but requires auditing all existing inline fragment functions to confirm they produce appropriate surrounding whitespace.

I propose the community adds a 'non-breaking html seperator function' , which returns a Z89 with <span>&nbsp;</span> and include this whenever needed -> WIP Patch if approved can go

Change #1275953 had a related patch set uploaded (by Daphne Smit; author: Daphne Smit):

[mediawiki/extensions/WikiLambda@master] abstract: Remove inline &nbsp; separator from AbstractPreviewFragment

https://gerrit.wikimedia.org/r/1275953

DSmit-WMF changed the task status from Open to In Progress.Apr 23 2026, 8:51 AM
DSmit-WMF claimed this task.
DSmit-WMF moved this task from To Triage to Bugs to investigate on the Abstract Wikipedia team board.
DSmit-WMF added a subscriber: DSantamaria.

Change #1275953 merged by jenkins-bot:

[mediawiki/extensions/WikiLambda@master] abstract: Remove inline &nbsp; separator from AbstractPreviewFragment

https://gerrit.wikimedia.org/r/1275953