diff --git a/frontend/src/components/ContentWithSnippets.tsx b/frontend/src/components/ContentWithSnippets.tsx index 88d1bd70..29023053 100644 --- a/frontend/src/components/ContentWithSnippets.tsx +++ b/frontend/src/components/ContentWithSnippets.tsx @@ -1,6 +1,7 @@ import React from "react"; -import ReactMarkdown from "react-markdown"; +import ReactMarkdown, { Components } from "react-markdown"; import { CodeSnippet } from "./CodeSnippet"; +import CustomAnchor from "./CustomAnchor"; interface ContentWithSnippetsProps { content: string; @@ -11,7 +12,11 @@ export const ContentWithSnippets: React.FC = ({ }) => { const parseContent = (text: string) => { const codeBlockRegex = /```(\w+(?:-exec)?)\n([\s\S]*?)```/g; - const parts = []; + const parts: { + type: "text" | "code"; + content: string; + language?: string; + }[] = []; let lastIndex = 0; let match; @@ -27,18 +32,24 @@ export const ContentWithSnippets: React.FC = ({ if (lang.endsWith("-exec")) { parts.push({ type: "code", + content: code.trim(), language: lang.replace("-exec", ""), - code: code.trim(), }); } else { - parts.push({ type: "text", content: match[0] }); + parts.push({ + type: "text", + content: match[0], + }); } lastIndex = match.index + match[0].length; } if (lastIndex < text.length) { - parts.push({ type: "text", content: text.slice(lastIndex) }); + parts.push({ + type: "text", + content: text.slice(lastIndex), + }); } return parts; @@ -48,10 +59,25 @@ export const ContentWithSnippets: React.FC = ({ return parseContent(content).map((part, index) => { if (part.type === "code" && part.language) { return ( - + ); } - return {part.content}; + return ( + + {part.content} + + ); }); }, [content]); diff --git a/frontend/src/components/CreateAnswerForm.tsx b/frontend/src/components/CreateAnswerForm.tsx index cae18e3d..f7d9650f 100644 --- a/frontend/src/components/CreateAnswerForm.tsx +++ b/frontend/src/components/CreateAnswerForm.tsx @@ -114,18 +114,7 @@ export function CreateAnswerForm({ questionId }: CreateAnswerFormProps) { {isPreviewMode ? (
-
- {" "} - -
- {/* Render ReactMarkdown for the rest of the content */} - - {content} - +
) : (