Skip to content

Commit

Permalink
website: fix markdown type error.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Nov 26, 2023
1 parent 12448d8 commit 33e1b98
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
34 changes: 12 additions & 22 deletions www/src/components/Markdown.tsx
@@ -1,46 +1,36 @@
import { FC, PropsWithChildren, useRef } from 'react';
import CodeLayout from 'react-code-preview-layout';
import { getMetaId, isMeta, getURLParameters, CodeBlockData } from 'markdown-react-code-preview-loader';
import { getMetaId, getURLParameters, CodeBlockData } from 'markdown-react-code-preview-loader';
import MarkdownPreview, { MarkdownPreviewProps } from '@uiw/react-markdown-preview';
import rehypeIgnore from 'rehype-ignore';
import { CodeProps } from 'react-markdown/lib/ast-to-react';
import { type Node } from 'unist';
import styled from 'styled-components';

const Preview = CodeLayout.Preview;
const Code = CodeLayout.Code;
const Toolbar = CodeLayout.Toolbar;

interface CodePreviewProps extends CodeProps {
mdData?: CodeBlockData;
}

const CodeLayoutView = styled(CodeLayout)`
& + div.copied {
display: none !important;
}
`;

const CodePreview: FC<PropsWithChildren<CodePreviewProps>> = ({ inline, node, ...props }) => {
interface CodePreviewProps {
mdData?: CodeBlockData;
'data-meta'?: string;
node?: Node;
}

const CodePreview: FC<PropsWithChildren<CodePreviewProps>> = (props) => {
const $dom = useRef<HTMLDivElement>(null);
const { mdData, ...rest } = props;
// useEffect(() => {
// if ($dom.current) {
// const parentElement = $dom.current.parentElement;
// if (parentElement && parentElement.parentElement) {
// parentElement.parentElement.replaceChild($dom.current, parentElement);
// }
// }
// }, [$dom]);
const { 'data-meta': meta } = props as any;
if (inline || !isMeta(meta)) {
return <code {...rest} />;
}
const line = node.position?.start.line;
const { mdData, node, 'data-meta': meta, ...rest } = props;
const line = node?.position?.start.line;
const metaId = getMetaId(meta) || String(line);
const Child = mdData?.components[`${metaId}`];
if (metaId && typeof Child === 'function') {
const code = mdData?.data[metaId].value || '';
const param = getURLParameters(meta);
const param = getURLParameters(meta || '');
return (
<CodeLayoutView ref={$dom}>
<Preview>
Expand Down
1 change: 0 additions & 1 deletion www/src/pages/theme/Preview.tsx
Expand Up @@ -70,7 +70,6 @@ export const Preview: FC<PropsWithChildren<PreviewProps>> = (props) => {
const themeExtensionName = themePkgNmae?.replace('@uiw/codemirror-theme-', '') + (!!mode ? `-${mode}` : '');
const extension = themeData[toCamelCase(themeExtensionName) as keyof typeof themeData];
const repoName = themePkgNmae?.replace(/@uiw\//, '');
console.log('mdData:', mdData);
return (
<Warpper>
<Content>
Expand Down

0 comments on commit 33e1b98

Please sign in to comment.