Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions components/code-block.tsx

This file was deleted.

6 changes: 3 additions & 3 deletions components/diffview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { EditorState } from 'prosemirror-state';
import { EditorView } from 'prosemirror-view';
import React, { useEffect, useRef } from 'react';
import { renderToString } from 'react-dom/server';
import ReactMarkdown from 'react-markdown';
import { Streamdown } from 'streamdown';

import { diffEditor, DiffType } from '@/lib/editor/diff';

Expand Down Expand Up @@ -60,10 +60,10 @@ export const DiffView = ({ oldContent, newContent }: DiffEditorProps) => {
const parser = DOMParser.fromSchema(diffSchema);

const oldHtmlContent = renderToString(
<ReactMarkdown>{oldContent}</ReactMarkdown>,
<Streamdown>{oldContent}</Streamdown>,
);
const newHtmlContent = renderToString(
<ReactMarkdown>{newContent}</ReactMarkdown>,
<Streamdown>{newContent}</Streamdown>,
);

const oldContainer = document.createElement('div');
Expand Down
91 changes: 6 additions & 85 deletions components/markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,10 @@
import Link from 'next/link';
import React, { memo } from 'react';
import ReactMarkdown, { type Components } from 'react-markdown';
import remarkGfm from 'remark-gfm';
import { CodeBlock } from './code-block';
import { Streamdown, type StreamdownProps } from 'streamdown';

type Components = StreamdownProps['components'];

const components: Partial<Components> = {
// @ts-expect-error
code: CodeBlock,
pre: ({ children }) => <>{children}</>,
ol: ({ node, children, ...props }) => {
return (
<ol className="list-decimal list-outside ml-4" {...props}>
{children}
</ol>
);
},
li: ({ node, children, ...props }) => {
return (
<li className="py-1" {...props}>
{children}
</li>
);
},
ul: ({ node, children, ...props }) => {
return (
<ul className="list-decimal list-outside ml-4" {...props}>
{children}
</ul>
);
},
strong: ({ node, children, ...props }) => {
return (
<span className="font-semibold" {...props}>
{children}
</span>
);
},
a: ({ node, children, ...props }) => {
return (
// @ts-expect-error
Expand All @@ -49,59 +18,11 @@ const components: Partial<Components> = {
</Link>
);
},
h1: ({ node, children, ...props }) => {
return (
<h1 className="text-3xl font-semibold mt-6 mb-2" {...props}>
{children}
</h1>
);
},
h2: ({ node, children, ...props }) => {
return (
<h2 className="text-2xl font-semibold mt-6 mb-2" {...props}>
{children}
</h2>
);
},
h3: ({ node, children, ...props }) => {
return (
<h3 className="text-xl font-semibold mt-6 mb-2" {...props}>
{children}
</h3>
);
},
h4: ({ node, children, ...props }) => {
return (
<h4 className="text-lg font-semibold mt-6 mb-2" {...props}>
{children}
</h4>
);
},
h5: ({ node, children, ...props }) => {
return (
<h5 className="text-base font-semibold mt-6 mb-2" {...props}>
{children}
</h5>
);
},
h6: ({ node, children, ...props }) => {
return (
<h6 className="text-sm font-semibold mt-6 mb-2" {...props}>
{children}
</h6>
);
},
};

const remarkPlugins = [remarkGfm];

const NonMemoizedMarkdown = ({ children }: { children: string }) => {
return (
<ReactMarkdown remarkPlugins={remarkPlugins} components={components}>
{children}
</ReactMarkdown>
);
};
const NonMemoizedMarkdown = ({ children }: { children: string }) => (
<Streamdown components={components}>{children}</Streamdown>
);

export const Markdown = memo(
NonMemoizedMarkdown,
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,12 @@
"react": "19.0.0-rc-45804af1-20241021",
"react-data-grid": "7.0.0-beta.47",
"react-dom": "19.0.0-rc-45804af1-20241021",
"react-markdown": "^9.0.1",
"react-resizable-panels": "^2.1.7",
"redis": "^5.0.0",
"remark-gfm": "^4.0.0",
"resumable-stream": "^2.0.0",
"server-only": "^0.0.1",
"sonner": "^1.5.0",
"streamdown": "^1.0.11",
"swr": "^2.2.5",
"tailwind-merge": "^2.5.2",
"tailwindcss-animate": "^1.0.7",
Expand Down
Loading
Loading