{"id":27002955,"url":"https://github.com/md2docx/remark-docx","last_synced_at":"2025-09-04T13:34:39.113Z","repository":{"id":284480399,"uuid":"955056238","full_name":"md2docx/remark-docx","owner":"md2docx","description":"A Unified/Remark plugin that injects a DOCX compiler using [`mdast2docx`](https://github.com/tiny-md/mdast2docx) and outputs `.docx` files from Markdown.","archived":false,"fork":false,"pushed_at":"2025-04-02T08:13:48.000Z","size":875,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T09:26:18.390Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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-26T03:23:18.000Z","updated_at":"2025-04-02T08:13:51.000Z","dependencies_parsed_at":"2025-03-26T05:39:31.369Z","dependency_job_id":null,"html_url":"https://github.com/md2docx/remark-docx","commit_stats":null,"previous_names":["md2docx/remark-docx"],"tags_count":2,"template":false,"template_full_name":"md2docx/md2docx-plugin-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/md2docx%2Fremark-docx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/md2docx%2Fremark-docx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/md2docx%2Fremark-docx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/md2docx%2Fremark-docx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/md2docx","download_url":"https://codeload.github.com/md2docx/remark-docx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247123086,"owners_count":20887261,"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":[],"created_at":"2025-04-04T05:14:32.336Z","updated_at":"2025-04-04T05:14:32.881Z","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":"# @m2d/remark-docx \u003cimg src=\"https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png\" height=\"40\"/\u003e\n\n[![test](https://github.com/md2docx/remark-docx/actions/workflows/test.yml/badge.svg)](https://github.com/md2docx/remark-docx/actions/workflows/test.yml) [![codecov](https://codecov.io/gh/md2docx/remark-docx/graph/badge.svg)](https://codecov.io/gh/md2docx/remark-docx) [![Version](https://img.shields.io/npm/v/@m2d/remark-docx?color=green)](https://www.npmjs.com/package/@m2d/remark-docx)\n![Downloads](https://img.shields.io/npm/d18m/@m2d/remark-docx)\n![Bundle Size](https://img.shields.io/bundlephobia/minzip/@m2d/remark-docx)\n\n\u003e A Unified/Remark plugin that injects a DOCX compiler using [`mdast2docx`](https://github.com/md2docx/mdast2docx) and outputs `.docx` files from Markdown.\n\n---\n\n## 🧭 Overview\n\n`@m2d/remark-docx` enables direct export of Markdown content to Microsoft Word (`.docx`) using the Unified ecosystem. It seamlessly bridges `remark` with the [`mdast2docx`](https://github.com/md2docx/mdast2docx) compiler and auto-injects common plugins like GFM tables, math, lists, and inline HTML support.\n\nIt’s designed for both **browser** and **Node.js** environments, handling environment-specific features like image or HTML parsing smartly.\n\n---\n\n## ✨ Features\n\n- 📄 Converts Markdown to `.docx` using `mdast2docx`\n- 🔌 Auto-injects plugins for GFM tables, math, lists, images, and HTML\n- 🧠 Smart: excludes DOM-only plugins in Node.js\n- 💥 Supports both `.process()` and `.processSync()` with an async `.result`\n- 🔄 Output as `Blob`, `Buffer`, or `base64`\n\n---\n\n## 📦 Installation\n\n```bash\nnpm install @m2d/remark-docx docx\n```\n\nAlso install any optional plugins you wish to include in your pipeline:\n\n```bash\nnpm install remark-parse remark-gfm remark-math remark-frontmatter\n```\n\nOther package managers:\n\n```bash\nyarn add @m2d/remark-docx docx\npnpm add @m2d/remark-docx docx\n```\n\n---\n\n## 🚀 Usage\n\n### 🔗 Browser Example (Async)\n\n```ts\nimport { unified } from \"unified\";\nimport remarkParse from \"remark-parse\";\nimport remarkGfm from \"remark-gfm\";\nimport remarkMath from \"remark-math\";\nimport remarkFrontmatter from \"remark-frontmatter\";\nimport { remarkDocx } from \"@m2d/remark-docx\";\n\nconst processor = unified()\n  .use(remarkParse)\n  .use(remarkGfm)\n  .use(remarkFrontmatter)\n  .use(remarkMath)\n  .use(remarkDocx);\n\nconst downloadDocx = () =\u003e {\n  processor\n    .process(md)\n    .then(res =\u003e res.result)\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 = \"document.docx\";\n      link.click();\n      URL.revokeObjectURL(url);\n    });\n};\n```\n\n### ⚡ Browser Example (Sync + Async Result)\n\n```ts\nconst { result } = processor.processSync(md) as { result: Promise\u003cBlob\u003e };\nresult.then(blob =\u003e {\n  const url = URL.createObjectURL(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### 🐢 Node.js Example\n\n```ts\nimport fs from \"node:fs\";\nimport { unified } from \"unified\";\nimport remarkParse from \"remark-parse\";\nimport remarkGfm from \"remark-gfm\";\nimport remarkMath from \"remark-math\";\nimport remarkFrontmatter from \"remark-frontmatter\";\nimport { remarkDocx } from \"@m2d/remark-docx\";\n\nconst markdown = `\n# Hello DOCX\n\nThis is a *Markdown* document with **tables**, math, and more.\n\n| A | B |\n|---|---|\n| 1 | 2 |\n\nInline math: $x^2 + y^2 = z^2$\n`;\n\nconst processor = unified()\n  .use(remarkParse)\n  .use(remarkGfm)\n  .use(remarkFrontmatter)\n  .use(remarkMath)\n  .use(remarkDocx, \"buffer\"); // outputType = \"buffer\" in Node\n\nconst { result } = processor.processSync(markdown) as { result: Promise\u003cBuffer\u003e };\n\nresult.then(buffer =\u003e {\n  fs.writeFileSync(\"output.docx\", buffer);\n  console.log(\"✔ DOCX file written: output.docx\");\n});\n```\n\n---\n\n## 🧩 Plugin Behavior\n\nBy default, these `mdast2docx` plugins are included:\n\n| Plugin        | Description             |\n| ------------- | ----------------------- |\n| `htmlPlugin`  | Parses inline HTML      |\n| `tablePlugin` | GFM table support       |\n| `listPlugin`  | Ordered/unordered lists |\n| `mathPlugin`  | KaTeX math blocks       |\n| `imagePlugin` | Resolves images         |\n\nOn **Node.js**, `htmlPlugin` and `imagePlugin` are automatically excluded to avoid DOM dependency issues.\n\nTo override this behavior, pass custom plugins using `sectionProps.plugins`.\n\n---\n\n## 📘 API\n\n### `remarkDocx(outputType?, docxProps?, sectionProps?)`\n\n| Param          | Type                                 | Description                         |\n| -------------- | ------------------------------------ | ----------------------------------- |\n| `outputType`   | `\"blob\"` \\| `\"buffer\"` \\| `\"base64\"` | Default is `\"blob\"`                 |\n| `docxProps`    | `IDocxProps`                         | Global DOCX config (optional)       |\n| `sectionProps` | `ISectionProps`                      | Section + plugin control (optional) |\n\nReturns a `Processor` where `.result` on `vfile` is a `Promise\u003cBlob | Buffer | string\u003e` depending on the mode.\n\n---\n\n## 🔥 Output Handling\n\nBoth `.process()` and `.processSync()` return a `vfile` with a `result` field:\n\n```ts\nconst file = await processor.process(md);\nconst blobOrBuffer = await file.result;\n```\n\n\u003e This makes the plugin environment-safe and decoupled from internal mutation or I/O.\n\n---\n\n## 🛠 Development\n\n```bash\nnpm run dev       # Watch mode\nnpm run build     # Compile to /dist\nnpm run lint      # Lint source\nnpm run test      # Run tests\n```\n\n---\n\n## 📄 License\n\nLicensed under the [MPL-2.0 License](https://www.mozilla.org/en-US/MPL/2.0/).\n\n---\n\n## 💖 Sponsors\n\nSupport the project \u0026 its ecosystem:\n\n- [@md2docx](https://github.com/sponsors/md2docx)\n- [@mayank1513](https://github.com/sponsors/mayank1513)\n\n---\n\n## 🔗 Related Projects\n\n- [`mdast2docx`](https://github.com/md2docx/mdast2docx) – The DOCX engine\n- [`docx`](https://github.com/dolanmiu/docx) – Low-level DOCX generation\n- [`unified`](https://unifiedjs.com) – Processor pipeline\n- [`remark`](https://github.com/remarkjs/remark) – Markdown parser\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%2Fremark-docx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmd2docx%2Fremark-docx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmd2docx%2Fremark-docx/lists"}