Fix markdown editor escaped list markers
This commit is contained in:
@@ -4,6 +4,7 @@ import remarkGfm from "remark-gfm";
|
||||
import { parseProjectMentionHref } from "@paperclipai/shared";
|
||||
import { cn } from "../lib/utils";
|
||||
import { useTheme } from "../context/ThemeContext";
|
||||
import { normalizeMarkdownArtifacts } from "../lib/markdown";
|
||||
|
||||
interface MarkdownBodyProps {
|
||||
children: string;
|
||||
@@ -114,6 +115,7 @@ function MermaidDiagramBlock({ source, darkMode }: { source: string; darkMode: b
|
||||
|
||||
export function MarkdownBody({ children, className }: MarkdownBodyProps) {
|
||||
const { theme } = useTheme();
|
||||
const normalizedMarkdown = normalizeMarkdownArtifacts(children);
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
@@ -154,7 +156,7 @@ export function MarkdownBody({ children, className }: MarkdownBodyProps) {
|
||||
},
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
{normalizedMarkdown}
|
||||
</Markdown>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
} from "@mdxeditor/editor";
|
||||
import { buildProjectMentionHref, parseProjectMentionHref } from "@paperclipai/shared";
|
||||
import { cn } from "../lib/utils";
|
||||
import { normalizeMarkdownArtifacts } from "../lib/markdown";
|
||||
|
||||
/* ---- Mention types ---- */
|
||||
|
||||
@@ -203,7 +204,7 @@ export const MarkdownEditor = forwardRef<MarkdownEditorRef, MarkdownEditorProps>
|
||||
}: MarkdownEditorProps, forwardedRef) {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const ref = useRef<MDXEditorMethods>(null);
|
||||
const latestValueRef = useRef(value);
|
||||
const latestValueRef = useRef(normalizeMarkdownArtifacts(value));
|
||||
const [uploadError, setUploadError] = useState<string | null>(null);
|
||||
const [isDragOver, setIsDragOver] = useState(false);
|
||||
const dragDepthRef = useRef(0);
|
||||
@@ -281,9 +282,10 @@ export const MarkdownEditor = forwardRef<MarkdownEditorRef, MarkdownEditorProps>
|
||||
}, [hasImageUpload]);
|
||||
|
||||
useEffect(() => {
|
||||
if (value !== latestValueRef.current) {
|
||||
ref.current?.setMarkdown(value);
|
||||
latestValueRef.current = value;
|
||||
const normalizedValue = normalizeMarkdownArtifacts(value);
|
||||
if (normalizedValue !== latestValueRef.current) {
|
||||
ref.current?.setMarkdown(normalizedValue);
|
||||
latestValueRef.current = normalizedValue;
|
||||
}
|
||||
}, [value]);
|
||||
|
||||
@@ -554,11 +556,15 @@ export const MarkdownEditor = forwardRef<MarkdownEditorRef, MarkdownEditorProps>
|
||||
>
|
||||
<MDXEditor
|
||||
ref={ref}
|
||||
markdown={value}
|
||||
markdown={normalizeMarkdownArtifacts(value)}
|
||||
placeholder={placeholder}
|
||||
onChange={(next) => {
|
||||
latestValueRef.current = next;
|
||||
onChange(next);
|
||||
const normalizedNext = normalizeMarkdownArtifacts(next);
|
||||
latestValueRef.current = normalizedNext;
|
||||
if (normalizedNext !== next) {
|
||||
ref.current?.setMarkdown(normalizedNext);
|
||||
}
|
||||
onChange(normalizedNext);
|
||||
}}
|
||||
onBlur={() => onBlur?.()}
|
||||
className={cn("paperclip-mdxeditor", !bordered && "paperclip-mdxeditor--borderless")}
|
||||
|
||||
Reference in New Issue
Block a user