Skip to content

Treat u, s, and bdi as phrasing content (fixes #997) - #1032

Open
cpruijsen wants to merge 2 commits into
mozilla:mainfrom
cpruijsen:fix/issue-997
Open

cpruijsen wants to merge 2 commits into
mozilla:mainfrom
cpruijsen:fix/issue-997

Conversation

@cpruijsen

Copy link
Copy Markdown

Fixes #997.

PHRASING_ELEMS already included B and BDO but not U, S, or BDI. When Readability wraps a DIV's phrasing children into <p> tags, those tags were treated as breaks, so

<div>Seigneur, mon Die<u>u</u> et mon salut.</div>

became

<p>Seigneur, mon Die</p><u>u</u><p> et mon salut.</p>

and excerpt stopped at "Seigneur, mon Die". Same split for <s>, <bdi>, and for <a> that contains <u>.

The sample in the issue is a <p>. Wrapping of consecutive phrasing children only runs on DIV; a <p> that already contains <u> is left alone. The incorrect output in the issue is the DIV-wrapping result, which is what the test page uses.

Summary

  • Add U, S, and BDI to PHRASING_ELEMS (same list as B / BDO, matching HTML phrasing content).
  • In _replaceBrs, do not pull a phrasing sibling that contains a <br><br> chain into the new <p>. Those chains become paragraphs next; wrapping them nests <p> inside <p>/<u>, and jsdom and JSDOMParser then disagree, so hukumusume cannot stay green on both parsers. A single nested <br> is still pulled in (it does not become a paragraph).
  • Test page phrasing-u-s-bdi with the reporter's underline example plus <s> and <bdi> inside DIVs.

Decision

  • Chose: only U, S, BDI. Alternative: also PICTURE / MAP / AREA / SLOT / TEMPLATE. Reasoning: those three are what PHRASING_ELEMS missing <u>, <s>, and <bdi> elements causes paragraph splitting #997 asked for, and the list already deliberately omits some phrasing tags (CANVAS, IFRAME, SVG, VIDEO). Happy to add more if you want.
  • Chose: _replaceBrs skip when a phrasing node contains a <br><br> chain, rather than regenerating hukumusume/expected.html. Alternative: regenerate that fixture. Reasoning: JSDOMParser and jsdom then disagree on nested <p> inside <u>. Happy to switch if you want a parser picked as source of truth.

Test plan

  • npm test -- -g phrasing-u-s-bdi (jsdom + JSDOMParser)
  • npm test (existing pages, including hukumusume)
  • npm run lint
  • Optional: a live article that uses <u> / <s> / <bdi> inside DIV-wrapped paragraphs in Firefox Reader View

These HTML5 phrasing elements were omitted from PHRASING_ELEMS, so
DIV wrapping treated them as blocks and split paragraphs around them.
A single nested br does not become a paragraph, so skipping those
siblings dropped the paragraph created by an earlier br-br chain.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHRASING_ELEMS missing <u>, <s>, and <bdi> elements causes paragraph splitting

1 participant