Open Bug 2023945 Opened 8 months ago Updated 5 months ago

Reader mode whitespace normalization is not really correct

Categories

(Core :: Machine Learning: On Device, defect, P3)

defect

Tracking

()

People

(Reporter: gregtatum, Unassigned)

References

(Blocks 1 open bug)

Details

In Bug 2021462 I moved all whitespace normalization into PageExtractor from the tool calls. I implemented a simple whitespace collapsing algorithm that collapsed multiple spaces and newlines into single ones. The reader mode API returns the textContent of the document, which includes all whitespace of the HTML that is not actually presentational. The problem with collapsing whitespace at this level is that there is no way to properly determine what should actually be a newline.

https://drafts.csswg.org/css-text-4/#white-space-processing

Control characters (Unicode category Cc)—​other than tabs (U+0009), line feeds (U+000A), carriage returns (U+000D) and sequences that form a segment break—​must be rendered as a visible glyph which the UA must synthesize if the glyphs found in the font are not visible, and must be otherwise treated as any other character of the Other Symbols (So) general category and Common script. The UA may use a glyph provided by a font specifically for the control character, substitute the glyphs provided for the corresponding symbol in the Control Pictures block, generate a visual representation of its code point value, or use some other method to provide an appropriate visible glyph. As required by Unicode, unsupported Default_ignorable characters must be ignored for text rendering. [UNICODE]

Carriage returns (U+000D) are treated identically to spaces (U+0020) in all respects.

Here carriage returns are treated as spaces, so there is no semantic meaning in the textContent's whitespace.

I'm thinking a better solution here (which has a perf cost) would be to take the HTML text from reader mode, and then run it through a DOMParser to get the document, then run our DOMExtractor algorithm over it to get the whitespace. This way things like paragraph tags will be turned into newlines.

See Also: → 2052368
You need to log in before you can comment on or make changes to this bug.