Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Don't leave table rows and cells without a table - #1045

Open
mnaoumov wants to merge 1 commit into
mozilla:mainfrom
mnaoumov:fix-orphaned-table-parts
Open

mnaoumov wants to merge 1 commit into
mozilla:mainfrom
mnaoumov:fix-orphaned-table-parts

Conversation

@mnaoumov

@mnaoumov mnaoumov commented Dec 3, 2026

Copy link
Copy Markdown

Fixes #775

The problem

When a <table>, or a part of one, is picked as the top candidate or as a sibling to keep, _grabArticle renames it to <div>. Its rows and cells stay as they are, so the output contains <tbody>, <tr> or <td> without a <table>. Browsers drop such tags when they parse the result again.

The Wikipedia page from the issue no longer triggers this, because its HTML has changed since. The ctext.org example from the comments still does on main.

The fix

  1. If the top candidate is a <thead>, <tbody>, <tfoot> or <tr> of a data table, the whole table is used instead, with the higher of the two scores. This is skipped for a table with nested tables. lwn-1 has such a layout table, which looks like a data table because of a nested <th>, and its navigation would come back otherwise.
  2. A data table is no longer renamed to <div>.
  3. What is left of layout tables is replaced after the cleanup: rows with <div>, cells with <p> or <div>. This follows what is already done for single-cell tables.

The ctext.org example is still seen as a layout table, so it now gives plain <div> and <p> elements.

Tests

Three new test pages with made-up text:

  1. data-table-top-candidate: a data table is the main content.
  2. data-table-with-text: text next to a data table. On main the text is lost too.
  3. layout-table-top-candidate: the same shape as the ctext.org example.

Two existing pages had <td> without a table in their expected output, and that is now gone: hukumusume (td became div or p) and lwn-1 (two wrappers and an empty cell are removed). The lwn-1 diff is mostly indentation, so it is easier to read with whitespace changes hidden.

npm run lint and npm test pass.

A table (or a part of one) that was picked as the top candidate or as its
sibling was turned into a div, which left its rows and cells behind as
invalid markup. Keep data tables whole, and turn what is left of layout
tables into divs and paragraphs.

Fixes mozilla#775
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.

<table> tag can be mistakenly trimmed

1 participant