Skip to content

Commit

Permalink
fix: markdown rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
immccn123 committed Oct 20, 2023
1 parent e5c73b0 commit 4c59240
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 29 deletions.
2 changes: 2 additions & 0 deletions packages/viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
"react-icons": "^4.11.0",
"react-infinite-scroll-component": "^6.1.0",
"react-markdown": "^9.0.0",
"rehype-highlight": "^7.0.0",
"rehype-katex": "^7.0.0",
"remark-gfm": "^4.0.0",
"remark-luogu-flavor": "^1.0.0",
"remark-math": "^6.0.0",
"socket.io-client": "^4.7.2",
"swr": "^2.2.2"
Expand Down
4 changes: 2 additions & 2 deletions packages/viewer/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function RootLayout({ children }: React.PropsWithChildren) {
)}
<NavBar />
<div className="container-lg" style={{ marginTop: "2rem" }}>
<div
{/* <div
className="col-lg-6 col-md-7 col-12 mt-5 mb-4 mx-auto alert alert-warning"
role="alert"
>
Expand All @@ -42,7 +42,7 @@ export default function RootLayout({ children }: React.PropsWithChildren) {
升级了讨论区
</a>
,暂未完成相关适配。
</div>
</div> */}
{children}
</div>
<Footer />
Expand Down
59 changes: 32 additions & 27 deletions packages/viewer/src/components/replies/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import "katex/dist/katex.min.css";
import "highlight.js/styles/tokyo-night-dark.css";
import gfm from "remark-gfm";
// import gfm from "remark-gfm";
import remarkLuoguFlavor from "remark-luogu-flavor";
import rehypeHighlight from "rehype-highlight";
import { useRef } from "react";

// import { computePosition, shift } from "@floating-ui/dom";
Expand All @@ -26,7 +28,7 @@ export default function Content({
// const userRefs = useRef<Record<number, HTMLDivElement | null>>({});

// useEffect(() => {
// contentRef.current?.querySelectorAll("a[data-uid]").forEach((element) => {
// contentRef.current?.querySelectorAll(".lfm-user-mention").forEach((element) => {
// const uid = parseInt(element.getAttribute("data-uid")!, 10);
// const tooltip = userRefs.current[uid]!;
// if (!tooltip) return;
Expand All @@ -48,29 +50,29 @@ export default function Content({
// tooltip.style.display = "none";
// }

// (
// [
// ["mouseenter", showTooltip],
// ["mouseleave", hideTooltip],
// ["focus", showTooltip],
// ["blur", hideTooltip],
// ...(userIdState
// ? [
// [
// "click",
// (event: Event) => {
// event.preventDefault();
// hideTooltip();
// if (userIdState[0] !== uid) userIdState[1](uid);
// else userIdState[1](null);
// },
// ],
// ]
// : []),
// ] as [string, () => void][]
// ).forEach(([event, listener]) =>
// element.addEventListener(event, listener),
// );
// // (
// // [
// // ["mouseenter", showTooltip],
// // ["mouseleave", hideTooltip],
// // ["focus", showTooltip],
// // ["blur", hideTooltip],
// // ...(userIdState
// // ? [
// // [
// // "click",
// // (event: Event) => {
// // event.preventDefault();
// // hideTooltip();
// // if (userIdState[0] !== uid) userIdState[1](uid);
// // else userIdState[1](null);
// // },
// // ],
// // ]
// // : []),
// // ] as [string, () => void][]
// // ).forEach(([event, listener]) =>
// // element.addEventListener(event, listener),
// // );
// });
// });

Expand All @@ -81,8 +83,11 @@ export default function Content({
ref={contentRef}
>
<Markdown
rehypePlugins={[rehypeKatex]}
remarkPlugins={[remarkMath, [gfm, { singleTilde: false }]]}
rehypePlugins={[rehypeKatex, rehypeHighlight]}
remarkPlugins={[
remarkMath,
[remarkLuoguFlavor, { userLinkPointToLuogu: false }],
]}
skipHtml
>
{content}
Expand Down
45 changes: 45 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4c59240

Please sign in to comment.