mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-08 18:44:22 +01:00
refactor: optimize Markdown rendering and add support for code artifacts
This commit is contained in:
parent
f1fb8e991c
commit
f2a516db02
1 changed files with 14 additions and 10 deletions
|
|
@ -8,6 +8,7 @@ import ReactMarkdown from 'react-markdown';
|
||||||
import rehypeHighlight from 'rehype-highlight';
|
import rehypeHighlight from 'rehype-highlight';
|
||||||
import remarkDirective from 'remark-directive';
|
import remarkDirective from 'remark-directive';
|
||||||
import type { PluggableList, Pluggable } from 'unified';
|
import type { PluggableList, Pluggable } from 'unified';
|
||||||
|
import type { Pluggable } from 'unified';
|
||||||
import { langSubset, preprocessLaTeX, handleDoubleClick } from '~/utils';
|
import { langSubset, preprocessLaTeX, handleDoubleClick } from '~/utils';
|
||||||
import { CodeBlockArtifact, CodeMarkdown } from '~/components/Artifacts/Code';
|
import { CodeBlockArtifact, CodeMarkdown } from '~/components/Artifacts/Code';
|
||||||
import { Artifact, artifactPlugin } from '~/components/Artifacts/Artifact';
|
import { Artifact, artifactPlugin } from '~/components/Artifacts/Artifact';
|
||||||
|
|
@ -124,6 +125,7 @@ const Markdown = memo(({ content = '', showCursor, isLatestMessage }: TContentPr
|
||||||
const artifactIdRef = useRef<string | null>(null);
|
const artifactIdRef = useRef<string | null>(null);
|
||||||
const codeBlocksRef = useRef<number | null>(null);
|
const codeBlocksRef = useRef<number | null>(null);
|
||||||
const LaTeXParsing = useRecoilValue<boolean>(store.LaTeXParsing);
|
const LaTeXParsing = useRecoilValue<boolean>(store.LaTeXParsing);
|
||||||
|
const codeArtifacts = useRecoilValue<boolean>(store.codeArtifacts);
|
||||||
|
|
||||||
const isInitializing = content === '';
|
const isInitializing = content === '';
|
||||||
|
|
||||||
|
|
@ -155,18 +157,20 @@ const Markdown = memo(({ content = '', showCursor, isLatestMessage }: TContentPr
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const remarkPlugins: Pluggable[] = codeArtifacts
|
||||||
|
? [
|
||||||
|
supersub,
|
||||||
|
remarkGfm,
|
||||||
|
[remarkMath, { singleDollarTextMath: true }],
|
||||||
|
remarkDirective,
|
||||||
|
artifactPlugin,
|
||||||
|
]
|
||||||
|
: [supersub, remarkGfm, [remarkMath, { singleDollarTextMath: true }]];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ReactMarkdown
|
<ReactMarkdown
|
||||||
remarkPlugins={[
|
/** @ts-ignore */
|
||||||
/* @ts-ignore */
|
remarkPlugins={remarkPlugins}
|
||||||
supersub,
|
|
||||||
remarkGfm,
|
|
||||||
/* @ts-ignore */
|
|
||||||
[remarkMath, { singleDollarTextMath: true }],
|
|
||||||
remarkDirective,
|
|
||||||
/* @ts-ignore */
|
|
||||||
artifactPlugin,
|
|
||||||
]}
|
|
||||||
/* @ts-ignore */
|
/* @ts-ignore */
|
||||||
rehypePlugins={rehypePlugins}
|
rehypePlugins={rehypePlugins}
|
||||||
// linkTarget="_new"
|
// linkTarget="_new"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue