some changes
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-02-10 17:06:51 +01:00
parent f884ac1d1d
commit f7c6d3ae16
8 changed files with 756 additions and 45 deletions

View File

@@ -14,10 +14,11 @@ import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
import remarkTypograf from "@mavrin/remark-typograf";
import smartypants from "remark-smartypants";
import oembed from "@agentofuser/remark-oembed";
import rehypeRaw from "rehype-raw";
import emoji from "remark-emoji";
import rehypeSanitize from "rehype-sanitize";
import oembed from "@agentofuser/remark-oembed";
import YouTube from "react-youtube";
//import rehypeSanitize from "rehype-sanitize";
SyntaxHighlighter.registerLanguage("tsx", tsx);
SyntaxHighlighter.registerLanguage("typescript", typescript);
@@ -26,8 +27,26 @@ SyntaxHighlighter.registerLanguage("bash", bash);
SyntaxHighlighter.registerLanguage("markdown", markdown);
SyntaxHighlighter.registerLanguage("json", json);
export const StyledMarkdown = ({ html }: { html: string }) => {
const MarkdownComponents: Components = {
a: (props : any) => {
try {
const url = new URL(props.href);
if (
url.origin.includes("youtube.com") &&
props.node.position.start.column === 1
){
return <YouTube videoId={url.searchParams.get("v") || "dQw4w9WgXcQ"} />;
}
} catch (e) {
//console.log(e);
}
return <a {...props} />;
},
h1: (props: any) => {
const arr = props.children;
let heading = "";
@@ -195,7 +214,7 @@ export const StyledMarkdown = ({ html }: { html: string }) => {
<ReactMarkdown
components={MarkdownComponents}
rehypePlugins={[rehypeRaw]}
remarkPlugins={[remarkGfm, remarkTypograf, smartypants, oembed, emoji]}
remarkPlugins={[oembed, remarkGfm, remarkTypograf, smartypants, emoji]}
children={html}
/>
</div>