diff --git a/src/MarkdownView.tsx b/src/MarkdownView.tsx index 2e45c13..0e08f86 100644 --- a/src/MarkdownView.tsx +++ b/src/MarkdownView.tsx @@ -126,7 +126,11 @@ export default function MarkdownView(props: MarkdownViewProps): ReactElement { converter.addExtension(extensions); } - let html = converter.makeHtml(markdown ?? markup); + // Always sanitize basic tags before returning element + let text = markdown ?? markup; + text = initial_sanitization(text); + + let html = converter.makeHtml(text); if (sanitizeHtml) { html = sanitizeHtml(html); } @@ -175,3 +179,16 @@ function filterWhitespaceElements(node: Node) { return true; } } + +function initial_sanitization(string: String) { + let map = new Map([ + ['&', '&'], + ['<', '<'], + ['>', '>'], + ['"', '"'], + ["'", '''], + ['/', '/'], + ]); + const reg = /[&<>"'/]/gi; + return string.replace(reg, match => map.get(match)!); +}