nested-markdown
v0.0.14
Published
React renderer for extended markdown with inline nested markdown blocks.
Maintainers
Readme
nested-markdown
React renderer for extended markdown with inline nested markdown blocks.
Demo
Try out the live demo.
Install
npm i nested-markdownor
yarn add nested-markdownPeer dependencies:
react/react-dom(>= 17)
Quick Start
import NestedMarkdown from "nested-markdown";
const content = [
"This is normal markdown.",
"",
'```nested-md emoji="💡" show="both" bgColor="#F8FFEE" textColor="#0F172A" borderColor="#A5D6A7"',
"# Nested content",
"",
"- Supports GFM (tables, lists, etc.)",
"- Can show preview and/or the original code",
"```",
"",
].join("\n");
export default function App() {
return <NestedMarkdown content={content} theme="auto" />;
}Component API
NestedMarkdowncontent?: string— Markdown source (alias:children?: string)className?: string— Class for outer containercomponents?: Components—react-markdownoverrides merged with defaultsstyle?: React.CSSProperties— Inline styles for the outer containertheme?: "light" | "dark" | "auto"— Color theme (default"auto")- Also accepts most
react-markdownprops (e.g.remarkPlugins,rehypePlugins,allowedElements,skipHtml)
expandNestedMarkdown(markdown: string): Promise<string>— Preprocesses nested blocks into safe HTML
Nested Block Syntax
For a comprehensive guide on syntax, attributes, and examples, please refer to the User Manual.
Preferred (fenced) syntax:
```nested-md key="value" ...
...raw markdown body...
```Legacy (HTML comment) syntax:
- Start:
<!-- nested-md:start key="value" ... --> - Body: raw markdown body or an inner raw markdown body fenced
```md ... ``` - End:
<!-- nested-md:end -->
Attributes
id?: string— Copied todata-idon wrappershow?: "preview" | "code" | "both"— Display modebgColor?: string,textColor?: string,borderColor?: string— Colorsemoji?: string— Emoji/icon columnboxed?: "true" | "false"— Boxed UI (default true)style?: string— Extra inline styles for wrapper
Styling Defaults
- Tables are wrapped with horizontal scroll and basic table styles
- Images render with a normal
<img>and normalize relativesrcpaths - Inline
codeandmarkhave gentle defaults - Automatic Dark Mode: Custom colors (bg/text/border) are automatically adjusted for dark mode, so you don't need to specify separate dark theme colors.
Security
rehype-rawis enabled to render the preprocessed HTML- Strict
rehype-sanitizeschema allows only needed tags/attributes includingdiv[data-nested-md]
SSR
- Designed to work with SSR setups; ensure peer deps (
react) are present in the host app
License
- MIT
