Skip to content

Commit

Permalink
website: update markdown preview.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed May 19, 2023
1 parent 0158c5b commit ec88a44
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
6 changes: 1 addition & 5 deletions merge/src/Internal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ export const Internal = React.forwardRef((props: CodeMirrorMergeProps, ref?: Rea
}
}, [editor.current, original, modified, view]);

useEffect(() => {
return () => {
view && view.destroy();
};
}, []);
useEffect(() => () => view && view.destroy(), []);

useEffect(() => {
if (view) {
Expand Down
17 changes: 12 additions & 5 deletions www/src/components/Markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { FC, PropsWithChildren, useEffect, useRef } from 'react';
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 MarkdownPreview, { MarkdownPreviewProps } from '@uiw/react-markdown-preview';
import rehypeIgnore from 'rehype-ignore';
import { CodeProps } from 'react-markdown/lib/ast-to-react';
import styled from 'styled-components';

const Preview = CodeLayout.Preview;
const Code = CodeLayout.Code;
Expand All @@ -13,6 +14,12 @@ interface CodePreviewProps extends CodeProps {
mdData?: CodeBlockData;
}

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

const CodePreview: FC<PropsWithChildren<CodePreviewProps>> = ({ inline, node, ...props }) => {
const $dom = useRef<HTMLDivElement>(null);
const { mdData, ...rest } = props;
Expand All @@ -35,15 +42,15 @@ const CodePreview: FC<PropsWithChildren<CodePreviewProps>> = ({ inline, node, ..
const code = mdData?.data[metaId].value || '';
const param = getURLParameters(meta);
return (
<CodeLayout ref={$dom}>
<CodeLayoutView ref={$dom}>
<Preview>
<Child />
</Preview>
<Toolbar>{param.title || 'Example'}</Toolbar>
<Toolbar text={code}>{param.title || 'Example'}</Toolbar>
<Code>
<pre {...rest} />
</Code>
</CodeLayout>
</CodeLayoutView>
);
}
return <code {...rest} />;
Expand All @@ -59,7 +66,7 @@ export default function Markdown(props: MarkdownProps) {
<MarkdownPreview
{...rest}
style={{ paddingTop: 30 }}
disableCopy={true}
// disableCopy={true}
rehypePlugins={[rehypeIgnore]}
source={props.source || ''}
components={{
Expand Down
1 change: 0 additions & 1 deletion www/src/pages/theme/Preview.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { FC, Children, PropsWithChildren, cloneElement, useState } from 'react';
import styled from 'styled-components';
import MarkdownPreview from '@uiw/react-markdown-preview';
import { useMdData } from '../../components/useMdData';
import { Warpper } from '../../components/Warpper';
import { PreCode } from './themes/PreCode';
Expand Down

0 comments on commit ec88a44

Please sign in to comment.