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
45 changes: 24 additions & 21 deletions apps/dashboard/knip.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
{
"$schema": "https://unpkg.com/knip@5/schema.json",
"ignore": [
"src/@/components/ui/**",
"src/@/components/misc/AnnouncementBanner.tsx",
"src/@/components/cmd-k-search/index.tsx",
"src/@/lib/search.ts"
],
"ignoreBinaries": ["only-allow"],
"ignoreDependencies": [
"@thirdweb-dev/service-utils",
"@thirdweb-dev/vault-sdk",
"thirdweb",
"@types/color",
"fast-xml-parser",
"@workspace/ui",
"tailwindcss-animate",
"@radix-ui/react-tooltip",
"shiki"
],
"next": true,
"project": ["src/**"]
"$schema": "https://unpkg.com/knip@5/schema.json",
"ignore": [
"src/@/components/ui/**",
"src/@/components/misc/AnnouncementBanner.tsx",
"src/@/components/cmd-k-search/index.tsx",
"src/@/lib/search.ts"
],
"ignoreBinaries": ["only-allow"],
"ignoreDependencies": [
"@thirdweb-dev/service-utils",
"@thirdweb-dev/vault-sdk",
"thirdweb",
"@types/color",
"fast-xml-parser",
"@workspace/ui",
"tailwindcss-animate",
"@radix-ui/react-tooltip",
"shiki",
"react-children-utilities",
"react-markdown",
"remark-gfm"
],
"next": true,
"project": ["src/**"]
}
226 changes: 1 addition & 225 deletions apps/dashboard/src/@/components/blocks/markdown-renderer.tsx
Original file line number Diff line number Diff line change
@@ -1,225 +1 @@
import { onlyText } from "react-children-utilities";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
import { CodeClient } from "@/components/ui/code/code.client";
import { PlainTextCodeBlock } from "@/components/ui/code/plaintext-code";
import { InlineCode } from "@/components/ui/inline-code";
import {
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import { UnderlineLink } from "@/components/ui/UnderlineLink";
import { cn } from "@/lib/utils";

export const MarkdownRenderer: React.FC<{
markdownText: string;
className?: string;
code?: {
disableCodeHighlight?: boolean;
ignoreFormattingErrors?: boolean;
className?: string;
};
inlineCode?: {
className?: string;
};
p?: {
className?: string;
};
li?: {
className?: string;
};
skipHtml?: boolean;
}> = (markdownProps) => {
const { markdownText, className, code } = markdownProps;
const commonHeadingClassName = "mb-2 leading-5 font-semibold tracking-tight";

return (
<div className={className}>
<ReactMarkdown
components={{
a: (props) => (
<UnderlineLink
href={props.href ?? "#"}
rel="noopener noreferrer"
target="_blank"
{...cleanedProps(props)}
className="mt-4"
/>
),

code: ({ ...props }) => {
const codeStr = onlyText(props.children);

if (props?.className || codeStr.length > 100) {
if (code?.disableCodeHighlight || !props.className) {
return (
<div className="my-4">
{/* @ts-expect-error - TODO: fix this */}
<PlainTextCodeBlock
{...cleanedProps(props)}
className={markdownProps.code?.className}
code={onlyText(props.children).trim()}
/>
</div>
);
}
const language = props.className.replace("language-", "");
return (
<div className="my-4">
<CodeClient
// @ts-expect-error - TODO: fix this
lang={language}
{...cleanedProps(props)}
className={markdownProps.code?.className}
code={onlyText(props.children).trim()}
ignoreFormattingErrors={code?.ignoreFormattingErrors}
/>
</div>
);
}

return (
<InlineCode
className={markdownProps.inlineCode?.className}
code={onlyText(props.children).trim()}
/>
);
},
h1: (props) => (
<h2
className={cn(
commonHeadingClassName,
"mb-3 border-dashed border-b pb-2 text-xl md:text-2xl",
)}
{...cleanedProps(props)}
/>
),

h2: (props) => (
<h3
{...cleanedProps(props)}
className={cn(
commonHeadingClassName,
"mt-8 mb-3 border-dashed border-b pb-2 text-lg md:text-xl",
)}
/>
),

h3: (props) => (
<h4
{...cleanedProps(props)}
className={cn(
commonHeadingClassName,
"mt-4 text-base md:text-lg",
)}
/>
),

h4: (props) => (
<h5
{...cleanedProps(props)}
className={cn(commonHeadingClassName, "mt-4 text-lg")}
/>
),

h5: (props) => (
<h6
{...cleanedProps(props)}
className={cn(commonHeadingClassName, "mt-4 text-lg")}
/>
),

h6: (props) => (
<p
{...cleanedProps(props)}
className={cn(commonHeadingClassName, "mt-4 text-lg")}
/>
),

hr: (props) => (
<hr {...cleanedProps(props)} className="my-5 bg-border" />
),
li: ({ children: c, ...props }) => (
<li
className={cn(
"text-muted-foreground leading-relaxed [&>p]:m-0",
markdownProps.li?.className,
)}
{...cleanedProps(props)}
>
{c}
</li>
),
ol: (props) => (
<ol
className="mb-4 list-outside list-decimal pl-4 space-y-2 [&>li]:first:mt-2"
{...cleanedProps(props)}
/>
),

p: (props) => (
<p
className={cn(
"mb-3 text-muted-foreground leading-7",
markdownProps.p?.className,
)}
{...cleanedProps(props)}
/>
),
strong(props) {
return <strong className="font-medium" {...cleanedProps(props)} />;
},

table: (props) => (
<div className="mb-6">
<TableContainer>
<Table {...cleanedProps(props)} />
</TableContainer>
</div>
),
tbody: (props) => <TableBody {...cleanedProps(props)} />,

td: (props) => (
<TableCell {...cleanedProps(props)} className="text-left" />
),

th: ({ children: c, ...props }) => (
<TableHead
{...cleanedProps(props)}
className="text-left text-muted-foreground"
>
{c}
</TableHead>
),
thead: (props) => <TableHeader {...cleanedProps(props)} />,
tr: (props) => <TableRow {...cleanedProps(props)} />,
ul: (props) => {
return (
<ul
className="mb-4 list-outside list-disc pl-4 space-y-2 [&>li]:first:mt-2"
{...cleanedProps(props)}
/>
);
},
}}
remarkPlugins={[remarkGfm]}
skipHtml={markdownProps.skipHtml}
>
{markdownText}
</ReactMarkdown>
</div>
);
};

function cleanedProps<T extends object & { node?: unknown }>(
props: T,
): Omit<T, "node"> {
// biome-ignore lint/correctness/noUnusedVariables: EXPECTED
const { node, ...rest } = props;
return rest;
}
export { MarkdownRenderer } from "@workspace/ui/components/markdown-renderer";
6 changes: 3 additions & 3 deletions apps/dashboard/src/@/components/chat/CustomChats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -413,15 +413,15 @@ function StyledMarkdownRenderer(props: {
}) {
return (
<MarkdownRenderer
className="[&>*:first-child]:mt-0 [&>*:first-child]:border-none [&>*:first-child]:pb-0 [&>*:last-child]:mb-0"
className="text-sm text-foreground [&>*:first-child]:mt-0 [&>*:first-child]:border-none [&>*:first-child]:pb-0 [&>*:last-child]:mb-0 leading-relaxed"
code={{
className: "bg-card",
ignoreFormattingErrors: true,
}}
inlineCode={{ className: "border-none" }}
li={{ className: "text-foreground leading-relaxed" }}
markdownText={props.text}
p={{
className: props.type === "assistant" ? "" : "leading-normal",
className: "text-foreground leading-relaxed",
}}
skipHtml
/>
Expand Down
17 changes: 1 addition & 16 deletions apps/dashboard/src/@/components/ui/UnderlineLink.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
import Link from "next/link";
import { cn } from "../../lib/utils";

type LinkProps = React.ComponentProps<typeof Link>;

export function UnderlineLink(props: LinkProps) {
return (
<Link
{...props}
className={cn(
"underline decoration-muted-foreground/50 decoration-dotted underline-offset-[5px] hover:text-foreground hover:decoration-foreground hover:decoration-solid",
props.className,
)}
/>
);
}
export { UnderlineLink } from "@workspace/ui/components/UnderlineLink";
5 changes: 4 additions & 1 deletion apps/playground-web/knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"@workspace/ui",
"tailwindcss-animate",
"@radix-ui/react-tooltip",
"prettier"
"prettier",
"react-children-utilities",
"react-markdown",
"remark-gfm"
],
"next": true,
"project": ["src/**"]
Expand Down
Loading
Loading