import React from 'react'; import Markdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import {Prism as SyntaxHighlighter} from 'react-syntax-highlighter'; import {darcula} from 'react-syntax-highlighter/dist/esm/styles/prism'; import {getSchemaTpl, tipedLabel} from 'amis-editor-core'; import 'amis'; import '../../src/index'; import PanelPreview from './PanelPreview'; export interface DocProps { children?: string | null | undefined; } export function mdComment(fun: Function) { const txt = fun.toString(); return txt; } function str2schema(code: string) { const fn = new Function('getSchemaTpl', 'tipedLabel', `return [${code}]`); return fn.call(null, getSchemaTpl, tipedLabel); } export default function Doc({children}: DocProps) { return (
{props.children};
},
code(props) {
const {children, className, node, ref, ...rest} = props;
const match = /language-(\w+)/.exec(className || '');
if (match?.[1] === 'schema') {
const schema = str2schema(children as string);
return (
{children}
);
}
}}
/>