{"id":27002961,"url":"https://github.com/md2docx/mdast2docx","last_synced_at":"2025-04-04T05:14:34.182Z","repository":{"id":281968965,"uuid":"945261069","full_name":"md2docx/mdast2docx","owner":"md2docx","description":"Utility to convert MDAST (Markdown Abstract Syntax Tree) to DOCX","archived":false,"fork":false,"pushed_at":"2025-04-02T08:18:56.000Z","size":860,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T09:27:34.914Z","etag":null,"topics":["ai","converter","docx","generative-ai","javascript","mayank1513","nodejs","remark","remark-plugin","remark-plugins","typescript","unified"],"latest_commit_sha":null,"homepage":"https://mdast2docx.vercel.app/","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},"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-03-09T02:37:43.000Z","updated_at":"2025-04-02T08:19:00.000Z","dependencies_parsed_at":"2025-03-25T08:39:03.740Z","dependency_job_id":"0b4cb304-3675-4904-b0b4-b4116c5a0589","html_url":"https://github.com/md2docx/mdast2docx","commit_stats":null,"previous_names":["tiny-md/mdast2docx","md2docx/mdast2docx"],"tags_count":10,"template":false,"template_full_name":"react18-tools/turborepo-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/md2docx%2Fmdast2docx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/md2docx%2Fmdast2docx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/md2docx%2Fmdast2docx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/md2docx%2Fmdast2docx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/md2docx","download_url":"https://codeload.github.com/md2docx/mdast2docx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246790554,"owners_count":20834521,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["ai","converter","docx","generative-ai","javascript","mayank1513","nodejs","remark","remark-plugin","remark-plugins","typescript","unified"],"created_at":"2025-04-04T05:14:33.451Z","updated_at":"2025-04-04T05:14:34.175Z","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":"# **MDAST (Markdown Abstract Syntax Tree) to DOCX** \u003cimg src=\"https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png\" style=\"height: 40px\"/\u003e\n\n🚀 **Effortlessly convert Markdown Abstract Syntax Trees (MDAST) to DOCX.**\n\n[![Test](https://github.com/md2docx/mdast2docx/actions/workflows/test.yml/badge.svg)](https://github.com/md2docx/mdast2docx/actions/workflows/test.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/aa896ec14c570f3bb274/maintainability)](https://codeclimate.com/github/md2docx/mdast2docx/maintainability) [![Code Coverage](https://codecov.io/gh/md2docx/mdast2docx/graph/badge.svg)](https://codecov.io/gh/md2docx/mdast2docx) [![Version](https://img.shields.io/npm/v/mdast2docx.svg?colorB=green)](https://www.npmjs.com/package/mdast2docx) [![Downloads](https://img.shields.io/npm/d18m/mdast2docx)](https://www.npmjs.com/package/mdast2docx) ![Bundle Size](https://img.shields.io/bundlephobia/minzip/mdast2docx)\n\n---\n\n## **✨ Features**\n\n✅ **MDAST to DOCX conversion** — Supports standard Markdown elements  \n✅ **Footnotes handling** — Converts Markdown footnotes to DOCX format  \n✅ **Tables support** — Converts Markdown tables into DOCX tables  \n✅ **Hyperlink support** — External and internal hyperlinks are now fully functional  \n✅ **New Plugin Architecture** — Extend and customize DOCX output with plugins  \n✅ **Customizable image handling** — Images are now supported via `@m2d/image` plugin\n\n\u003e **Note:** Images are no longer supported by default. To enable image support, use the image plugin from `@m2d/image` or `mdast2docx/plugins` explicitly.  \n\u003e This change helps us keep the library lean and extensible by community via plugins.\n\n---\n\n## **🚀 Relevance to Generative AI**\n\n\u003cdetails open\u003e\n\u003csummary\u003e\n\u003ci\u003eConverts markdown content/artifacts generated by Generative AI to docx for further processing/record-keeping/sharing.\u003c/i\u003e\n\u003c/summary\u003e\n\nModern **Generative AI tools** often produce structured content in **Markdown (MD)** format. However, converting this AI-generated Markdown into **professional DOCX documents** requires an additional transformation step. This is where **MDAST to DOCX** comes in.\n\n### **How It Works**\n\n1. **AI tools generate content in Markdown**.\n2. **Unified.js \u0026 Remark Ecosystem** convert Markdown into **Markdown Abstract Syntax Tree (MDAST)**.\n3. **MDAST to DOCX** processes this structure and exports a **well-formatted DOCX document**.\n\n### **Use Cases**\n\n- **AI-Generated Reports** – Convert AI-generated Markdown reports into polished DOCX files.\n- **AI-Powered Content Export** – Transform AI-generated blogs, research papers, and structured content into a DOCX format for easy sharing and editing.\n- **Client \u0026 Server Flexibility** – Works both in **browser-based AI tools** and **high-performance server environments**.\n\n### **✅ Benefits**\n\n- **Works on both Client \u0026 Server** – Choose to **offload processing to the client** for better scalability or **run it on the server** for batch conversions.\n- **Optimized \u0026 Extensible** – Use **only the plugins you need**, keeping your AI workflows lightweight.\n\nBy integrating **MDAST to DOCX**, AI applications can **seamlessly export Markdown-based content into DOCX**, making it more accessible, editable, and shareable. 🚀\n\n\u003c/details\u003e\n\n---\n\n## **📦 Installation**\n\n### **Install Everything at Once**\n\n```bash\npnpm add mdast2docx\n```\n\n### **Or Install Only What You Need (Scoped Packages)**\n\n```bash\npnpm add @m2d/core @m2d/html @m2d/image @m2d/math @m2d/table @m2d/list @m2d/mdast\n```\n\n---\n\n## **🚀 Usage**\n\n### **Basic Example**\n\n```typescript\nimport { toDocx } from \"mdast2docx\";\nimport { unified } from \"unified\";\nimport remarkParse from \"remark-parse\";\nimport remarkMmd from \"remark-mmd\"; // Assumed MMD plugin\n\nconst markdown = `\n# Sample Document  \nThis is a **bold** text and _italic_ text.  \n\n\u003e A blockquote example  \n\n- List Item 1  \n- List Item 2  \n\n[Click Here](https://example.com)  \n\nThis is a footnote reference[^1].  \n\n[^1]: This is the footnote content.\n`;\n\nconst mdast = unified().use(remarkParse).use(remarkMmd).parse(markdown);\n\n(async () =\u003e {\n  const docxBlob = await toDocx(mdast, { title: \"My Document\" }, {});\n  const url = URL.createObjectURL(docxBlob as Blob);\n  const link = document.createElement(\"a\");\n  link.href = url;\n  link.download = \"document.docx\";\n  link.click();\n  URL.revokeObjectURL(url);\n})();\n```\n\n---\n\n## **📜 API Reference**\n\n### **`toDocx(astInputs, docxProps, defaultSectionProps, outputType?)`**\n\n| Parameter                 | Type                                               | Description                                                      |\n| ------------------------- | -------------------------------------------------- | ---------------------------------------------------------------- |\n| `astInputs`               | `Root` \\| `{ ast: Root; props?: ISectionProps }[]` | Single or multiple MDAST trees with optional section properties. |\n| `docxProps`               | `IDocxProps`                                       | General document properties (title, styles, metadata).           |\n| `defaultSectionProps`     | `ISectionProps`                                    | Default properties for document sections.                        |\n| `outputType` _(optional)_ | `\"blob\"` (default) \\| `\"buffer\"` \\| `\"base64\"`     | Format of the generated DOCX document.                           |\n\n📌 **Returns:** A `Promise` resolving to a DOCX document in the chosen format.\n\n---\n\n## **📜 Supported Markdown Elements**\n\n| Markdown Syntax                    | Supported in DOCX                     |\n| ---------------------------------- | ------------------------------------- |\n| Headings `# H1` to `###### H6`     | ✅                                    |\n| Paragraphs                         | ✅                                    |\n| Bold `**text**` \u0026 Italics `_text_` | ✅                                    |\n| Blockquotes `\u003e quote`              | ✅                                    |\n| Lists (ordered \u0026 unordered)        | ✅ _(ordered lists via `listPlugin`)_ |\n| Links `[text](url)`                | ✅                                    |\n| Images `![alt](url)`               | ✅ _(via `imagePlugin`)_              |\n| Code Blocks `` `code` ``           | ✅                                    |\n| Footnotes `[^1]`                   | ✅                                    |\n| Tables                             | ✅ _(via `tablePlugin`)_              |\n| Hyperlinks (external \u0026 internal)   | ✅                                    |\n| Latex Math                         | ✅ _(via `mathPlugin`)_               |\n| HTML Tags                          | ✅ _(via `htmlPlugin`)_               |\n\n---\n\n## **🔧 Configuration**\n\nYou can customize the DOCX output using `ISectionProps` and `IDocxProps`.\n\n### **Example: Customizing Styles**\n\n```typescript\nconst docxProps = {\n  title: \"Styled Document\",\n  author: \"John Doe\",\n};\n\nconst sectionProps = {\n  page: { margin: { top: 1000, bottom: 1000, left: 1200, right: 1200 } },\n};\n\nconst docxBlob = await toDocx(mdast, docxProps, sectionProps);\n```\n\n### **Use Plugins**\n\nPlugins allow extending functionality like adding image or table support.\n\n```typescript\nimport { toDocx } from \"@m2d/core\";\nimport { imagePlugin } from \"@m2d/image\";\nimport { tablePlugin } from \"@m2d/table\";\nimport { listPlugin } from \"@m2d/list\";\nimport { mathPlugin } from \"@m2d/math\";\n\nconst downloadDocx = () =\u003e {\n  toDocx(\n    mdast,\n    {},\n    { plugins: [imagePlugin(), tablePlugin(), listPlugin(), mathPlugin()] },\n    \"blob\",\n  ).then(blob =\u003e {\n    const url = URL.createObjectURL(blob as Blob);\n    const link = document.createElement(\"a\");\n    link.href = url;\n    link.download = \"my-document.docx\";\n    link.click();\n    URL.revokeObjectURL(url);\n  });\n};\n```\n\n📖 **More details:**\n\n- [DOCX.js Document Properties](https://docx.js.org/#/usage/document)\n- [DOCX.js Section Options](https://docx.js.org/#/usage/sections)\n\n---\n\n## **🧠 Relevance in Generative AI**\n\nAI tools often generate Markdown as output (e.g., reports, documentation, summaries). This library makes it easy to convert those Markdown-based outputs into rich DOCX documents.\n\n- Supports both **client-side** and **server-side** usage\n- Enables **offloading document generation** to users' browsers or running high-performance server renderers\n- Combine it with `unified` and `remark` to parse Markdown into MDAST, and then convert to DOCX seamlessly\n\n---\n\n## **📝 Contributing**\n\nWe welcome contributions! To get started:\n\n1. **Fork** the repository\n2. **Create a feature branch** (`git checkout -b feature-new`)\n3. **Commit your changes** (`git commit -m \"Add new feature\"`)\n4. **Push to GitHub** (`git push origin feature-new`)\n5. **Open a Pull Request** 🚀\n\n### **Extend Functionality with Plugins**\n\nThe community can create plugins to extend the functionality of this library. For inspiration, check out the existing plugins in the [`lib/src/plugins`](https://github.com/md2docx/mdast2docx/tree/main/lib/src/plugins) folder.\n\n---\n\n## **📄 License**\n\nThis project is **licensed under MPL-2.0**. See the [LICENSE](./LICENSE) file for details.\n\n---\n\n## **🙌 Acknowledgments**\n\nThanks to the **docx.js** and **unified.js** ecosystems for making this possible.\n\n\u003e ⭐ **Star this repository** if you find it useful!  \n\u003e ❤️ Support our work by [sponsoring](https://github.com/sponsors/mayank1513).\n\n---\n\n\u003cp align=\"center\"\u003eMade 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%2Fmdast2docx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmd2docx%2Fmdast2docx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmd2docx%2Fmdast2docx/lists"}