Skip to content

Commit fdea868

Browse files
fix: drop SanitizeXMLRx #5
1 parent 86921f1 commit fdea868

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

src/core/outline.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import type { Page } from "puppeteer";
1010
import type { DictMap } from "pdf-lib/src/core/objects/PDFDict";
1111
import type { PDFContext, PDFDocument, PDFRef } from "pdf-lib";
12-
import { decode as htmlEntitiesDecode } from "html-entities";
12+
import { decode } from "html-entities";
1313
import { PDFArray, PDFDict, PDFHexString, PDFName, PDFNumber } from "pdf-lib";
1414

1515
export interface RootOutlineNode {
@@ -43,15 +43,6 @@ export interface OutlineRef {
4343
color?: number[]
4444
}
4545

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-
5546
/**
5647
* Parses the outline of a webpage based on specified tags.
5748
* @param {Element[]} tagsToProcess - An array of HTML elements to process.
@@ -257,7 +248,7 @@ function buildPdfObjectsForOutline(outlinesWithRef: OutlineRef[], context: PDFCo
257248
const next = outlinesWithRef[i + 1];
258249

259250
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)));
261252
pdfObject.set(PDFName.of("Dest"), PDFName.of(item.destination));
262253
pdfObject.set(PDFName.of("Parent"), item.parentRef);
263254

0 commit comments

Comments
 (0)