diff options
Diffstat (limited to 'packages/markdown/remark/src')
-rw-r--r-- | packages/markdown/remark/src/rehype-escape.ts | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/packages/markdown/remark/src/rehype-escape.ts b/packages/markdown/remark/src/rehype-escape.ts index e776c1bb1..e99e37e41 100644 --- a/packages/markdown/remark/src/rehype-escape.ts +++ b/packages/markdown/remark/src/rehype-escape.ts @@ -1,5 +1,9 @@ import { visit } from 'unist-util-visit'; +export function escapeEntities(value: string): string { + return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); +} + export default function rehypeEscape(): any { return function (node: any): any { return visit(node, 'element', (el) => { @@ -8,7 +12,7 @@ export default function rehypeEscape(): any { // Visit all raw children and escape HTML tags to prevent Markdown code // like "This is a `<script>` tag" from actually opening a script tag visit(el, 'raw', (raw) => { - raw.value = raw.value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); + raw.value = escapeEntities(raw.value); }); } return el; |