feat: style change

This commit is contained in:
Hk-Gosuto
2023-12-04 21:33:27 +08:00
parent 796abf83ce
commit 4c46de7d1d
5 changed files with 452 additions and 319 deletions

View File

@@ -116,38 +116,41 @@ function escapeDollarNumber(text: string) {
return escapedText;
}
function _MarkDownContent(props: { content: string }) {
function _MarkDownContent(props: { content: string; imageBase64?: string }) {
const escapedContent = useMemo(
() => escapeDollarNumber(props.content),
[props.content],
);
return (
<ReactMarkdown
remarkPlugins={[RemarkMath, RemarkGfm, RemarkBreaks]}
rehypePlugins={[
RehypeKatex,
[
RehypeHighlight,
{
detect: false,
ignoreMissing: true,
<div>
{props.imageBase64 && <img src={props.imageBase64} alt="" />}
<ReactMarkdown
remarkPlugins={[RemarkMath, RemarkGfm, RemarkBreaks]}
rehypePlugins={[
RehypeKatex,
[
RehypeHighlight,
{
detect: false,
ignoreMissing: true,
},
],
]}
components={{
pre: PreCode,
p: (pProps) => <p {...pProps} dir="auto" />,
a: (aProps) => {
const href = aProps.href || "";
const isInternal = /^\/#/i.test(href);
const target = isInternal ? "_self" : aProps.target ?? "_blank";
return <a {...aProps} target={target} />;
},
],
]}
components={{
pre: PreCode,
p: (pProps) => <p {...pProps} dir="auto" />,
a: (aProps) => {
const href = aProps.href || "";
const isInternal = /^\/#/i.test(href);
const target = isInternal ? "_self" : aProps.target ?? "_blank";
return <a {...aProps} target={target} />;
},
}}
>
{escapedContent}
</ReactMarkdown>
}}
>
{escapedContent}
</ReactMarkdown>
</div>
);
}
@@ -160,6 +163,7 @@ export function Markdown(
fontSize?: number;
parentRef?: RefObject<HTMLDivElement>;
defaultShow?: boolean;
imageBase64?: string;
} & React.DOMAttributes<HTMLDivElement>,
) {
const mdRef = useRef<HTMLDivElement>(null);
@@ -178,7 +182,10 @@ export function Markdown(
{props.loading ? (
<LoadingIcon />
) : (
<MarkdownContent content={props.content} />
<MarkdownContent
content={props.content}
imageBase64={props.imageBase64}
/>
)}
</div>
);