defuddle icon indicating copy to clipboard operation
defuddle copied to clipboard

Table header rows, cells and sections removed by class/id selectors (Pandoc, Quarto, Microsoft Learn)

Open davszp opened this issue 1 month ago • 0 comments

Some selectors in EXACT_SELECTORS / PARTIAL_SELECTORS remove elements by words in their class or id, whatever the element is:

  1. Header rows. .header removes <tr class="header"> (Pandoc, Quarto, Microsoft Learn). The first data row becomes the header (the table part of #395).
  2. Cells. A cell removed by its class (td.date, td.timestamp, …) takes its column with it; every later value of the row shifts under the wrong heading.
  3. Sections. Pandoc and Quarto give each section.levelN an id from its heading (sec-taxonomy, …-with-additive-errors). The id matches a pattern and the whole section is removed (the "11.2 Two types of errors" report in #395).

Example (quarto.org/docs/authoring/tables.html), before:

| 12 | 12 | 12 | 12 |
| --- | --- | --- | --- |
| 123 | 123 | 123 | 123 |

after:

| Default | Left | Right | Center |
| --- | --- | --- | --- |
| 12 | 12 | 12 | 12 |

Fix. Following two rules selectors.ts already has (pre/code skipped, heading ids not matched):

  • table rows and cells are never removed by name, except in tables holding code (Hexo's td.gutter is still removed);
  • a section.levelN id is not matched when it is its heading's slug or a sec- label (section#related-posts is still removed).

Tested on 768 real pages, 0.19.6 with and without the fix: 13 change, all for the better, none for the worse; the other 755 are byte-identical. Header rows return on all 35 tables of Microsoft's exFAT spec, 16 tables of Quarto's own table guide, and tables on otexts' Forecasting (fpp2/fpp3) and gwern.net; five lost sections return on otexts and one in the Pandoc manual; values return to their columns on three pages.

Possible PR: one file, src/removals/selectors.ts, +49 / −2 lines, plus three fixtures with expected output (112 lines) that fail before and pass after. Full suite passes with linkedom and JSDOM.

Overlaps #399, which its author closed. Would you like a PR, or would you rather fix it yourself?

davszp avatar Oct 29 '26 17:10 davszp