Commit 17431e1f authored by Guillaume's avatar Guillaume
Browse files

resolves #259 should preserve white spaces in <pre> elements

parent 075718ae
<!DOCTYPE html PUBLIC>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Preformatted Text element</title>
<script src="../../../dist/paged.polyfill.js"></script>
<style>
@page {
size: 220mm 15mm;
margin: 0;
}
/* interface */
@media screen {
body {
background-color: whitesmoke;
}
.pagedjs_page {
margin-bottom: 0;
flex: none;
border-left: 1px solid rgba(0, 0,0,0.2);
border-right: 1px solid rgba(0, 0,0,0.2);
border-bottom: 1px dashed rgba(0, 0,0,0.1);
background-color: white;
}
.pagedjs_page:first-child {
border-top: 1px solid rgba(0, 0,0,0.2);
}
.pagedjs_page:last-child {
border-bottom: 1px solid rgba(0, 0,0,0.2);
}
}
</style>
</head>
<body>
<section>
<pre>
88888888ba 88 88
88 "8b 88 ""
88 ,8P 88
88aaaaaa8P' ,adPPYYba, ,adPPYb,d8 ,adPPYba, ,adPPYb,88 88 ,adPPYba,
88""""""' "" `Y8 a8" `Y88 a8P_____88 a8" `Y88 88 I8[ ""
88 ,adPPPPP88 8b 88 8PP""""""" 8b 88 88 `"Y8ba,
88 88, ,88 "8a, ,d88 "8b, ,aa "8a, ,d88 888 88 aa ]8I
88 `"8bbdP"Y8 `"YbbdP"Y8 `"Ybbd8"' `"8bbdP"Y8 888 88 `"YbbdP"'
aa, ,88 ,88
"Y8bbdP" 888P"
</pre>
</section>
</body>
</html>
const TIMEOUT = 10000;
describe("pre", () => {
let page;
beforeAll(async () => {
page = await loadPage("splits/pre/pre.html");
return page.rendered;
}, TIMEOUT);
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
it("should render 4 pages", async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => r.length);
expect(pages).toBe(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);
});
}
});
......@@ -336,10 +336,11 @@ export function *words(node) {
let currentLetter;
let range;
const significantWhitespaces = node.parentElement && node.parentElement.nodeName === 'PRE';
while(currentOffset < max) {
while (currentOffset < max) {
currentLetter = currentText[currentOffset];
if (/^[\S\u202F\u00A0]$/.test(currentLetter)) {
if (/^[\S\u202F\u00A0]$/.test(currentLetter) || significantWhitespaces) {
if (!range) {
range = document.createRange();
range.setStart(node, currentOffset);
......@@ -358,7 +359,6 @@ export function *words(node) {
if (range) {
range.setEnd(node, currentOffset);
yield range;
range = undefined;
}
}
......
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