Skip to content

Commit

Permalink
🐛 fix: fix latex in thinking tag render (lobehub#6063)
Browse files Browse the repository at this point in the history
* fix latex-in-thinking

* fix latex-in-thinking

* fix latex-in-thinking
  • Loading branch information
arvinxx authored Feb 13, 2025
1 parent d421e93 commit 7e89b2d
Show file tree
Hide file tree
Showing 5 changed files with 458 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/features/Conversation/components/ChatItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ const Item = memo<ChatListItemProps>(
() => ({
components,
customRender: markdownCustomRender,
rehypePlugins,
remarkPlugins,
rehypePlugins: item?.role === 'user' ? undefined : rehypePlugins,
remarkPlugins: item?.role === 'user' ? undefined : remarkPlugins,
}),
[components, markdownCustomRender],
[components, markdownCustomRender, item?.role],
);

const onChange = useCallback((value: string) => updateMessageContent(id, value), [id]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createRemarkCustomTagPlugin } from '../remarkPlugins/createRemarkCustomTagPlugin';
import { MarkdownElement } from '../type';
import Component from './Render';
import { createRemarkCustomTagPlugin } from './remarkPlugin';

const ThinkingElement: MarkdownElement = {
Component,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { toMarkdown } from 'mdast-util-to-markdown';
import { SKIP, visit } from 'unist-util-visit';

import { treeNodeToString } from './getNodeContent';

export const createRemarkCustomTagPlugin = (tag: string) => () => {
return (tree: any) => {
visit(tree, 'html', (node, index, parent) => {
Expand Down Expand Up @@ -31,17 +32,7 @@ export const createRemarkCustomTagPlugin = (tag: string) => () => {
);

// 转换为 Markdown 字符串
const content = contentNodes
.map((n: any) => {
// fix https://github.com/lobehub/lobe-chat/issues/5668
if (n.type === 'paragraph') {
return n.children.map((child: any) => child.value).join('');
}

return toMarkdown(n);
})
.join('\n\n')
.trim();
const content = treeNodeToString(contentNodes);

// 创建自定义节点
const customNode = {
Expand Down
Loading

0 comments on commit 7e89b2d

Please # to comment.