Skip to content

Commit 33e1b98

Browse files
committedNov 26, 2023
website: fix markdown type error.
1 parent 12448d8 commit 33e1b98

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed
 

‎www/src/components/Markdown.tsx

+12-22
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,36 @@
11
import { FC, PropsWithChildren, useRef } from 'react';
22
import CodeLayout from 'react-code-preview-layout';
3-
import { getMetaId, isMeta, getURLParameters, CodeBlockData } from 'markdown-react-code-preview-loader';
3+
import { getMetaId, getURLParameters, CodeBlockData } from 'markdown-react-code-preview-loader';
44
import MarkdownPreview, { MarkdownPreviewProps } from '@uiw/react-markdown-preview';
55
import rehypeIgnore from 'rehype-ignore';
6-
import { CodeProps } from 'react-markdown/lib/ast-to-react';
6+
import { type Node } from 'unist';
77
import styled from 'styled-components';
88

99
const Preview = CodeLayout.Preview;
1010
const Code = CodeLayout.Code;
1111
const Toolbar = CodeLayout.Toolbar;
1212

13-
interface CodePreviewProps extends CodeProps {
14-
mdData?: CodeBlockData;
15-
}
16-
1713
const CodeLayoutView = styled(CodeLayout)`
1814
& + div.copied {
1915
display: none !important;
2016
}
2117
`;
2218

23-
const CodePreview: FC<PropsWithChildren<CodePreviewProps>> = ({ inline, node, ...props }) => {
19+
interface CodePreviewProps {
20+
mdData?: CodeBlockData;
21+
'data-meta'?: string;
22+
node?: Node;
23+
}
24+
25+
const CodePreview: FC<PropsWithChildren<CodePreviewProps>> = (props) => {
2426
const $dom = useRef<HTMLDivElement>(null);
25-
const { mdData, ...rest } = props;
26-
// useEffect(() => {
27-
// if ($dom.current) {
28-
// const parentElement = $dom.current.parentElement;
29-
// if (parentElement && parentElement.parentElement) {
30-
// parentElement.parentElement.replaceChild($dom.current, parentElement);
31-
// }
32-
// }
33-
// }, [$dom]);
34-
const { 'data-meta': meta } = props as any;
35-
if (inline || !isMeta(meta)) {
36-
return <code {...rest} />;
37-
}
38-
const line = node.position?.start.line;
27+
const { mdData, node, 'data-meta': meta, ...rest } = props;
28+
const line = node?.position?.start.line;
3929
const metaId = getMetaId(meta) || String(line);
4030
const Child = mdData?.components[`${metaId}`];
4131
if (metaId && typeof Child === 'function') {
4232
const code = mdData?.data[metaId].value || '';
43-
const param = getURLParameters(meta);
33+
const param = getURLParameters(meta || '');
4434
return (
4535
<CodeLayoutView ref={$dom}>
4636
<Preview>

‎www/src/pages/theme/Preview.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export const Preview: FC<PropsWithChildren<PreviewProps>> = (props) => {
7070
const themeExtensionName = themePkgNmae?.replace('@uiw/codemirror-theme-', '') + (!!mode ? `-${mode}` : '');
7171
const extension = themeData[toCamelCase(themeExtensionName) as keyof typeof themeData];
7272
const repoName = themePkgNmae?.replace(/@uiw\//, '');
73-
console.log('mdData:', mdData);
7473
return (
7574
<Warpper>
7675
<Content>

0 commit comments

Comments
 (0)
Please sign in to comment.