Convert markdown to JSX with ease for React and React-like projects.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
React component wrapper providing convenient JSX integration with markdown content and configuration options.
High-level React component that accepts markdown content as children and renders it as JSX with optional configuration.
/**
* React component that renders markdown content as JSX
* Accepts markdown string as children and optional configuration
*/
const Markdown: React.FC<MarkdownComponentProps>;
interface MarkdownComponentProps extends Omit<React.HTMLAttributes<Element>, 'children'> {
/** Markdown content as string */
children: string;
/** Configuration options for parsing and rendering */
options?: MarkdownToJSX.Options;
}Usage Examples:
import Markdown from "markdown-to-jsx";
import React from "react";
// Basic usage
function BasicExample() {
return (
<Markdown>
# Welcome
This is **markdown** content!
</Markdown>
);
}
// With options
function WithOptions() {
return (
<Markdown
options={{
overrides: {
h1: { props: { className: "main-title" } },
p: { props: { className: "paragraph" } }
}
}}
>
# Custom Styled Title
This paragraph will have custom styling.
</Markdown>
);
}
// With additional HTML props
function WithProps() {
return (
<Markdown
className="markdown-container"
id="content"
data-testid="markdown-content"
>
# Content
The wrapper element will receive these props.
</Markdown>
);
}
// Dynamic content
function DynamicContent({ content }: { content: string }) {
return (
<Markdown options={{ forceBlock: true }}>
{content}
</Markdown>
);
}The component automatically merges additional props with the wrapper element, allowing for full HTML attribute support.
// Props are passed through to the wrapper element
<Markdown
className="custom-class"
style={{ padding: '1rem' }}
onClick={handleClick}
data-markdown="true"
>
# Clickable Content
</Markdown>
// Results in wrapper element with all props appliedThe component intelligently chooses wrapper elements based on content and configuration:
<span> by default<div> by defaultforceWrapper: trueoptions.wrapper to specify element typeoptions.wrapper: null to return array of elementsUsage Examples:
// Inline content (wrapped in span)
<Markdown>Just some *italic* text</Markdown>
// Renders: <span>Just some <em>italic</em> text</span>
// Block content (wrapped in div)
<Markdown>
# Title
Paragraph content
</Markdown>
// Renders: <div><h1>Title</h1><p>Paragraph content</p></div>
// Custom wrapper
<Markdown options={{ wrapper: "article" }}>
# Article Title
Content here
</Markdown>
// Renders: <article>...</article>
// No wrapper (returns array)
<Markdown options={{ wrapper: null }}>
# Title
Content
</Markdown>
// Renders: [<h1>Title</h1>, <p>Content</p>]
// Force wrapper for single elements
<Markdown options={{ forceWrapper: true }}>
Just a single paragraph
</Markdown>
// Renders: <span><p>Just a single paragraph</p></span>The component provides user-friendly error handling for invalid inputs and malformed markdown.
// Component validates input type
<Markdown>{123}</Markdown> // Logs error in development
// Handles empty content gracefully
<Markdown>{""}</Markdown> // Renders empty span
// Handles undefined content
<Markdown>{undefined}</Markdown> // Treats as empty stringAdditional validation and warnings in development mode for better developer experience.
// Development warnings for common mistakes
<Markdown>{123}</Markdown>
// Console warning: "markdown-to-jsx: component only accepts string children"
<Markdown options={{ overrides: "invalid" }}>Content</Markdown>
// Console error: "options.overrides must be an object literal"Full TypeScript support with proper type checking for props and options.
import Markdown from "markdown-to-jsx";
// TypeScript ensures correct prop types
function TypedComponent({ content }: { content: string }) {
return (
<Markdown
options={{
overrides: {
// TypeScript validates override structure
h1: {
component: "h2", // Valid
props: { className: "title" } // Valid
},
p: CustomParagraph // Valid React component
}
}}
>
{content}
</Markdown>
);
}
// Custom component with proper typing
const CustomParagraph: React.FC<React.PropsWithChildren<{}>> = ({ children }) => (
<p className="custom-paragraph">{children}</p>
);