Update markdown.tsx

This commit is contained in:
yorkeking 2023-04-04 01:48:19 +08:00 committed by GitHub
parent bb8972e986
commit 42767b055d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,8 +4,8 @@ import RemarkMath from "remark-math";
import RemarkBreaks from "remark-breaks"; import RemarkBreaks from "remark-breaks";
import RehypeKatex from "rehype-katex"; import RehypeKatex from "rehype-katex";
import RemarkGfm from "remark-gfm"; import RemarkGfm from "remark-gfm";
import RehypePrsim from "rehype-prism-plus"; import RehypeHighlight from "rehype-highlight";
import { useRef } from "react"; import { useRef, useState, RefObject, useEffect } from "react";
import { copyToClipboard } from "../utils"; import { copyToClipboard } from "../utils";
export function PreCode(props: { children: any }) { export function PreCode(props: { children: any }) {
@ -27,11 +27,43 @@ export function PreCode(props: { children: any }) {
); );
} }
const useLazyLoad = (ref: RefObject<Element>): boolean => {
const [isIntersecting, setIntersecting] = useState<boolean>(false);
useEffect(() => {
const observer = new IntersectionObserver(([entry]) => {
if (entry.isIntersecting) {
setIntersecting(true);
observer.disconnect();
}
});
if (ref.current) {
observer.observe(ref.current);
}
return () => {
observer.disconnect();
};
}, [ref]);
return isIntersecting;
};
export function Markdown(props: { content: string }) { export function Markdown(props: { content: string }) {
return ( return (
<ReactMarkdown <ReactMarkdown
remarkPlugins={[RemarkMath, RemarkGfm, RemarkBreaks]} remarkPlugins={[RemarkMath, RemarkGfm, RemarkBreaks]}
rehypePlugins={[RehypeKatex, [RehypePrsim, { ignoreMissing: true }]]} rehypePlugins={[
RehypeKatex,
[
RehypeHighlight,
{
detect: false,
ignoreMissing: true,
},
],
]}
components={{ components={{
pre: PreCode, pre: PreCode,
}} }}