diff --git a/specs/splits/pre/__image_snapshots_linux__/pre-spec-js-pre-should-create-a-pdf-1-snap.png b/specs/splits/pre/__image_snapshots_linux__/pre-spec-js-pre-should-create-a-pdf-1-snap.png new file mode 100644 index 0000000000000000000000000000000000000000..cb52af74162de9f240699c6dd36a65fd42b5aea5 Binary files /dev/null and b/specs/splits/pre/__image_snapshots_linux__/pre-spec-js-pre-should-create-a-pdf-1-snap.png differ diff --git a/specs/splits/pre/__image_snapshots_linux__/pre-spec-js-pre-should-create-a-pdf-2-snap.png b/specs/splits/pre/__image_snapshots_linux__/pre-spec-js-pre-should-create-a-pdf-2-snap.png new file mode 100644 index 0000000000000000000000000000000000000000..3866d02cbc6690f02ec6f5bc713ad212a9baaf37 Binary files /dev/null and b/specs/splits/pre/__image_snapshots_linux__/pre-spec-js-pre-should-create-a-pdf-2-snap.png differ diff --git a/specs/splits/pre/__image_snapshots_linux__/pre-spec-js-pre-should-create-a-pdf-3-snap.png b/specs/splits/pre/__image_snapshots_linux__/pre-spec-js-pre-should-create-a-pdf-3-snap.png new file mode 100644 index 0000000000000000000000000000000000000000..5713738f289e4a24fe8fcd6dedb1e4a58f877897 Binary files /dev/null and b/specs/splits/pre/__image_snapshots_linux__/pre-spec-js-pre-should-create-a-pdf-3-snap.png differ diff --git a/specs/splits/pre/__image_snapshots_linux__/pre-spec-js-pre-should-create-a-pdf-4-snap.png b/specs/splits/pre/__image_snapshots_linux__/pre-spec-js-pre-should-create-a-pdf-4-snap.png new file mode 100644 index 0000000000000000000000000000000000000000..9269b9cdf739cdd9d51272deeb7094f9e234e021 Binary files /dev/null and b/specs/splits/pre/__image_snapshots_linux__/pre-spec-js-pre-should-create-a-pdf-4-snap.png differ diff --git a/specs/splits/pre/pre.html b/specs/splits/pre/pre.html new file mode 100644 index 0000000000000000000000000000000000000000..69dacabccc35ef5ebf59dcb531095d77666bf3c0 --- /dev/null +++ b/specs/splits/pre/pre.html @@ -0,0 +1,52 @@ + + + + + Preformatted Text element + + + + +
+
+        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"
+	
+
+ + diff --git a/specs/splits/pre/pre.spec.js b/specs/splits/pre/pre.spec.js new file mode 100644 index 0000000000000000000000000000000000000000..371d33a409ccb860a413d71f3e516b72cf29f60c --- /dev/null +++ b/specs/splits/pre/pre.spec.js @@ -0,0 +1,31 @@ +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); + }); + } +}); diff --git a/src/utils/dom.js b/src/utils/dom.js index 672bb2c45656c0b33e810cec7a77c566fa53c4f9..f3a9d3ae67245fedf129a09d4262f350f67172de 100644 --- a/src/utils/dom.js +++ b/src/utils/dom.js @@ -301,10 +301,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); @@ -323,7 +324,6 @@ export function *words(node) { if (range) { range.setEnd(node, currentOffset); yield range; - range = undefined; } }