-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender-function.tsx
More file actions
84 lines (81 loc) · 2.18 KB
/
Copy pathrender-function.tsx
File metadata and controls
84 lines (81 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import {
BoldText,
Divider,
LinkTextProps,
LinkText,
List,
ListProps,
Note,
Paragraph,
Title,
Title2,
Title3,
ExampleProps,
Example,
ListItem,
TableCell,
TableHeaderCell,
TableRow,
TableHead,
TableBody,
Table,
Summary,
Facts,
PageMeta,
Container,
Math,
Experiment,
Definition,
Grid,
} from "@/components/Common/DocContent";
import ModuleTopicsList from "@/components/Module/ModuleList";
import { JSX, PropsWithChildren } from "react";
import { InlineMath } from "react-katex";
export function parseQuestionText(katext: string) {
const parts = katext.split(/(\$[^$]*\$)/g); // Split on $...$
return parts.map((part, index) => {
if (part.startsWith("$") && part.endsWith("$")) {
return <InlineMath key={index} math={part.slice(1, -1)} />;
}
return <span key={index}>{part}</span>;
});
}
type MdxParser = PropsWithChildren & JSX.IntrinsicAttributes;
type MdxListParser = ListProps & JSX.IntrinsicAttributes;
type MdxLinkParser = LinkTextProps;
type MdxExampleParser = ExampleProps;
export const mdxParser = {
h1: (props: MdxParser) => <Title {...props} />,
h2: (props: MdxParser) => <Title2 {...props} />,
h3: (props: MdxParser) => <Title3 {...props} />,
p: (props: MdxParser) => <Paragraph {...props} />,
li: (props: MdxParser) => <ListItem {...props} />,
Bold: (props: MdxParser) => <BoldText {...props} />,
BoldText: (props: MdxParser) => <BoldText {...props} />,
a: (props: MdxLinkParser) => <LinkText {...props} />,
Note: (props: MdxParser) => <Note {...props} />,
blockquote: (props: MdxParser) => <Note {...props} />,
hr: (props: MdxParser) => <Divider {...props} />,
Line: (props: MdxParser) => <Divider {...props} />,
List: (props: MdxListParser) => <List {...props} />,
Example: (props: MdxExampleParser) => <Example {...props} />,
ListItem,
Paragraph,
Title2,
// Experiment,
Definition,
Grid,
Math,
Divider,
Table,
TableHead,
TableBody,
TableRow,
TableHeaderCell,
TableCell,
Summary,
Facts,
PageMeta,
ModuleTopicsList,
Container,
};