Skip to content

Commit c45fa0c

Browse files
committed
Decode numeric HTML entities in CLI text output
1 parent 4398e43 commit c45fa0c

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

cli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ function htmlToText(html: string): string {
1010
.replace(/<\/div>/gi, "\n")
1111
.replace(/<\/li>/gi, "\n")
1212
.replace(/<[^>]+>/g, "")
13+
.replace(/&#(\d+);/g, (_m, code) => String.fromCodePoint(Number(code)))
14+
.replace(/&#x([0-9a-fA-F]+);/g, (_m, code) => String.fromCodePoint(parseInt(code, 16)))
1315
.replace(/&amp;/g, "&")
1416
.replace(/&lt;/g, "<")
1517
.replace(/&gt;/g, ">")
1618
.replace(/&quot;/g, '"')
17-
.replace(/&#39;/g, "'")
1819
.replace(/&nbsp;/g, " ")
1920
.replace(/\n{3,}/g, "\n\n")
2021
.trim();

0 commit comments

Comments
 (0)