Skip to content

Commit

Permalink
feat(ai-native): add katex plugin for md render
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshinesmilelk authored and BroKun committed Dec 18, 2024
1 parent a4ab6ca commit 09341a1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/libro-ai-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,21 @@
"typecheck:tsc": "tsc --noEmit"
},
"dependencies": {
"@difizen/libro-jupyter": "^0.3.2",
"@difizen/libro-code-editor": "^0.3.2",
"@ant-design/icons": "^5.4.0",
"@difizen/mana-app": "latest",
"@difizen/mana-l10n": "latest",
"@difizen/magent-libro": "^0.1.27",
"@difizen/libro-code-editor": "^0.3.2",
"@difizen/libro-jupyter": "^0.3.2",
"@difizen/magent-chat": "^0.1.27",
"@difizen/magent-core": "^0.1.27",
"@difizen/magent-libro": "^0.1.27",
"@difizen/mana-app": "latest",
"@difizen/mana-l10n": "latest",
"copy-to-clipboard": "^3.3.3",
"eventsource-parser": "^1.1.2",
"react-syntax-highlighter": "^15.5.0",
"katex": "^0.16.10",
"markdown-it": "^13.0.1",
"react-syntax-highlighter": "^15.5.0",
"rehype-katex": "^7.0.1",
"rehype-raw": "^7.0.0",
"remark-breaks": "^4.0.0",
"remark-gfm": "^4.0.0",
"uuid": "^9.0.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/libro-ai-native/src/ai-native-for-cell-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ import { l10n } from '@difizen/mana-l10n';
import { Button } from 'antd';
import type { ParsedEvent } from 'eventsource-parser/stream';
import { EventSourceParserStream } from 'eventsource-parser/stream';
import rehypeKatex from 'rehype-katex';
import rehypeRaw from 'rehype-raw';
import breaks from 'remark-breaks';
import remarkGfm from 'remark-gfm';
import 'katex/dist/katex.min.css'; // 引入 KaTeX 样式

import { CodeBlockInCell } from './ai-native-code-block.js';
import { LibroAINativeService } from './ai-native-service.js';
Expand Down Expand Up @@ -49,6 +52,7 @@ export function LibroAINativeForCellRender() {
type="message"
components={{ code: CodeBlockInCell }}
remarkPlugins={[remarkGfm, breaks]}
rehypePlugins={[rehypeKatex, rehypeRaw]}
>
{msgItem?.content || ''}
</LLMRender>
Expand Down
1 change: 1 addition & 0 deletions packages/libro-ai-native/src/chat-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ViewRender,
} from '@difizen/mana-app';
import { useRef } from 'react';
import 'katex/dist/katex.min.css'; // 引入 KaTeX 样式

import { LibroAINativeService } from './ai-native-service.js';
import { LibroAiNativeChatView } from './libro-ai-native-chat-view.js';
Expand Down
3 changes: 3 additions & 0 deletions packages/libro-ai-native/src/libro-ai-native-chat-view.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { CellView, LibroView } from '@difizen/libro-jupyter';
import { ChatView, ChatComponents } from '@difizen/magent-chat';
import { inject, prop, transient, view, ViewOption } from '@difizen/mana-app';
import rehypeKatex from 'rehype-katex';
import rehypeRaw from 'rehype-raw';
import breaks from 'remark-breaks';
import remarkGfm from 'remark-gfm';

Expand Down Expand Up @@ -32,6 +34,7 @@ export class LibroAiNativeChatView extends ChatView {
return {
components: { code: CodeBlockInChat, img: ImageModal },
remarkPlugins: [remarkGfm, breaks],
rehypePlugins: [rehypeRaw, rehypeKatex] as any[],
};
}

Expand Down

0 comments on commit 09341a1

Please sign in to comment.