Page MenuHomePhabricator

Trailing newlines of templates that get span-wrapped can sometimes break CSS
Open, Needs TriagePublic

Description

Compare rendering on enwiki:Zacharie Boucher: Parsoid vs default parser. If you scroll to the bottom of the article to the navboxes, you will see excess whitespcae between the two collapsed boxes. Same on enwiki:Ergocalciferol or enwiki:Barack_Obama_2008_presidential_campaign and many others. You will see some extra whitespace between two navboxes which is pretty jarring when the boxes are collapsed.

If you inspect the HTML around the whitespace and look at the CSS that applies to Parsoid HTML vs legacy HTML, you will see this CSS selector .mw-parser-output .navbox + .navbox, .mw-parser-output .navbox + .navbox-styles + .navbox that applies to the default parser HTML. On the Parsoid side, there is a <span about="#mwt...">\n</span> between a div.navbox-styles and a div.navbox which prevents the CSS selector from applying.

One option is to try to make the CSS less sensitive. But, there is a simple fix on the Parsoid HTML side. Trailing newlines from templates that get span-wrapped can be stripped altogether. As a literal \n character in HTML, they don't influence rendering. And, being part of a template, they don't play any role in round-tripping either. So, it is safe to delete these spans from Parsoid output which also eliminates this jarring whitespace difference in Parsoid output.