Skip to content

fix: fix basic markdown usage #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2025
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
2 changes: 1 addition & 1 deletion src/components/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function Chat() {
<ChatBubble variant="sent">
<ChatBubbleAvatar fallback="User" className="w-14" />
<ChatBubbleMessage variant="sent" className="bg-zinc-700">
<Markdown className="text-gray-300">
<Markdown isInverted>
{sanitizeQuestionPrompt({
question: question?.message ?? "",
answer: answer?.message ?? "",
Expand Down
6 changes: 3 additions & 3 deletions src/components/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const wrapObjectOutput = (input: AlertConversation["trigger_string"]) => {
if (data === null) return "N/A";
if (typeof data === "string") {
return (
<Markdown className="bg-secondary rounded-lg overflow-auto w-fit p-1">
{data}
</Markdown>
<div className="bg-secondary rounded-lg overflow-auto w-fit p-1">
<Markdown>{data}</Markdown>
</div>
);
}
if (!data.type || !data.name) return "N/A";
Expand Down
17 changes: 2 additions & 15 deletions src/components/Help.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function Help() {
} catch (error) {
console.error("Error loading help content:", error);
setContent(
"# Error\nFailed to load help content. Please try again later."
"# Error\nFailed to load help content. Please try again later.",
);
}
};
Expand All @@ -40,20 +40,7 @@ export function Help() {

return (
<div className="max-w-5xl bg-white rounded-lg px-6 mx-auto">
<Markdown
className="prose prose-lg max-w-none
prose-headings:text-gray-900
prose-h1:text-3xl prose-h1:font-bold prose-h1:mb-8
prose-h2:text-2xl prose-h2:font-semibold prose-h2:mt-8 prose-h2:mb-4
prose-h3:text-xl prose-h3:font-medium prose-h3:mt-6 prose-h3:mb-3
prose-p:text-gray-600 prose-p:leading-relaxed
prose-code:text-blue-600
prose-pre:bg-gray-900 prose-pre:rounded-lg prose-pre:p-4
prose-pre:shadow-md
"
>
{content}
</Markdown>
<Markdown>{content}</Markdown>
</div>
);
}
25 changes: 6 additions & 19 deletions src/components/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import remarkGfm from "remark-gfm";
import ReactMarkdown from "react-markdown";
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
import { oneDark } from "react-syntax-highlighter/dist/esm/styles/prism";
import { cn } from "@/lib/utils";
import { CopyToClipboard } from "./CopyToClipboard";
import hljs from "highlight.js";

Expand Down Expand Up @@ -33,7 +32,7 @@ const LANGUAGES_SUBSET_DETECTION = [

interface Props {
children: string;
className?: string;
isInverted?: boolean;
}

const customStyle = {
Expand All @@ -52,9 +51,11 @@ const customStyle = {
boxSizing: "border-box",
},
};
export function Markdown({ children, className = "" }: Props) {

export function Markdown({ children, isInverted = false }: Props) {
return (
<ReactMarkdown
className={`max-w-none prose prose-pre:shadow-md prose-pre:rounded-lg prose-pre:p-4 prose-p:leading-relaxed prose-h1:text-3xl prose-h1:font-bold prose-h1:mb-8 prose-h2:text-2xl prose-h2:font-semibold prose-h2:mt-8 prose-h2:mb-4 prose-h3:text-xl prose-h3:font-medium prose-h3:mt-6 prose-h3:mb-3 ${isInverted ? "prose-invert" : ""}`}
components={{
code({ className, children, ...props }) {
if (!children) return null;
Expand All @@ -71,7 +72,7 @@ export function Markdown({ children, className = "" }: Props) {
<SyntaxHighlighter
style={customStyle}
language={language}
PreTag="div"
PreTag="pre"
className="rounded-lg overflow-hidden shadow-lg text-sm my-6 whitespace-normal"
wrapLines
{...props}
Expand All @@ -84,22 +85,9 @@ export function Markdown({ children, className = "" }: Props) {
</div>
);
},
p({ children }) {
return (
<p
className={cn(
"text-gray-600 leading-relaxed mt-6 mb-3",
className,
)}
>
{children}
</p>
);
},
pre({ children }) {
return <div className="not-prose">{children}</div>;
return children;
},

a({ children, ...props }) {
return (
<a
Expand All @@ -116,7 +104,6 @@ export function Markdown({ children, className = "" }: Props) {
},
}}
remarkPlugins={[remarkGfm]}
className={className}
>
{children}
</ReactMarkdown>
Expand Down
Loading