import { CopyOutlined, EditOutlined } from '@ant-design/icons'; import type { DisplayDataOutputModel } from '@difizen/libro-jupyter'; import { copy2clipboard } from '@difizen/libro-jupyter'; import { useInject, ViewInstance } from '@difizen/mana-app'; import { Collapse } from 'antd'; import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; import { LibroPromptCellView } from './prompt-cell-view.js'; export const CodeBlock = (props: any) => { const { className, children } = props; if (!props.inline && className) { const [, lang] = /language-(\w+)/.exec(className || '') || []; return (
        {lang && 
{lang}
} { copy2clipboard(children); }} className={`chat-msg-md-code-copy`} /> {typeof children === 'string' ? children.trim() : children}
); } return {children}; }; export const InterpreterCodeBlock = (props: any) => { const { className, children } = props; const instance = useInject(ViewInstance); const cell = instance.cell; if (!(cell instanceof LibroPromptCellView)) { return null; } const replace = (data: string) => { if (cell.editor) { const length = cell.editor.model.value.length; const start = cell.editor.getPositionAt(0); const end = cell.editor.getPositionAt(length); if (start && end) { cell.editor.replaceSelection(data, { start, end, }); } } }; if (!props.inline && className) { const [, lang] = /language-(\w+)/.exec(className || '') || []; return (
                    {
                      
{ cell.interpreterEditMode = true; if (cell.model.interpreterCode) { replace(cell.model.interpreterCode); } }} >
代码编辑
} {typeof children === 'string' ? children.trim() : children}

), }, ]} >
); } return {children}; };