Skip to content

Commit b4330d8

Browse files
committedOct 24, 2024
fix double code escape
1 parent c75a19f commit b4330d8

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed
 

‎src/inline-plugins/code.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import type { InlinePlugin } from "../types.ts";
2-
import { escape } from "@dbushell/hyperless";
2+
import { escape, unescape } from "@dbushell/hyperless";
33

44
const REGEXP = /`([^`]+)`/g;
55

66
const plugin: InlinePlugin = {
77
type: "code",
88
prerender: (text: string) => {
9-
if (text.includes("`") === false) return text;
9+
if (text.indexOf("`") === -1) return text;
1010
// Inline code is escaped early to avoid `<div>` being parsed as HTML node
11-
return text.replace(REGEXP, (...match) => escape(match[0]));
11+
return text.replace(REGEXP, (...match) => {
12+
const text = unescape(match[0]);
13+
return escape(text);
14+
});
1215
},
1316
render: (text: string) => {
1417
text = text.replace(REGEXP, (...match) => `<code>${match[1]}</code>`);

‎test/code_test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ Deno.test("code (anchor inception)", async () => {
2525
"<p><code>This [emoji] 🍋‍🟩 is a [lime](https://emojipedia.org/lime) ok?</code></p>",
2626
);
2727
});
28+
29+
Deno.test("code (html)", async () => {
30+
const html = await hmmarkdown("<div>`</div>`</div>");
31+
assertEquals(html, "<div><p><code>&lt;/div&gt;</code></p></div>");
32+
});

0 commit comments

Comments
 (0)
Please sign in to comment.