mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-24 23:19:39 -05:00
22 lines
784 B
TypeScript
22 lines
784 B
TypeScript
import MarkdownToJsx from "markdown-to-jsx";
|
|
import * as React from "react";
|
|
|
|
// note: markdown-to-jsx also handles these, this is just to prevent them from appearing as plain text
|
|
const DANGEROUS_HTML_TAGS_REGEX =
|
|
/<(style|iframe|script|title|textarea|xmp|noembed|noframes|plaintext)[\s\S]*?<\/\1>|<(style|iframe|script|title|textarea|xmp|noembed|noframes|plaintext)[^>]*\/>/gi;
|
|
|
|
// note: this is not handled by markdown-to-jsx currently
|
|
const INLINE_STYLE_REGEX = /\s*style\s*=\s*(?:"[^"]*"|'[^']*')/gi;
|
|
|
|
export function Markdown({ children }: { children: string }) {
|
|
const sanitized = children
|
|
.replace(DANGEROUS_HTML_TAGS_REGEX, "")
|
|
.replace(INLINE_STYLE_REGEX, "");
|
|
|
|
return (
|
|
<MarkdownToJsx options={{ wrapper: React.Fragment }}>
|
|
{sanitized}
|
|
</MarkdownToJsx>
|
|
);
|
|
}
|