+# MDX Renderer [`@m2d/react-markdown`]
-[](https://github.com/md2docx/react-markdown/actions/workflows/test.yml) [](https://codeclimate.com/github/md2docx/react-markdown/maintainability) [](https://codecov.io/gh/md2docx/react-markdown) [](https://www.npmjs.com/package/@m2d/react-markdown) [](https://www.npmjs.com/package/@m2d/react-markdown)  [](https://gitpod.io/from-referrer/)
+[](https://github.com/md2docx/react-markdown/actions/workflows/test.yml)
+[](https://codeclimate.com/github/md2docx/react-markdown/maintainability)
+[](https://codecov.io/gh/md2docx/react-markdown)
+[](https://www.npmjs.com/package/@m2d/react-markdown)
+[](https://www.npmjs.com/package/@m2d/react-markdown)
+
-> โจ A modern, JSX-compatible, SSR-ready Markdown renderer for React โ with full access to MDAST & HAST trees for tools like `mdast2docx`.
+> โจ A modern, SSR-compatible Markdown renderer for React with full MDAST/HAST access โ built for **customization**, **performance**, and **document generation** - **docx/pdf**.
---
-## ๐ฅ Why mdx-render?
+## ๐ฅ Why `@m2d/react-markdown`?
-`mdx-render` goes beyond traditional React Markdown libraries by focusing on:
+`@m2d/react-markdown` goes beyond traditional React Markdown libraries by focusing on:
- โ
**Server-side rendering (SSR)** without hooks
- โ
**Full JSX children support** (not just strings)
@@ -17,9 +22,21 @@
- โ
**Custom component overrides** per tag
- โ
**Integration with tools like [`mdast2docx`](https://github.com/md2docx/mdast2docx)**
+Compared to `react-markdown`, this library offers:
+
+| Feature | `@m2d/react-markdown` โ
| `react-markdown` โ |
+| ----------------------------------- | ------------------------ | ------------------- |
+| Full JSX support (not just strings) | โ
| โ |
+| SSR-safe (no hooks) | โ
| โ ๏ธ (limited) |
+| MDAST + HAST access via `astRef` | โ
| โ |
+| Component-level overrides | โ
| โ
|
+| Unified plugin support | โ
| โ
|
+| Tiny bundle (minzipped) | **~35 kB** | ~45 kB |
+| Built-in DOCX-friendly AST output | โ
| โ |
+
---
-## ๐ Installation
+## ๐ฆ Installation
```bash
pnpm add @m2d/react-markdown
@@ -39,10 +56,30 @@ yarn add @m2d/react-markdown
---
-## โก Quick Example
+## ๐ Server vs Client
+
+By default, this package is SSR-safe and has **no client-specific hooks**.
+
+### โ
Server (default):
+
+```tsx
+import { Md } from "@m2d/react-markdown";
+```
+
+### ๐ Client (for dynamic reactivity/memoization):
```tsx
-import { Md } from "mdx-render";
+import { Md } from "@m2d/react-markdown/client";
+```
+
+This version supports client-side behavior with memoization and dynamic JSX rendering.
+
+---
+
+## โก Example: Rendering + Exporting DOCX
+
+```tsx
+import { Md } from "@m2d/react-markdown/client";
import { toDocx } from "mdast2docx";
import { useRef } from "react";
@@ -55,7 +92,7 @@ export default function Page() {
@@ -64,48 +101,50 @@ export default function Page() {
}
```
+> Note for Server Component use you can replace useRef with custom ref object `const astRef = {current: undefined} as AstRef`
+
---
## ๐ง JSX-Aware Parsing
-Unlike other libraries, this renderer supports **JSX as children**, which means you can nest Markdown inside arbitrary components:
+Unlike most markdown renderers, `@m2d/react-markdown` supports **arbitrary JSX as children**:
```tsx
completely + em: Unwrap, + blockquote: Omit, + code: props =>, }}> - {`*This will be unwrapped*\n\n> This will be removed!`} -
Please enroll in [our courses](https://mayank-chaudhari.vercel.app/courses) or [sponsor](https://github.com/sponsors/mayank1513) our work.
+> ๐ก Want to support this project? [Sponsor](https://github.com/sponsors/mayank1513) or check out our [courses](https://mayank-chaudhari.vercel.app/courses)!
---
-with ๐ by Mayank Kumar Chaudhari
+Built with โค๏ธ by Mayank Kumar Chaudhari
diff --git a/lib/CHANGELOG.md b/lib/CHANGELOG.md index 21995b39..d901f23c 100644 --- a/lib/CHANGELOG.md +++ b/lib/CHANGELOG.md @@ -1,5 +1,38 @@ # @m2d/react-markdown +## 0.2.0 + +### Minor Changes + +- e1d4106: Add client-side `