mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-08-03 12:57:20 +02:00
Compare commits
No commits in common. "c00591c1b6910600f2d1128018752d81f2e531dc" and "58ac273f1f36b3d01b21f2a07b19f5884eca1b2a" have entirely different histories.
c00591c1b6
...
58ac273f1f
@ -544,71 +544,4 @@ describe("accessibility", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("A TH in a TR itself in a TBody is rowheader", () => {
|
|
||||||
let pages;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
pages = await loadAndWait("bug2014080.pdf", ".textLayer");
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
await closePages(pages);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("must check that the table has the right structure", async () => {
|
|
||||||
await Promise.all(
|
|
||||||
pages.map(async ([browserName, page]) => {
|
|
||||||
let elementRole = await page.evaluate(() =>
|
|
||||||
Array.from(
|
|
||||||
document.querySelector(".structTree [role='table']").children
|
|
||||||
).map(child => child.getAttribute("role"))
|
|
||||||
);
|
|
||||||
|
|
||||||
// THeader and TBody must be rowgroup.
|
|
||||||
expect(elementRole)
|
|
||||||
.withContext(`In ${browserName}`)
|
|
||||||
.toEqual(["rowgroup", "rowgroup"]);
|
|
||||||
|
|
||||||
elementRole = await page.evaluate(() =>
|
|
||||||
Array.from(
|
|
||||||
document.querySelector(
|
|
||||||
".structTree [role='table'] > [role='rowgroup'] > [role='row']"
|
|
||||||
).children
|
|
||||||
).map(child => child.getAttribute("role"))
|
|
||||||
);
|
|
||||||
|
|
||||||
// THeader has 3 columnheader.
|
|
||||||
expect(elementRole)
|
|
||||||
.withContext(`In ${browserName}`)
|
|
||||||
.toEqual(["columnheader", "columnheader", "columnheader"]);
|
|
||||||
|
|
||||||
elementRole = await page.evaluate(() =>
|
|
||||||
Array.from(
|
|
||||||
document.querySelector(
|
|
||||||
".structTree [role='table'] > [role='rowgroup']:nth-child(2)"
|
|
||||||
).children
|
|
||||||
).map(child => child.getAttribute("role"))
|
|
||||||
);
|
|
||||||
|
|
||||||
// TBody has 5 rows.
|
|
||||||
expect(elementRole)
|
|
||||||
.withContext(`In ${browserName}`)
|
|
||||||
.toEqual(["row", "row", "row", "row", "row"]);
|
|
||||||
|
|
||||||
elementRole = await page.evaluate(() =>
|
|
||||||
Array.from(
|
|
||||||
document.querySelector(
|
|
||||||
".structTree [role='table'] > [role='rowgroup']:nth-child(2) > [role='row']:first-child"
|
|
||||||
).children
|
|
||||||
).map(child => child.getAttribute("role"))
|
|
||||||
);
|
|
||||||
// First row has a rowheader and 2 cells.
|
|
||||||
expect(elementRole)
|
|
||||||
.withContext(`In ${browserName}`)
|
|
||||||
.toEqual(["rowheader", "cell", "cell"]);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -872,4 +872,3 @@
|
|||||||
!page_with_number_and_link.pdf
|
!page_with_number_and_link.pdf
|
||||||
!Brotli-Prototype-FileA.pdf
|
!Brotli-Prototype-FileA.pdf
|
||||||
!bug2013793.pdf
|
!bug2013793.pdf
|
||||||
!bug2014080.pdf
|
|
||||||
|
|||||||
Binary file not shown.
@ -61,8 +61,8 @@ const PDF_ROLE_TO_HTML_ROLE = {
|
|||||||
TR: "row",
|
TR: "row",
|
||||||
TH: "columnheader",
|
TH: "columnheader",
|
||||||
TD: "cell",
|
TD: "cell",
|
||||||
THead: "rowgroup",
|
THead: "columnheader",
|
||||||
TBody: "rowgroup",
|
TBody: null,
|
||||||
TFoot: null,
|
TFoot: null,
|
||||||
// Standard structure type Caption
|
// Standard structure type Caption
|
||||||
Caption: null,
|
Caption: null,
|
||||||
@ -353,7 +353,7 @@ class StructTreeLayerBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#walk(node, parentNodes = []) {
|
#walk(node) {
|
||||||
if (!node) {
|
if (!node) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -378,14 +378,7 @@ class StructTreeLayerBuilder {
|
|||||||
element.setAttribute("role", "heading");
|
element.setAttribute("role", "heading");
|
||||||
element.setAttribute("aria-level", match[1]);
|
element.setAttribute("aria-level", match[1]);
|
||||||
} else if (PDF_ROLE_TO_HTML_ROLE[role]) {
|
} else if (PDF_ROLE_TO_HTML_ROLE[role]) {
|
||||||
element.setAttribute(
|
element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
|
||||||
"role",
|
|
||||||
role === "TH" &&
|
|
||||||
parentNodes.at(-1)?.role === "TR" &&
|
|
||||||
parentNodes.at(-2)?.role === "TBody"
|
|
||||||
? "rowheader" // TH inside TR itself in TBody is a rowheader.
|
|
||||||
: PDF_ROLE_TO_HTML_ROLE[role]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (role === "Figure" && this.#addImageInTextLayer(node, element)) {
|
if (role === "Figure" && this.#addImageInTextLayer(node, element)) {
|
||||||
return element;
|
return element;
|
||||||
@ -430,11 +423,9 @@ class StructTreeLayerBuilder {
|
|||||||
// parent node to avoid creating an extra span.
|
// parent node to avoid creating an extra span.
|
||||||
this.#setAttributes(node.children[0], element);
|
this.#setAttributes(node.children[0], element);
|
||||||
} else {
|
} else {
|
||||||
parentNodes.push(node);
|
|
||||||
for (const kid of node.children) {
|
for (const kid of node.children) {
|
||||||
element.append(this.#walk(kid, parentNodes));
|
element.append(this.#walk(kid));
|
||||||
}
|
}
|
||||||
parentNodes.pop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return element;
|
return element;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user