Some checks failed
Branch Build CE / Build Setup (push) Has been cancelled
Branch Build CE / Build-Push Admin Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Web Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Space Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Live Collaboration Docker Image (push) Has been cancelled
Branch Build CE / Build-Push API Server Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Proxy Docker Image (push) Has been cancelled
Branch Build CE / Build-Push AIO Docker Image (push) Has been cancelled
Branch Build CE / Upload Build Assets (push) Has been cancelled
Branch Build CE / Build Release (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Codespell / Check for spelling errors (push) Has been cancelled
Sync Repositories / sync_changes (push) Has been cancelled
Synced from upstream: 8853637e981ed7d8a6cff32bd98e7afe20f54362
76 lines
2.0 KiB
TypeScript
76 lines
2.0 KiB
TypeScript
import React from "react";
|
|
import ReactMarkdown from "react-markdown";
|
|
|
|
interface CustomComponentProps {
|
|
href: string;
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
type CustomComponent = React.ComponentType<CustomComponentProps>;
|
|
|
|
interface Props {
|
|
markdown: string;
|
|
components?: {
|
|
a?: CustomComponent;
|
|
blockquote?: CustomComponent;
|
|
code?: CustomComponent;
|
|
del?: CustomComponent;
|
|
em?: CustomComponent;
|
|
heading?: CustomComponent;
|
|
hr?: CustomComponent;
|
|
image?: CustomComponent;
|
|
inlineCode?: CustomComponent;
|
|
link?: CustomComponent;
|
|
list?: CustomComponent;
|
|
listItem?: CustomComponent;
|
|
paragraph?: CustomComponent;
|
|
strong?: CustomComponent;
|
|
table?: CustomComponent;
|
|
tableCell?: CustomComponent;
|
|
tableHead?: CustomComponent;
|
|
tableRow?: CustomComponent;
|
|
};
|
|
options?: any;
|
|
}
|
|
|
|
const HeadingPrimary: CustomComponent = ({ children }) => (
|
|
<h1 className="text-lg font-semibold text-custom-text-100">{children}</h1>
|
|
);
|
|
|
|
const HeadingSecondary: CustomComponent = ({ children }) => (
|
|
<h3 className="text-base font-semibold text-custom-text-100">{children}</h3>
|
|
);
|
|
|
|
const Paragraph: CustomComponent = ({ children }) => <p className="text-sm text-custom-text-200">{children}</p>;
|
|
|
|
const OrderedList: CustomComponent = ({ children }) => (
|
|
<ol className="mb-4 ml-8 list-decimal text-sm text-custom-text-200">{children}</ol>
|
|
);
|
|
|
|
const UnorderedList: CustomComponent = ({ children }) => (
|
|
<ul className="mb-4 ml-8 list-disc text-sm text-custom-text-200">{children}</ul>
|
|
);
|
|
|
|
const Link: CustomComponent = ({ href, children }) => (
|
|
<a href={href} className="underline hover:no-underline" target="_blank" rel="noopener noreferrer">
|
|
{children}
|
|
</a>
|
|
);
|
|
|
|
export const MarkdownRenderer: React.FC<Props> = ({ markdown, options = {} }) => {
|
|
const customComponents = {
|
|
h1: HeadingPrimary,
|
|
h3: HeadingSecondary,
|
|
p: Paragraph,
|
|
ol: OrderedList,
|
|
ul: UnorderedList,
|
|
a: Link,
|
|
};
|
|
|
|
return (
|
|
<ReactMarkdown components={customComponents} {...options}>
|
|
{markdown}
|
|
</ReactMarkdown>
|
|
);
|
|
};
|