From 8821ee582a96bc012d2f3ae277b0d39d6cccdebb Mon Sep 17 00:00:00 2001 From: Jake Coble Date: Fri, 26 Jul 2024 15:11:17 -0400 Subject: [PATCH 1/2] Don't escape progress tags --- src/lib/parseMarkdown.options.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/parseMarkdown.options.ts b/src/lib/parseMarkdown.options.ts index 84ad685..84785e8 100644 --- a/src/lib/parseMarkdown.options.ts +++ b/src/lib/parseMarkdown.options.ts @@ -91,6 +91,7 @@ export const SANITIZE_HTML_OPTIONS: IOptions = { mtr: ["rowalign"], munder: ["accentunder"], munderover: ["accent", "accentunder"], + progress: ["value"], }, disallowedTagsMode: "escape", parser: { @@ -175,6 +176,7 @@ export const SANITIZE_HTML_OPTIONS: IOptions = { "iframe", "kbd", "mark", + "progress", "q", "rb", "rp", From 7ea5a84e9b14bb5395bbf06a7885bab1bd7920dd Mon Sep 17 00:00:00 2001 From: Jake Coble Date: Fri, 26 Jul 2024 17:15:30 -0400 Subject: [PATCH 2/2] Fix smartypants correctly --- src/lib/parseMarkdown.spec.ts | 11 +++++++++++ src/lib/parseMarkdown.ts | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/lib/parseMarkdown.spec.ts b/src/lib/parseMarkdown.spec.ts index 18c59f4..c5ff985 100644 --- a/src/lib/parseMarkdown.spec.ts +++ b/src/lib/parseMarkdown.spec.ts @@ -176,4 +176,15 @@ describe("body", () => { ].join("\n"), ); }); + + it("uses correct quotation marks", () => { + expect( + parseMarkdown( + 'For a lot of engineering problems, "almost right" isn\'t good enough.', + { strict: false }, + ), + ).toBe( + "

For a lot of engineering problems, “almost right” isn’t good enough.

\n", + ); + }); }); diff --git a/src/lib/parseMarkdown.ts b/src/lib/parseMarkdown.ts index fd7707e..74ee54b 100644 --- a/src/lib/parseMarkdown.ts +++ b/src/lib/parseMarkdown.ts @@ -38,6 +38,19 @@ const tokenizer = { marked.use({ tokenizer }); marked.use({ + tokenizer: { + inlineText(src) { + // don't escape inlineText, unless it's < and > + const cap = this.rules.inline.text.exec(src); + const text = cap[0].replace("<", "<").replace(">", ">"); + + return { + type: "text", + raw: text, + text: text, + }; + }, + }, hooks: { postprocess(html) { return smartypants(html, "1");