-
Notifications
You must be signed in to change notification settings - Fork 2
Add Markdown component with GFM support and XSS protection #19
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
Changes from 4 commits
a2f93b7
3b31240
e517621
d9a2987
c31876c
ee033e8
4ebe6c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ import './alert'; | |
| import './chart'; | ||
| import './list'; | ||
| import './tree-view'; | ||
| import './markdown'; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { ComponentRegistry } from '@object-ui/core'; | ||
| import { Markdown } from '@/ui'; | ||
|
|
||
| ComponentRegistry.register('markdown', | ||
| ({ schema, className, ...props }) => ( | ||
| <Markdown | ||
| content={schema.content || ''} | ||
| className={className} | ||
| {...props} | ||
| /> | ||
| ), | ||
| { | ||
| label: 'Markdown', | ||
| inputs: [ | ||
| { | ||
| name: 'content', | ||
| type: 'string', | ||
| label: 'Markdown Content', | ||
| required: true, | ||
| inputType: 'textarea' | ||
| }, | ||
| { name: 'className', type: 'string', label: 'CSS Class' } | ||
| ], | ||
| defaultProps: { | ||
| content: '# Hello World\n\nThis is a **markdown** component with *formatting* support.\n\n- Item 1\n- Item 2\n- Item 3', | ||
| } | ||
| } | ||
| ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import * as React from "react" | ||
| import ReactMarkdown from "react-markdown" | ||
| import remarkGfm from "remark-gfm" | ||
| import rehypeSanitize from "rehype-sanitize" | ||
| import { cn } from "@/lib/utils" | ||
|
|
||
| export interface MarkdownProps { | ||
| content: string | ||
| className?: string | ||
| } | ||
|
Comment on lines
+13
to
+31
|
||
|
|
||
| function Markdown({ content, className }: MarkdownProps) { | ||
| return ( | ||
| <div | ||
| data-slot="markdown" | ||
| className={cn( | ||
| "prose prose-sm dark:prose-invert max-w-none", | ||
| "prose-headings:font-semibold prose-headings:tracking-tight", | ||
| "prose-h1:text-3xl prose-h2:text-2xl prose-h3:text-xl", | ||
| "prose-p:leading-relaxed prose-p:text-foreground", | ||
| "prose-a:text-primary prose-a:no-underline hover:prose-a:underline", | ||
| "prose-code:text-foreground prose-code:bg-muted prose-code:px-1 prose-code:py-0.5 prose-code:rounded prose-code:before:content-none prose-code:after:content-none", | ||
| "prose-pre:bg-muted prose-pre:text-foreground prose-pre:border", | ||
| "prose-blockquote:border-l-primary prose-blockquote:text-muted-foreground", | ||
| "prose-strong:text-foreground prose-strong:font-semibold", | ||
| "prose-ul:list-disc prose-ol:list-decimal", | ||
| "prose-li:text-foreground prose-li:marker:text-muted-foreground", | ||
| "prose-table:border prose-th:border prose-th:bg-muted prose-td:border", | ||
| "prose-img:rounded-md prose-img:border", | ||
| className | ||
| )} | ||
| > | ||
| <ReactMarkdown | ||
| remarkPlugins={[remarkGfm]} | ||
| rehypePlugins={[rehypeSanitize]} | ||
| > | ||
| {content} | ||
| </ReactMarkdown> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export { Markdown } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The renderer component function lacks JSDoc documentation. Add a JSDoc comment explaining that this is a Schema-driven renderer for markdown content, following the 'Schema First' principle outlined in Rule #3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added detailed JSDoc documentation to the markdown renderer component explaining its schema-driven architecture and usage. Includes example JSON configuration and lists all supported features. (commit c31876c)