Skip to content

Commit

Permalink
feat: add support for emoji inside messages markdown
Browse files Browse the repository at this point in the history
Closes 5382
  • Loading branch information
thingersoft committed Jan 21, 2025
1 parent fa9e778 commit 358c4ac
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 20 deletions.
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"rehype-highlight": "^6.0.0",
"rehype-katex": "^6.0.3",
"remark-directive": "^3.0.0",
"remark-emoji": "^5.0.1",
"remark-gfm": "^4.0.0",
"remark-math": "^6.0.0",
"remark-supersub": "^1.0.0",
Expand Down
32 changes: 17 additions & 15 deletions client/src/components/Chat/Messages/Content/Markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import React, { memo, useMemo, useRef, useEffect } from 'react';
import remarkGfm from 'remark-gfm';
import remarkMath from 'remark-math';
import supersub from 'remark-supersub';
import rehypeKatex from 'rehype-katex';
import { useRecoilValue } from 'recoil';
import React, { memo, useEffect, useMemo, useRef } from 'react';
import ReactMarkdown from 'react-markdown';
import { useRecoilValue } from 'recoil';
import rehypeHighlight from 'rehype-highlight';
import rehypeKatex from 'rehype-katex';
import remarkDirective from 'remark-directive';
import remarkEmoji from 'remark-emoji';
import remarkGfm from 'remark-gfm';
import remarkMath from 'remark-math';
import supersub from 'remark-supersub';
import type { Pluggable } from 'unified';
import { CodeBlockProvider, useCodeBlockContext, useToastContext } from '~/Providers';
import { Artifact, artifactPlugin } from '~/components/Artifacts/Artifact';
import { langSubset, preprocessLaTeX, handleDoubleClick } from '~/utils';
import { useToastContext, CodeBlockProvider, useCodeBlockContext } from '~/Providers';
import CodeBlock from '~/components/Messages/Content/CodeBlock';
import { useFileDownload } from '~/data-provider';
import useLocalize from '~/hooks/useLocalize';
import store from '~/store';
import { handleDoubleClick, langSubset, preprocessLaTeX } from '~/utils';

type TCodeProps = {
inline: boolean;
Expand Down Expand Up @@ -185,13 +186,14 @@ const Markdown = memo(({ content = '', showCursor, isLatestMessage }: TContentPr

const remarkPlugins: Pluggable[] = codeArtifacts
? [
supersub,
remarkGfm,
[remarkMath, { singleDollarTextMath: true }],
remarkDirective,
artifactPlugin,
]
: [supersub, remarkGfm, [remarkMath, { singleDollarTextMath: true }]];
supersub,
remarkEmoji,
remarkGfm,
[remarkMath, { singleDollarTextMath: true }],
remarkDirective,
artifactPlugin,
]
: [supersub, remarkEmoji, remarkGfm, [remarkMath, { singleDollarTextMath: true }]];

return (
<CodeBlockProvider>
Expand Down
10 changes: 6 additions & 4 deletions client/src/components/Chat/Messages/Content/MarkdownLite.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { memo } from 'react';
import ReactMarkdown from 'react-markdown';
import rehypeHighlight from 'rehype-highlight';
import rehypeKatex from 'rehype-katex';
import remarkEmoji from 'remark-emoji';
import remarkGfm from 'remark-gfm';
import remarkMath from 'remark-math';
import rehypeKatex from 'rehype-katex';
import supersub from 'remark-supersub';
import ReactMarkdown from 'react-markdown';
import rehypeHighlight from 'rehype-highlight';
import type { PluggableList } from 'unified';
import { code, codeNoExecution, a, p } from './Markdown';
import { CodeBlockProvider } from '~/Providers';
import { langSubset } from '~/utils';
import { a, code, codeNoExecution, p } from './Markdown';

const MarkdownLite = memo(
({ content = '', codeExecution = true }: { content?: string; codeExecution?: boolean }) => {
Expand All @@ -30,6 +31,7 @@ const MarkdownLite = memo(
remarkPlugins={[
/** @ts-ignore */
supersub,
remarkEmoji,
remarkGfm,
[remarkMath, { singleDollarTextMath: true }],
]}
Expand Down
160 changes: 159 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 358c4ac

Please sign in to comment.