|
9 | 9 | import type { Page } from "puppeteer";
|
10 | 10 | import type { DictMap } from "pdf-lib/src/core/objects/PDFDict";
|
11 | 11 | import type { PDFContext, PDFDocument, PDFRef } from "pdf-lib";
|
12 |
| -import { decode as htmlEntitiesDecode } from "html-entities"; |
| 12 | +import { decode } from "html-entities"; |
13 | 13 | import { PDFArray, PDFDict, PDFHexString, PDFName, PDFNumber } from "pdf-lib";
|
14 | 14 |
|
15 | 15 | export interface RootOutlineNode {
|
@@ -43,15 +43,6 @@ export interface OutlineRef {
|
43 | 43 | color?: number[]
|
44 | 44 | }
|
45 | 45 |
|
46 |
| -const SanitizeXMLRx = /<[^>]+>/g; |
47 |
| - |
48 |
| -function sanitize(str: string) { |
49 |
| - if (str.includes("<")) |
50 |
| - str = str.replace(SanitizeXMLRx, ""); |
51 |
| - |
52 |
| - return htmlEntitiesDecode(str); |
53 |
| -} |
54 |
| - |
55 | 46 | /**
|
56 | 47 | * Parses the outline of a webpage based on specified tags.
|
57 | 48 | * @param {Element[]} tagsToProcess - An array of HTML elements to process.
|
@@ -257,7 +248,7 @@ function buildPdfObjectsForOutline(outlinesWithRef: OutlineRef[], context: PDFCo
|
257 | 248 | const next = outlinesWithRef[i + 1];
|
258 | 249 |
|
259 | 250 | const pdfObject: DictMap = new Map([]);
|
260 |
| - pdfObject.set(PDFName.of("Title"), PDFHexString.fromText(sanitize(item.title))); |
| 251 | + pdfObject.set(PDFName.of("Title"), PDFHexString.fromText(decode(item.title))); |
261 | 252 | pdfObject.set(PDFName.of("Dest"), PDFName.of(item.destination));
|
262 | 253 | pdfObject.set(PDFName.of("Parent"), item.parentRef);
|
263 | 254 |
|
|
0 commit comments