Commit 70240220 authored by Guillaume's avatar Guillaume

resolves #224 fold page break before

parent fa6a12af
<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
<title>fold-page-breaks-after</title>
<meta charset="UTF-8">
<style>
header {
page: cover;
}
main {
page: matter;
}
section {
break-after: page;
}
footer {
page: footer;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="../../../dist/paged.polyfill.js"></script>
</head>
<body>
<header>
<h1>Title</h1>
</header>
<main>
<section>
<h2>Section 1</h2>
<p>This is a paragraph.</p>
</section>
<section>
<h2>Section 2</h2>
<p>This is a paragraph.</p>
</section>
</main>
<footer>
Copyright &copy; 2020
</footer>
</body>
</html>
const TIMEOUT = 10000;
describe("fold-page-breaks-after", () => {
let page;
beforeAll(async () => {
page = await loadPage("named-page/no-forced-page-break/fold-page-breaks-after.html");
return page.rendered;
}, TIMEOUT);
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
it("should fold page breaks after", async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
expect(pages).toEqual(4);
});
if (!DEBUG) {
it("should create a pdf", async () => {
let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(1);
expect(pdf).toMatchPDFSnapshot(2);
expect(pdf).toMatchPDFSnapshot(3);
expect(pdf).toMatchPDFSnapshot(4);
});
}
}
);
<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
<title>fold-page-breaks-before</title>
<meta charset="UTF-8">
<style>
header {
page: cover;
}
section {
break-before: page;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="../../../dist/paged.polyfill.js"></script>
</head>
<body>
<header>
<h1>Title</h1>
</header>
<main>
<section>
<h2>Section</h2>
<p>This is a paragraph.</p>
</section>
</main>
</body>
</html>
const TIMEOUT = 10000;
describe("fold-page-breaks", () => {
let page;
beforeAll(async () => {
page = await loadPage("named-page/no-forced-page-break/fold-page-breaks-before.html");
return page.rendered;
}, TIMEOUT);
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
it("should fold page breaks before", 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);
});
}
}
);
import Handler from "../handler";
import csstree from "css-tree";
import { displayedElementAfter, displayedElementBefore } from "../../utils/dom";
import { displayedElementAfter, displayedElementBefore, needsPageBreak } from "../../utils/dom";
class Breaks extends Handler {
constructor(chunker, polisher, caller) {
......@@ -93,10 +93,14 @@ class Breaks extends Handler {
} else if (prop.property === "break-before") {
let nodeBefore = displayedElementBefore(elements[i], parsed);
// Breaks are only allowed between siblings, not between a box and its container.
// If we cannot find a node before we should not break!
// https://drafts.csswg.org/css-break-3/#break-propagation
if (nodeBefore) {
// Breaks are only allowed between siblings, not between a box and its container.
// If we cannot find a node before we should not break!
// https://drafts.csswg.org/css-break-3/#break-propagation
if (prop.value === "page" && needsPageBreak(elements[i], nodeBefore)) {
// we ignore this explicit page break because an implicit page break is already needed
continue;
}
elements[i].setAttribute("data-break-before", prop.value);
nodeBefore.setAttribute("data-next-break-before", prop.value);
}
......
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