refactor: cleanup
This commit is contained in:
@ -4,17 +4,12 @@ import { useMemo } from "react";
|
||||
import ReactMarkdown from "react-markdown";
|
||||
|
||||
import { HyperText } from "element/hypertext";
|
||||
import {
|
||||
transformText,
|
||||
type Fragment,
|
||||
type NostrComponents,
|
||||
} from "element/text";
|
||||
import { transformText, type Fragment } from "element/text";
|
||||
import type { Tags } from "types";
|
||||
|
||||
interface MarkdownProps {
|
||||
content: string;
|
||||
tags?: Tags;
|
||||
customComponents?: NostrComponents;
|
||||
}
|
||||
|
||||
interface LinkProps {
|
||||
@ -26,36 +21,20 @@ interface ComponentProps {
|
||||
children?: Array<Fragment>;
|
||||
}
|
||||
|
||||
export function Markdown({
|
||||
content,
|
||||
tags = [],
|
||||
customComponents,
|
||||
}: MarkdownProps) {
|
||||
export function Markdown({ content, tags = [] }: MarkdownProps) {
|
||||
const components = useMemo(() => {
|
||||
return {
|
||||
li: ({ children, ...props }: ComponentProps) => {
|
||||
return (
|
||||
children && (
|
||||
<li {...props}>
|
||||
{transformText(children, tags, customComponents)}
|
||||
</li>
|
||||
)
|
||||
);
|
||||
return children && <li {...props}>{transformText(children, tags)}</li>;
|
||||
},
|
||||
td: ({ children }: ComponentProps) => {
|
||||
return (
|
||||
children && <td>{transformText(children, tags, customComponents)}</td>
|
||||
);
|
||||
return children && <td>{transformText(children, tags)}</td>;
|
||||
},
|
||||
th: ({ children }: ComponentProps) => {
|
||||
return (
|
||||
children && <th>{transformText(children, tags, customComponents)}</th>
|
||||
);
|
||||
return children && <th>{transformText(children, tags)}</th>;
|
||||
},
|
||||
p: ({ children }: ComponentProps) => {
|
||||
return (
|
||||
children && <p>{transformText(children, tags, customComponents)}</p>
|
||||
);
|
||||
return children && <p>{transformText(children, tags)}</p>;
|
||||
},
|
||||
a: ({ href, children }: LinkProps) => {
|
||||
return href && <HyperText link={href}>{children}</HyperText>;
|
||||
|
Reference in New Issue
Block a user