Data tables are removed as "unlikely candidates" when a class name contains "header" (e.g. Wikipedia's plainrowheaders)

Đang mở Phù hợp với người mới
#1,036 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

@axchadxs đang làm issue này rồi.

Từ ngày 26/10/2026.

  • #1038 của @axchadxs — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript
Lĩnh vực
web-dev

Hướng nghiên cứu

Bắt đầu với bước kiểm tra các ứng viên ít có khả năng trong _grabArticle và các bài kiểm thử hiện có về việc loại bỏ ứng viên và bảng. Tái hiện vấn đề bằng ví dụ được cung cấp, sau đó xác minh rằng một bảng có lớp header và các dấu hiệu của bảng dữ liệu được giữ lại, trong khi các bảng bố cục vẫn được xử lý bằng bước dọn dẹp có điều kiện hiện có.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

A data table whose class contains header is removed whole by the unlikely-candidate pass in _grabArticle, because REGEXPS.unlikelyCandidates matches header anywhere in the class string. Wikipedia uses class="wikitable sortable plainrowheaders" on many award, filmography and discography tables, so those tables disappear from the output.

Elements inside a table are already exempt (!this._hasAncestorTag(node, "table")), but the <table> element itself is not.

Steps to reproduce

Readability 0.6.0 with jsdom 26.1.0 (the same check exists on main at ab4027a8):

import { Readability } from "@mozilla/readability";
import { JSDOM } from "jsdom";

const para = (n) => Array.from({ length: n }, (_, i) =>
  `<p>Paragraph ${i} of the article, long enough to be scored as content, with commas, clauses, and ordinary prose like a real page.</p>`).join("\n");
const table = (cls) => `<table class="${cls}"><caption>Awards</caption>
<tr><th>Award</th><th>Result</th></tr>
<tr><th scope="row">Academy Awards</th><td>Nominated</td></tr>
<tr><th scope="row">Annie Awards</th><td>Won</td></tr></table>`;
const run = (body) => new Readability(
  new JSDOM(`<!doctype html><html><body><article>${body}</article></body></html>`).window.document
).parse().content;

for (const cls of ["wikitable", "wikitable plainrowheaders"]) {
  console.log(cls, "→ table kept:", run(para(5) + table(cls) + para(2)).includes("Annie Awards"));
}

Output:

wikitable → table kept: true
wikitable plainrowheaders → table kept: false

With debug: true the log shows Removing unlikely candidate - wikitable sortable plainrowheaders ….

Real page: https://en.wikipedia.org/wiki/The_Wild_Robot_(film). The "Accolades" table (118 rows) is missing from the output.

Expected

A data table (one with a caption or <th> cells) is kept. In a table, "header" usually refers to the table's own header cells, not to the page header.

Possible fix

Exempt <table> elements from the unlikely-candidate check in the same way their descendants already are, or at least tables that _markDataTables would treat as data tables. Layout tables would still go through _cleanConditionally.

Related: #775 (also Wikipedia tables, different symptom).

Ngôn ngữ chính
JavaScript
Star
11.5k
Fork
741
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của mozilla/readability

Tất cả issue của mozilla/readability

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.