BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/simple-ai/markdown-content

Markdown Content

simple-ai/markdown-content
FreeComponent

A component that renders markdown content.

Live preview

live · rendered by the registry
Rendered by simple-ai on their own page — this is the component running, not a screenshot of it.

Install it

npx shadcn@latest add https://simple-ai.dev/r/markdown-content.json

Source

./src/registry/ui/markdown-content.tsxsimple-ai.dev/r/markdown-content.json · first 6 KB
1import { marked } from "marked";
2import type * as React from "react";
3import { isValidElement, memo, Suspense, useMemo } from "react";
4import ReactMarkdown, { type Components } from "react-markdown";
5import rehypeRaw from "rehype-raw";
6import remarkGfm from "remark-gfm";
7import { cn } from "@/lib/utils";
8
9const DEFAULT_PRE_BLOCK_CLASS =
10 "my-4 overflow-x-auto w-fit rounded-xl bg-zinc-950 text-zinc-50 dark:bg-zinc-900 border border-border p-4";
11
12const extractTextContent = (node: React.ReactNode): string => {
13 if (typeof node === "string") {
14 return node;
15 }
16 if (Array.isArray(node)) {
17 return node.map(extractTextContent).join("");
18 }
19 if (isValidElement(node)) {
20 // @ts-expect-error
21 return extractTextContent(node.props.children);
22 }
23 return "";
24};
25
26interface HighlightedPreProps extends React.HTMLAttributes<HTMLPreElement> {
27 language: string;
28}
29
30const HighlightedPre = memo(
31 async ({
32 children,
33 className,
34 language,
35 ...props
36 }: HighlightedPreProps) => {
37 const { codeToTokens, bundledLanguages } = await import("shiki");
38 const code = extractTextContent(children);
39
40 if (!(language in bundledLanguages)) {
41 return (
42 <pre
43 {...props}
44 className={cn(DEFAULT_PRE_BLOCK_CLASS, className)}
45 >
46 <code className="whitespace-pre-wrap">{children}</code>
47 </pre>
48 );
49 }
50
51 const { tokens } = await codeToTokens(code, {
52 lang: language as keyof typeof bundledLanguages,
53 themes: {
54 light: "github-dark",
55 dark: "github-dark",
56 },
57 });
58
59 return (
60 <pre {...props} className={cn(DEFAULT_PRE_BLOCK_CLASS, className)}>
61 <code className="whitespace-pre-wrap break-all">
62 {tokens.map((line, lineIndex) => (
63 <span
64 key={`line-${
65 // biome-ignore lint/suspicious/noArrayIndexKey: Needed for react key
66 lineIndex
67 }`}
68 >
69 {line.map((token, tokenIndex) => {
70 const style =
71 typeof token.htmlStyle === "string"
72 ? undefined
73 : token.htmlStyle;
74
75 return (
76 <span
77 key={`token-${
78 // biome-ignore lint/suspicious/noArrayIndexKey: Needed for react key
79 tokenIndex
80 }`}
81 style={style}
82 >
83 {token.content}
84 </span>
85 );
86 })}
87 {lineIndex !== tokens.length - 1 && "\n"}
88 </span>
89 ))}
90 </code>
91 </pre>
92 );
93 },
94);
95
96HighlightedPre.displayName = "HighlightedPre";
97
98interface CodeBlockProps extends React.HTMLAttributes<HTMLPreElement> {
99 language: string;
100}
101
102// … truncated

What it pulls in

npm packages

  • react-markdown
  • marked
  • shiki
  • remark-gfm
  • rehype-raw

Files it writes

  • ./src/registry/ui/markdown-content.tsx

Facts

Registry
simple-ai
Type
registry:ui
Access
Free
Files written
1
Licence
the repository states none
First indexed
2026-08-02
Last confirmed
today

Go to the source

Docs on simple-ai simple-ai.dev Alwurts/simple-ai on GitHub Raw registry item This item as JSON

More from simple-ai

All 77 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
base-handlebase-handlesimple-aiComponentsFree1 dep
base-nodebase-nodesimple-aiComponentsFreeno deps
Chat Inputchat-inputsimple-aiComponentsFree7 deps
Chat Messagechat-messagesimple-aiComponentsFreeno deps
Chat Message Areachat-message-areasimple-aiComponentsFree1 dep
Chat Suggestionschat-suggestionssimple-aiComponentsFreeno deps
Editable Handleeditable-handlesimple-aiComponentsFree1 dep
Generate Text Nodegenerate-text-nodesimple-aiComponentsFree1 dep
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex