Skip to content

Commit 0ace211

Browse files
authored
Merge pull request #1 from md2docx/html
Html
2 parents a080efa + 60e983b commit 0ace211

27 files changed

+827
-2735
lines changed

.github/workflows/manual-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ jobs:
3333
working-directory: ./lib
3434
- name: clean up working directory
3535
run: git status && git clean -f -d && git status
36-
# - name: Copy Readme file
37-
# run: cp ./README.md ./lib # todo: uncomment this line while rebranding
36+
- name: Copy Readme file
37+
run: cp ./README.md ./lib # todo: uncomment this line while rebranding
3838
- name: Apply changesets, publish and create release, branches and tags
3939
run: node ./scripts/manual-publish.js
4040
env:

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ jobs:
3535
- name: Test
3636
run: pnpm test
3737
working-directory: ./lib
38-
# - name: Copy Readme file
39-
# run: cp ./README.md ./lib # will be uncommented while rebranding
38+
- name: Copy Readme file
39+
run: cp ./README.md ./lib # will be uncommented while rebranding
4040
- name: Apply changesets, publish and create release, branches and tags
4141
run: node ./scripts/publish.js
4242
env:

.tkb

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,46 @@
11
{
22
"scope": "Workspace",
33
"tasks": {
4+
"G-1H47JpSI69kav1qZ-kp": {
5+
"id": "G-1H47JpSI69kav1qZ-kp",
6+
"description": "Star [this repository](https://github.com/md2docx/md2docx-plugin-template/) for easy access and to show your support",
7+
"columnId": "column-todo"
8+
},
9+
"RX4J5v4y5IOe_ucf8pMRT": {
10+
"id": "RX4J5v4y5IOe_ucf8pMRT",
11+
"description": "🌟 Enable [private vulnerability reporting](https://github.com/md2docx/html/security) (For public repo - do this after updating visibility to public)",
12+
"columnId": "column-todo"
13+
},
14+
"EdPbrbJLllUHfZmCS80f7": {
15+
"id": "EdPbrbJLllUHfZmCS80f7",
16+
"description": "Set up `CodeCov`\n - Visit Codecov and set up your repo\n - Create [repository secret]((https://github.com/md2docx/html/settings/secrets/actions)) for `CODECOV_TOKEN`",
17+
"columnId": "column-todo"
18+
},
19+
"MLLUsAhCKaKxvEXFY0HSq": {
20+
"id": "MLLUsAhCKaKxvEXFY0HSq",
21+
"description": "Set up `CodeClimate`\n - Visit CodeClimate and set up your repo\n - Create [repository secret]((https://github.com/md2docx/html/settings/secrets/actions)) for `CC_TEST_REPORTER_ID`\n - Add `*.test.*` to ignore patterns on the website\n - Update Code Climate badge",
22+
"columnId": "column-todo"
23+
},
24+
"gMYfaAh2RABMP8uZRQgNx": {
25+
"id": "gMYfaAh2RABMP8uZRQgNx",
26+
"description": "Add `NPM_AUTH_TOKEN` to repository secrets to automate package publishing\n - Log in to your [`npm` account](https://www.npmjs.com/login) and create an automation token\n - Create a new repository secret `NPM_AUTH_TOKEN`",
27+
"columnId": "column-todo"
28+
},
29+
"dC7QDBLH8BmHUfaYmIt81": {
30+
"id": "dC7QDBLH8BmHUfaYmIt81",
31+
"description": "(Optional) Add Repo Stats by visiting and setting up [repobeats](https://repobeats.axiom.co/)",
32+
"columnId": "column-todo"
33+
},
34+
"P_NrSJQ8m91Odgz8E1fS6": {
35+
"id": "P_NrSJQ8m91Odgz8E1fS6",
36+
"description": "Create your library and update examples",
37+
"columnId": "column-todo"
38+
},
39+
"1dRWJhy45E1Rq5wZAmPHt": {
40+
"id": "1dRWJhy45E1Rq5wZAmPHt",
41+
"description": "Update README as required",
42+
"columnId": "column-todo"
43+
},
444
"55DAZwduwTvlaxaJC8hlX": {
545
"id": "55DAZwduwTvlaxaJC8hlX",
646
"description": "(Optional) Set up [Deepsource](https://app.deepsource.com/login) for static code analysis",
@@ -47,6 +87,14 @@
4787
"id": "column-todo",
4888
"title": "To do",
4989
"tasksIds": [
90+
"G-1H47JpSI69kav1qZ-kp",
91+
"RX4J5v4y5IOe_ucf8pMRT",
92+
"EdPbrbJLllUHfZmCS80f7",
93+
"MLLUsAhCKaKxvEXFY0HSq",
94+
"gMYfaAh2RABMP8uZRQgNx",
95+
"dC7QDBLH8BmHUfaYmIt81",
96+
"P_NrSJQ8m91Odgz8E1fS6",
97+
"1dRWJhy45E1Rq5wZAmPHt",
5098
"55DAZwduwTvlaxaJC8hlX",
5199
"FDFqCQvLm2mUlnTJ3Gna5",
52100
"O1qAByMoxhHOR-a_guL91",
@@ -69,4 +117,4 @@
69117
]
70118
}
71119
]
72-
}
120+
}

README.md

Lines changed: 92 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,133 @@
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"/>
22

3-
[![test](https://github.com/md2docx/md2docx-plugin-template/actions/workflows/test.yml/badge.svg)](https://github.com/md2docx/md2docx-plugin-template/actions/workflows/test.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/aa896ec14c570f3bb274/maintainability)](https://codeclimate.com/github/md2docx/md2docx-plugin-template/maintainability) [![codecov](https://codecov.io/gh/md2docx/md2docx-plugin-template/graph/badge.svg)](https://codecov.io/gh/md2docx/md2docx-plugin-template) [![Version](https://img.shields.io/npm/v/@m2d/emoji.svg?colorB=green)](https://www.npmjs.com/package/@m2d/emoji) [![Downloads](https://img.jsdelivr.com/img.shields.io/npm/d18m/@m2d/emoji.svg)](https://www.npmjs.com/package/@m2d/emoji) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@m2d/emoji)
3+
[![Version](https://img.shields.io/npm/v/@m2d/html?color=green)](https://www.npmjs.com/package/@m2d/html) ![Downloads](https://img.shields.io/npm/d18m/@m2d/html) ![Bundle Size](https://img.shields.io/bundlephobia/minzip/@m2d/html)
44

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.
66
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+
```
918

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+
```
1122

12-
✅ Monorepo powered by Turborepo and GitHub actions for automating building, testing, and deploying your plugin library
23+
---
1324

14-
✅ Examples with Next.js, and Vite to showcase how your library can be utilized, also helps in quick manual testing
25+
## 🚀 Overview
1526

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.
1728

18-
✅ Examples ready to be deployed to Vercel
29+
---
1930

20-
✅ Code of Conduct and contributing files, ready for customization
31+
## ⚠️ Important
2132

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.
2336
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+
---
2538

26-
✅ Test setup with Vitest - A modern and fast testing framework supporting Jest-like APIs
39+
## 🛠️ Usage
2740

28-
✅ Workflows to automate testing on every pull-request or code push event
41+
```ts
42+
import { htmlPlugin } from "@m2d/html";
2943

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+
```
3150

32-
✅ Workflow to automatically rebrand the entire template based on your repository name. (Refer [TODO.md](./TODO.md))
51+
---
3352

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
3554

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.
3758

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.
3960
4061
---
4162

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 |
4378

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
4582

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
4788

48-
For detailed instructions and a checklist, please refer to [TODO.md](./TODO.md).
89+
---
4990

50-
### 🤩 Don't forget to star [this repository](https://github.com/react18-tools/turborepo-template)!
91+
## ⚠️ Limitations
5192

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.
5397

5498
---
5599

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.
57104

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.
62106
63107
---
64108

65-
### 💡 Derive Ideas from existing Plugins
109+
## 🔌 Related Plugins/Packages
66110

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) |
71117

72118
---
73119

74-
### 🙌 Contribute
120+
## ⭐ Support Us
75121

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+
---
77128

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
79130

80-
<hr />
131+
MIT © [Mayank Chaudhari](https://github.com/mayankchaudhari)
81132

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>

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ Note: We only accept pull requests addressing security vulnerabilities. Addition
2020

2121
## Reporting Vulnerabilities
2222

23-
Kindly report vulnerabilities [here](https://github.com/md2docx/md2docx-plugin-template/security/advisories/new).
23+
Kindly report vulnerabilities [here](https://github.com/md2docx/html/security/advisories/new).

TODO.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
- [ ] Install dependencies using `pnpm`
1313
- Run `pnpm i` to install dependencies
1414
- [ ] Make sure you run `pnpm rebrand` from the root directory to rebrand your repo.
15-
- [ ] 🌟 Enable [private vulnerability reporting]
15+
- [ ] 🌟 Enable [private vulnerability reporting](https://github.com/md2docx/html/security)
1616
- [ ] Set up `CodeCov`
1717
- Visit Codecov and set up your repo
18-
- Create [repository secret] for `CODECOV_TOKEN`
18+
- Create [repository secret]((https://github.com/md2docx/html/settings/secrets/actions)) for `CODECOV_TOKEN`
1919
- [ ] Set up `CodeClimate`
2020
- Visit CodeClimate and set up your repo
21-
- Create [repository secret] for `CC_TEST_REPORTER_ID`
21+
- Create [repository secret]((https://github.com/md2docx/html/settings/secrets/actions)) for `CC_TEST_REPORTER_ID`
2222
- Add `*.test.*` to ignore patterns on the website
2323
- Update Code Climate badge
2424
- [ ] Add `NPM_AUTH_TOKEN` to repository secrets to automate package publishing

examples/nextjs/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"dependencies": {
1515
"@m2d/core": "latest",
16-
"@m2d/emoji": "workspace:*",
16+
"@m2d/emoji": "latest",
1717
"@repo/shared": "workspace:*",
1818
"mdast2docx": "0.3.0",
1919
"next": "^15.2.3",
@@ -27,7 +27,8 @@
2727
"remark-math": "^6.0.0",
2828
"remark-parse": "^11.0.0",
2929
"unified": "^11.0.5",
30-
"webgl-generative-particles": "^0.0.1"
30+
"webgl-generative-particles": "^0.0.1",
31+
"@m2d/html": "workspace:*"
3132
},
3233
"devDependencies": {
3334
"@next/eslint-plugin-next": "^15.2.3",
@@ -38,4 +39,4 @@
3839
"@types/react-dom": "^19.0.4",
3940
"typescript": "^5.8.2"
4041
}
41-
}
42+
}

examples/vite/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"react18-loaders": "latest",
2121
"react18-themes": "^3.2.0",
2222
"@m2d/core": "latest",
23-
"@m2d/emoji": "workspace:*"
23+
"@m2d/emoji": "latest",
24+
"@m2d/html": "workspace:*"
2425
},
2526
"devDependencies": {
2627
"@repo/eslint-config": "workspace:*",
@@ -31,4 +32,4 @@
3132
"typescript": "^5.8.2",
3233
"vite": "^6.2.2"
3334
}
34-
}
35+
}

lib/CHANGELOG.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)