|
1 |
| -## 🧩 Plugin Template for `mdast2docx` & `@m2d/remark-docx` <img src="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png" style="height: 40px"/> |
| 1 | +# `@m2d/html` <img src="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png" height="40"/> |
2 | 2 |
|
3 |
| -[](https://github.com/md2docx/md2docx-plugin-template/actions/workflows/test.yml) [](https://codeclimate.com/github/md2docx/md2docx-plugin-template/maintainability) [](https://codecov.io/gh/md2docx/md2docx-plugin-template) [](https://www.npmjs.com/package/@m2d/emoji) [](https://www.npmjs.com/package/@m2d/emoji)  |
| 3 | +[](https://www.npmjs.com/package/@m2d/html)   |
4 | 4 |
|
5 |
| -> This repository serves as a starting point for building plugins that extend the functionality of [`mdast2docx`](https://www.npmjs.com/package/mdast2docx), [`@m2d/core`](https://www.npmjs.com/package/@m2d/core) and [`@m2d/remark-docx`](https://www.npmjs.com/package/@m2d/remark-docx). |
| 5 | +> Parses embedded **HTML** into extended **MDAST nodes** to unlock full HTML-to-DOCX conversion support. |
6 | 6 |
|
7 |
| -<details> |
8 |
| -<summary style="cursor:pointer"><h2 style="display:inline-block">Features</h2></summary> |
| 7 | +--- |
| 8 | + |
| 9 | +## 📦 Installation |
| 10 | + |
| 11 | +```bash |
| 12 | +npm install @m2d/html |
| 13 | +``` |
| 14 | + |
| 15 | +```bash |
| 16 | +pnpm add @m2d/html |
| 17 | +``` |
9 | 18 |
|
10 |
| -This template offers the following pre-configured features. Additionally, your repository will automatically be re-branded with the help of workflows and post-install scripts. |
| 19 | +```bash |
| 20 | +yarn add @m2d/html |
| 21 | +``` |
11 | 22 |
|
12 |
| -✅ Monorepo powered by Turborepo and GitHub actions for automating building, testing, and deploying your plugin library |
| 23 | +--- |
13 | 24 |
|
14 |
| -✅ Examples with Next.js, and Vite to showcase how your library can be utilized, also helps in quick manual testing |
| 25 | +## 🚀 Overview |
15 | 26 |
|
16 |
| -✅ Examples pre-configured for Light/Dark theme based on user preference |
| 27 | +The `@m2d/html` plugin for [`mdast2docx`](https://github.com/mayankchaudhari/mdast2docx) enables the parsing and transformation of **embedded raw HTML** inside Markdown into **extended MDAST**. This unlocks the ability to support features like images, tables, checkboxes, styles, and more — using HTML tags directly inside your Markdown documents. |
17 | 28 |
|
18 |
| -✅ Examples ready to be deployed to Vercel |
| 29 | +--- |
19 | 30 |
|
20 |
| -✅ Code of Conduct and contributing files, ready for customization |
| 31 | +## ⚠️ Important |
21 | 32 |
|
22 |
| -✅ Prettier and linter configured according to modern best practices (Feel free to add your flavor) |
| 33 | +> **This plugin must be registered early in the plugin pipeline.** |
| 34 | +> It transforms raw HTML into extended MDAST nodes, which are then handled by other `@m2d/*` plugins (such as `@m2d/image`, `@m2d/table`, etc). |
| 35 | +> If used after other plugins, the HTML content, e.g, images, tables, or lists may be ignored or lost in the DOCX output. |
23 | 36 |
|
24 |
| -✅ Recommended VSCode extensions - Prettier and [Kanban board](https://github.com/mayank1513/vscode-extension-trello-kanban-board) for code formatting and project management directly within your IDE |
| 37 | +--- |
25 | 38 |
|
26 |
| -✅ Test setup with Vitest - A modern and fast testing framework supporting Jest-like APIs |
| 39 | +## 🛠️ Usage |
27 | 40 |
|
28 |
| -✅ Workflows to automate testing on every pull-request or code push event |
| 41 | +```ts |
| 42 | +import { htmlPlugin } from "@m2d/html"; |
29 | 43 |
|
30 |
| -✅ Workflow to automatically publish and create GitHub releases when you update your library's `package.json` file. |
| 44 | +const plugins = [ |
| 45 | + htmlPlugin(), // ✅ Must come first |
| 46 | + imagePlugin(), |
| 47 | + tablePlugin(), |
| 48 | +]; |
| 49 | +``` |
31 | 50 |
|
32 |
| -✅ Workflow to automatically rebrand the entire template based on your repository name. (Refer [TODO.md](./TODO.md)) |
| 51 | +--- |
33 | 52 |
|
34 |
| -✅ Plus, this repo includes a quick checklist for configuring Codecov and other badges, setting up your docs website on GitHub pages, and more. See [Checklist](./TODO.md) or open TKB(Workspace) if you have installed the Trello-Kanban-Board extension. |
| 53 | +## 🧩 How It Works |
35 | 54 |
|
36 |
| -</details> |
| 55 | +1. Parses raw embedded HTML using the DOM. |
| 56 | +2. Converts DOM nodes to extended MDAST nodes. |
| 57 | +3. Other `@m2d/*` plugins or the `@m2d/core` package consume these extended nodes to generate DOCX output. |
37 | 58 |
|
38 |
| -> <img src="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png" style="height: 20px"/> Star [this repository](https://github.com/md2docx/md2docx-plugin-template) and share it with your friends. |
| 59 | +> This plugin enriches the AST to enable other plugins and core engine to convert it to docx. |
39 | 60 |
|
40 | 61 | ---
|
41 | 62 |
|
42 |
| -## Getting Started: |
| 63 | +## ✅ Supported Elements |
| 64 | + |
| 65 | +| HTML Element | MDAST Node | Notes | |
| 66 | +| ------------------------- | ----------------- | ------------------------------------ | |
| 67 | +| `<img>` | `image` | Supports styles and attributes | |
| 68 | +| `<br>` | `break` | Line breaks | |
| 69 | +| `<strong>`, `<b>` | `strong` | Bold text | |
| 70 | +| `<em>`, `<i>` | `emphasis` | Italics | |
| 71 | +| `<del>`, `<s>` | `delete` | Strike-through | |
| 72 | +| `<a>` | `link` | Hyperlinks | |
| 73 | +| `<table>` | `table`, `row` | Basic tables supported | |
| 74 | +| `<input type="checkbox">` | `checkbox` | Readonly checkboxes | |
| 75 | +| `<hr>` | `thematicBreak` | Horizontal line | |
| 76 | +| `<blockquote>` | `blockquote` | Blockquotes | |
| 77 | +| Others | `paragraph`, etc. | Styled or inline nodes with rich AST | |
43 | 78 |
|
44 |
| -This template is based on [Turborepo Template](https://github.com/react18-tools/turborepo-template/). But this one is optimized for md2docx plugins. It includes pre-configured unit-tests, a lot of extra stuff provided by the turborepo-template is removed, and comes with dependencies and scripts optimized for md2docx plugin development. |
| 79 | +--- |
| 80 | + |
| 81 | +## 🎨 Style Support |
45 | 82 |
|
46 |
| -To get started, simply click on the `"Use this template"` button to create a new repository based on this template, and install dependencies. Customize it according to your requirements for your next md2docx plugin. |
| 83 | +- `text-align`, `color`, `background-color` |
| 84 | +- `font-weight`, `font-style`, `text-decoration` |
| 85 | +- `text-transform` |
| 86 | +- `border`, `border-left`, etc. |
| 87 | +- `display: inline-block` and similar behaviors |
47 | 88 |
|
48 |
| -For detailed instructions and a checklist, please refer to [TODO.md](./TODO.md). |
| 89 | +--- |
49 | 90 |
|
50 |
| -### 🤩 Don't forget to star [this repository](https://github.com/react18-tools/turborepo-template)! |
| 91 | +## ⚠️ Limitations |
51 | 92 |
|
52 |
| -Looking for a hands-on course to get started with Turborepo? Check out [React and Next.js with TypeScript](https://mayank-chaudhari.vercel.app/courses/react-and-next-js-with-typescript) and [The Game of Chess with Next.js, React, and TypeScript](https://www.udemy.com/course/game-of-chess-with-nextjs-react-and-typescript/?referralCode=851A28F10B254A8523FE) |
| 93 | +- External `<style>` tags or CSS files are not supported. |
| 94 | +- Complex or deeply nested HTML may be simplified. |
| 95 | +- Table `rowSpan` and `colSpan` are not yet supported. |
| 96 | +- Script tags and non-visual elements are ignored. |
53 | 97 |
|
54 | 98 | ---
|
55 | 99 |
|
56 |
| -### 🧰 Helpful References |
| 100 | +## 🧪 Production Ready |
| 101 | + |
| 102 | +While this plugin was originally experimental, it is now **stable and production-ready**. |
| 103 | +It powers the rich HTML support in `mdast2docx`, including checkboxes, tables, and styled images. |
57 | 104 |
|
58 |
| -- [`@m2d/core`](https://www.npmjs.com/package/@m2d/core) – Core MDAST to DOCX engine |
59 |
| -- [`@m2d/remark-docx`](https://www.npmjs.com/package/@m2d/remark-docx) – Remark plugin |
60 |
| -- [Unified Ecosystem](https://unifiedjs.com) – AST-based processors for markdown, html, etc. |
61 |
| -- [MDAST Spec](https://github.com/syntax-tree/mdast) – Markdown Abstract Syntax Tree |
| 105 | +> 🧵 **Contributions, ideas, and feedback are welcome!** Open an issue or PR anytime. |
62 | 106 |
|
63 | 107 | ---
|
64 | 108 |
|
65 |
| -### 💡 Derive Ideas from existing Plugins |
| 109 | +## 🔌 Related Plugins/Packages |
66 | 110 |
|
67 |
| -- `@m2d/math`: Parse math blocks and convert to equation DOCX |
68 |
| -- `@m2d/image`: Convert Markdown/HTML images to inline DOCX images |
69 |
| -- `@m2d/html`: Parse raw HTML into extended MDAST with styles |
70 |
| -- `@m2d/table`: Advanced table support with merged cells, widths, styles |
| 111 | +| Plugin | Purpose | |
| 112 | +| ---------------------------------------------------- | -------------------------------------- | |
| 113 | +| [`@m2d/core`](https://npmjs.com/package/@m2d/core) | Converts extended MDAST to DOCX | |
| 114 | +| [`@m2d/image`](https://npmjs.com/package/@m2d/image) | Renders image nodes to DOCX | |
| 115 | +| [`@m2d/table`](https://npmjs.com/package/@m2d/table) | Renders table nodes to DOCX | |
| 116 | +| [`@m2d/list`](https://npmjs.com/package/@m2d/list) | Enhanced list support (tasks, bullets) | |
71 | 117 |
|
72 | 118 | ---
|
73 | 119 |
|
74 |
| -### 🙌 Contribute |
| 120 | +## ⭐ Support Us |
75 | 121 |
|
76 |
| -If you’re building a plugin you'd like to share, let us know or open a PR in the [mdast2docx plugins repo](https://github.com/m2djs/mdast2docx)! |
| 122 | +If you find this useful: |
| 123 | + |
| 124 | +- ⭐ Star [mdast2docx](https://github.com/tiny-md/mdast2docx) on GitHub |
| 125 | +- ❤️ Consider [sponsoring](https://github.com/sponsors/mayank1513) |
| 126 | + |
| 127 | +--- |
77 | 128 |
|
78 |
| -> <img src="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png" style="height: 20px"/> Enrolling in [our courses](https://mayank-chaudhari.vercel.app/courses) or [sponsor](https://github.com/sponsors/mayank1513) our work. |
| 129 | +## 🧾 License |
79 | 130 |
|
80 |
| -<hr /> |
| 131 | +MIT © [Mayank Chaudhari](https://github.com/mayankchaudhari) |
81 | 132 |
|
82 |
| -<p align="center" style="text-align:center">with 💖 by <a href="https://mayank-chaudhari.vercel.app" target="_blank">Mayank Kumar Chaudhari</a></p> |
| 133 | +<p align="center">Made with 💖 by <a href="https://mayank-chaudhari.vercel.app" target="_blank">Mayank Kumar Chaudhari</a></p> |
0 commit comments