Commit f21bf115 authored by Fred Chasen's avatar Fred Chasen

Merge branch 'named-page-ignore-undisplayed-nodes' into 'master'

Undisplayed nodes should not generate a page break

See merge request tools/pagedjs!129
parents 59191637 d58f3e6b
<!DOCTYPE html>
<html lang="en">
<head>
<title>no-forced-page-break</title>
<meta charset="UTF-8">
<script src="../../../dist/paged.polyfill.js"></script>
<style>
#toc {
page: tableofcontents;
}
section {
page: section;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<header>
<div id="toc"><h1>Table of Contents</h1></div>
<div style="display: none;"><ul class="sectlevel1">
<li class="toc-entry"><a href="#section-1">Section 1</a></li>
</ul></div>
<section>
<h2 id="section-1">Section 1</h2>
</section>
</header>
</body>
</html>
const TIMEOUT = 10000;
describe("ignore-undisplayed-nodes", () => {
let page;
beforeAll(async () => {
page = await loadPage("named-page/no-forced-page-break/ignore-undisplayed-nodes.html");
return page.rendered;
}, TIMEOUT);
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
it("should not force a page break after an undisplayed element and render only 2 pages", async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
expect(pages).toEqual(2);
});
if (!DEBUG) {
it("should create a pdf", async () => {
let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(1);
expect(pdf).toMatchPDFSnapshot(2);
});
}
});
......@@ -286,6 +286,9 @@ export function needsPageBreak(node, previousSignificantNode) {
if (typeof node === "undefined" || !previousSignificantNode || isIgnorable(node)) {
return false;
}
if (node.dataset && node.dataset.undisplayed) {
return false;
}
const previousSignificantNodePage = previousSignificantNode.dataset ? previousSignificantNode.dataset.page : undefined;
const currentNodePage = node.dataset ? node.dataset.page : undefined;
return currentNodePage !== previousSignificantNodePage;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment