import { LightAsync as SyntaxHighlighter } from 'react-syntax-highlighter'; import light from 'react-syntax-highlighter/dist/cjs/styles/hljs/xcode'; import dark from 'react-syntax-highlighter/dist/cjs/styles/hljs/vs2015'; import type { GenericNode } from 'mystjs'; import { useTheme } from '../theme'; import { NodeTypes } from 'myst-util-to-react'; type Props = { children: string; lang?: string; showLineNumbers?: boolean; emphasizeLines?: number[]; }; export function CodeBlock(props: Props) { const { isLight } = useTheme(); const { children, lang, emphasizeLines, showLineNumbers } = props; const highlightLines = new Set(emphasizeLines); return ( { if (typeof line === 'boolean') return {}; return highlightLines.has(line) ? ({ 'data-line-number': `${line}`, 'data-highlight': 'true', } as any) : ({ 'data-line-number': `${line}` } as any); }} customStyle={{ padding: '0.8rem' }} > {children} ); } export const codeRenderers: NodeTypes = { code(node: GenericNode) { return (
{node.value || ''}
); }, };