Skip to content

Commit 84b66fe

Browse files
committed
fix: Fix string html escape error (#101).
1 parent 928c8ea commit 84b66fe

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/utils.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,17 @@ export const processHtml = (html: string) => {
1818
// }
1919

2020
export function htmlEncode(sHtml: string) {
21-
return sHtml.replace(
22-
/[<>&"]/g,
23-
(c: string) => (({ '<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;' } as Record<string, string>)[c]),
24-
);
21+
return sHtml
22+
.replace(/```(tsx?|jsx?|html|xml)(.*)\s+([\s\S]*?)(\s.+)?```/g, (str: string) => {
23+
return str.replace(
24+
/[<&"]/g,
25+
(c: string) => (({ '<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;' } as Record<string, string>)[c]),
26+
);
27+
})
28+
.replace(
29+
/[<&"]/g,
30+
(c: string) => (({ '<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;' } as Record<string, string>)[c]),
31+
);
2532
}
2633

2734
export function stopPropagation(e: React.KeyboardEvent<HTMLTextAreaElement>) {

0 commit comments

Comments
 (0)