{"id":28911583,"url":"https://github.com/md2docx/react-markdown","last_synced_at":"2026-05-04T01:33:58.826Z","repository":{"id":300418827,"uuid":"1005311389","full_name":"md2docx/react-markdown","owner":"md2docx","description":"SSR-ready React Markdown renderer with MDAST reuse, JSX support, and unified plugin pipeline.","archived":false,"fork":false,"pushed_at":"2026-04-26T16:47:52.000Z","size":755,"stargazers_count":11,"open_issues_count":3,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-26T18:23:48.109Z","etag":null,"topics":["docx","jsx","markdown","mdast","react","rehype","remark","renderer","ssr","unified"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/md2docx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"contributing.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["md2docx","mayank1513"],"polar":"mayank1513","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":["https://pages.razorpay.com/mayank1513"]}},"created_at":"2025-06-20T03:10:48.000Z","updated_at":"2026-04-26T16:47:55.000Z","dependencies_parsed_at":"2025-12-01T20:01:53.413Z","dependency_job_id":null,"html_url":"https://github.com/md2docx/react-markdown","commit_stats":null,"previous_names":["md2docx/react-markdown"],"tags_count":7,"template":false,"template_full_name":"react18-tools/turborepo-template","purl":"pkg:github/md2docx/react-markdown","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/md2docx%2Freact-markdown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/md2docx%2Freact-markdown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/md2docx%2Freact-markdown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/md2docx%2Freact-markdown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/md2docx","download_url":"https://codeload.github.com/md2docx/react-markdown/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/md2docx%2Freact-markdown/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32591601,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T22:12:39.696Z","status":"ssl_error","status_checked_at":"2026-05-03T22:09:10.534Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docx","jsx","markdown","mdast","react","rehype","remark","renderer","ssr","unified"],"created_at":"2025-06-21T19:09:05.381Z","updated_at":"2026-05-04T01:33:58.820Z","avatar_url":"https://github.com/md2docx.png","language":"TypeScript","funding_links":["https://github.com/sponsors/md2docx","https://github.com/sponsors/mayank1513","https://polar.sh/mayank1513","https://pages.razorpay.com/mayank1513"],"categories":[],"sub_categories":[],"readme":"# MDX Renderer [`@m2d/react-markdown`] \u003cimg src=\"https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png\" style=\"height: 40px\"/\u003e\n\n[![test](https://github.com/md2docx/react-markdown/actions/workflows/test.yml/badge.svg)](https://github.com/md2docx/react-markdown/actions/workflows/test.yml)\n[![Maintainability](https://api.codeclimate.com/v1/badges/aa896ec14c570f3bb274/maintainability)](https://codeclimate.com/github/md2docx/react-markdown/maintainability)\n[![codecov](https://codecov.io/gh/md2docx/react-markdown/graph/badge.svg)](https://codecov.io/gh/md2docx/react-markdown)\n[![Version](https://img.shields.io/npm/v/@m2d/react-markdown.svg?colorB=green)](https://www.npmjs.com/package/@m2d/react-markdown)\n[![Downloads](https://img.jsdelivr.com/img.shields.io/npm/d18m/@m2d/react-markdown.svg)](https://www.npmjs.com/package/@m2d/react-markdown)\n![npm bundle size](https://img.shields.io/bundlephobia/minzip/@m2d/react-markdown)\n\n\u003e ✨ A modern, SSR-compatible Markdown renderer for React with full MDAST/HAST access — built for **customization**, **performance**, and **document generation** - **docx/pdf**.\n\n---\n\n## 🔥 Why `@m2d/react-markdown`?\n\n`@m2d/react-markdown` goes beyond traditional React Markdown libraries by focusing on:\n\n- ✅ **Server-side rendering (SSR)** without hooks\n- ✅ **Full JSX children support** (not just strings)\n- ✅ **Access to raw MDAST \u0026 HAST trees**\n- ✅ **Drop-in plugin support** via Unified (`remark`, `rehype`, etc.)\n- ✅ **Custom component overrides** per tag\n- ✅ **Integration with tools like [`mdast2docx`](https://github.com/md2docx/mdast2docx)**\n\nCompared to `react-markdown`, this library offers:\n\n| Feature                                | `@m2d/react-markdown` ✅ | `react-markdown` ❌ |\n| -------------------------------------- | ------------------------ | ------------------- |\n| Full JSX support (not just strings)    | ✅                       | ❌                  |\n| SSR-safe (no hooks)                    | ✅                       | ✅                  |\n| Client Side component with memoization | ✅                       | ❌                  |\n| MDAST + HAST access via `astRef`       | ✅                       | ❌                  |\n| Component-level overrides              | ✅                       | ✅                  |\n| Unified plugin support                 | ✅                       | ✅                  |\n| Tiny bundle (minzipped)                | **~35 kB**               | ~45 kB              |\n| Built-in DOCX-friendly AST output      | ✅                       | ❌                  |\n\n---\n\n## 📦 Installation\n\n```bash\npnpm add @m2d/react-markdown\n```\n\n**_or_**\n\n```bash\nnpm install @m2d/react-markdown\n```\n\n**_or_**\n\n```bash\nyarn add @m2d/react-markdown\n```\n\n---\n\n## 🚀 Server vs Client\n\nBy default, this package is SSR-safe and has **no client-specific hooks**.\n\n### ✅ Server (default):\n\n```tsx\nimport { Md } from \"@m2d/react-markdown\";\n```\n\n### 🔁 Client (for dynamic reactivity/memoization):\n\n```tsx\nimport { Md } from \"@m2d/react-markdown/client\";\n```\n\nThis version supports client-side behavior with memoization and dynamic JSX rendering.\n\n---\n\n## ⚡ Example: Rendering + Exporting DOCX\n\n```tsx\nimport { Md } from \"@m2d/react-markdown/client\";\nimport { toDocx } from \"mdast2docx\";\nimport { useRef } from \"react\";\n\nconst astRef = useRef([]);\n\nexport default function Page() {\n  return (\n    \u003c\u003e\n      \u003cMd astRef={astRef}\u003e{`# Hello\\n\\nThis is **Markdown**.`}\u003c/Md\u003e\n      \u003cbutton\n        onClick={() =\u003e {\n          const doc = toDocx(astRef.current[0].mdast);\n          // Save or download doc\n        }}\u003e\n        Export to DOCX\n      \u003c/button\u003e\n    \u003c/\u003e\n  );\n}\n```\n\n\u003e Note for Server Component use you can replace useRef with custom ref object `const astRef = {current: undefined} as AstRef`\n\n---\n\n## 🧠 JSX-Aware Parsing\n\nUnlike most markdown renderers, `@m2d/react-markdown` supports **arbitrary JSX as children**:\n\n```tsx\nimport { Mdx } from \"@m2d/react-markdown/server\";\n// ...\n\u003cMdx\u003e\n  \u003carticle\u003e{\"# Markdown Heading\\n\\nSome **rich** content.\"}\u003c/article\u003e\n\u003c/Mdx\u003e;\n```\n\n\u003e `astRef.current` is an array — one per Markdown string — each with `{ mdast, hast }`.\n\u003e The default `\u003cMd\u003e` export accepts only string children for better optimization.\n\n---\n\n## 🎨 Component Overrides\n\n```tsx\nimport { Md } from \"@m2d/react-markdown\";\nimport { Unwrap, Omit } from \"@m2d/react-markdown/server\";\n\n\u003cMd\n  components={{\n    em: Unwrap,\n    blockquote: Omit,\n    code: props =\u003e \u003cCodeBlock {...props} /\u003e,\n  }}\u003e\n  {`*em is unwrapped*\\n\\n\u003e blockquote is removed`}\n\u003c/Md\u003e;\n```\n\nUse the built-in helpers:\n\n- `Unwrap` – renders only children\n- `Omit` – removes element and content entirely\n- `CodeBlock` - it is your custom component\n\n---\n\n## 🔌 Plugin Support (Unified)\n\nUse any `remark` or `rehype` plugin:\n\n```tsx\n\u003cMd remarkPlugins={[remarkGfm]} rehypePlugins={[rehypeSlug, rehypeAutolinkHeadings]}\u003e\n  {markdown}\n\u003c/Md\u003e\n```\n\n---\n\n## 📂 Accessing MDAST + HAST\n\n```ts\ntype astRef = {\n  current: { mdast: Root; hast: HastRoot }[];\n};\n```\n\nUseful for:\n\n- 📄 DOCX export (`mdast2docx`)\n- 🧪 AST testing or analysis\n- 🛠️ Custom tree manipulation\n\n---\n\n## 📊 Performance\n\n\u003e **TL;DR:** `@m2d/react-markdown` performs competitively with `react-markdown`, especially on medium and large documents.\n\u003e\n\u003e 👉 [See full benchmarks →](./benchmark.md)\n\nBenchmarks include:\n\n- Multiple markdown fixture types (short, long, complex, deeply nested)\n- Plugin configurations like `remark-gfm`, `remark-math`, `rehype-raw`\n- Visual comparisons using interactive Mermaid `xychart-beta` charts\n- Ops/sec, ±%, and future memory profiling\n\n---\n\n## 💬 Upcoming Changes – Seeking Feedback\n\nWe're proposing a **major change** to the internal `astRef` structure to better support MDX-style custom components and rendering flexibility:\n\n👉 [Join the discussion →](https://github.com/md2docx/react-markdown/discussions/3)\n\nKey goals:\n\n- Allow `\u003cMd\u003e` to embed child components like JSX/MDX\n- Simplify recursive rendering model\n- Improve performance and reduce abstraction overhead\n\n## 🧭 Roadmap\n\n- [ ] 🔄 Merge JSX + `\u003cMd\u003e` segments into unified AST\n- [x] 🧪 Structural test utilities\n- [x] 🧑‍🏫 Next.js + DOCX example\n\n---\n\n## 🌍 Related Projects\n\n- [`mdast2docx`](https://github.com/md2docx/mdast2docx) – Convert MDAST → `.docx`\n- [`unified`](https://unifiedjs.com/) – Syntax tree ecosystem\n- [`react-markdown`](https://github.com/remarkjs/react-markdown) – Popular alternative (less customizable)\n\n---\n\n## 🙏 Acknowledgements\n\nWe are deeply grateful to the open-source community whose work made this project possible.\n\n- 🌱 **[react-markdown](https://github.com/remarkjs/react-markdown)** – For pioneering a React-based Markdown renderer. This library builds on its ideas while extending flexibility and SSR-readiness.\n- 🛠 **[unified](https://github.com/unifiedjs/unified)** – The brilliant engine powering our markdown-to-AST transformations.\n- ✨ **[remark](https://github.com/remarkjs/remark)** and **[rehype](https://github.com/rehypejs/rehype)** – For their modular ecosystems that make parsing and rendering delightful.\n- 🧾 **[mdast2docx](https://github.com/md2docx/mdast2docx)** – Our sister project that inspired the MDAST-first architecture of this library.\n\n\u003e 💖 To the maintainers, contributors, and communities behind these projects — thank you for your generosity, vision, and dedication to making the web better for everyone.\n\n---\n\n## 📘 License\n\nLicensed under the [MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/).\n\n\u003e 💡 Want to support this project? [Sponsor](https://github.com/sponsors/mayank1513) or check out our [courses](https://mayank-chaudhari.vercel.app/courses)!\n\n---\n\n\u003cp align=\"center\" style=\"text-align:center\"\u003eBuilt with ❤️ by \u003ca href=\"https://mayank-chaudhari.vercel.app\" target=\"_blank\"\u003eMayank Kumar Chaudhari\u003c/a\u003e\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmd2docx%2Freact-markdown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmd2docx%2Freact-markdown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmd2docx%2Freact-markdown/lists"}