md2x 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +115 -2
- package/dist/chunks/chunk-A4XDJ35P.js +1222 -0
- package/dist/chunks/{chunk-5DRL26RK.js → chunk-EFKQH5UR.js} +23 -23
- package/dist/chunks/{docx-exporter-FGXU5MTK.js → docx-exporter-ZZ76JXFU.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/md2x.js +6 -5
- package/dist/renderer/puppeteer-render-worker.js +97 -90
- package/dist/templates/html/example.html +35 -0
- package/dist/templates/svelte/example.svelte +18 -0
- package/dist/templates/vue/PrinterComponent.vue +875 -0
- package/dist/templates/vue/example.vue +17 -0
- package/dist/types/node/src/host/index.d.ts +3 -1
- package/dist/types/node/src/host/node-exporter.d.ts +47 -34
- package/dist/types/src/plugins/md2x-plugin.d.ts +9 -0
- package/package.json +1 -1
- package/dist/chunks/chunk-T2OSWHM4.js +0 -728
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# md2x
|
|
2
2
|
|
|
3
|
-
Markdown → PDF/DOCX/HTML/Image converter (local, no server). Supports Mermaid/Graphviz/Infographic/Vega/
|
|
3
|
+
Markdown → PDF/DOCX/HTML/Image converter (local, no server). Supports Mermaid/Graphviz/Infographic/Vega/Template(vue/svelte/html) rendering, math, and code highlighting.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/md2x)
|
|
6
6
|
|
|
@@ -15,6 +15,7 @@ Markdown → PDF/DOCX/HTML/Image converter (local, no server). Supports Mermaid/
|
|
|
15
15
|
| `--theme` | `-t` | Theme name | `default` | See `--list-themes` |
|
|
16
16
|
| `--diagram-mode` | - | HTML/Image diagram rendering mode | `live` | `img`, `live`, `none` |
|
|
17
17
|
| `--hr-page-break` | - | Convert horizontal rules to page breaks | `true` for PDF/DOCX, `false` for HTML/Image | `true`, `false` |
|
|
18
|
+
| `--templates-dir` | - | Extra template dir for md2x blocks (repeatable; resolved against input dir when relative) | - | Directory path |
|
|
18
19
|
| `--list-themes` | - | List all available themes | - | - |
|
|
19
20
|
|
|
20
21
|
### Diagram Modes (HTML/Image)
|
|
@@ -80,6 +81,11 @@ baseTag: true # emit <base href="file://.../"> for resolving relative path
|
|
|
80
81
|
diagramMode: live # img | live | none
|
|
81
82
|
cdn: # optional: override CDN URLs (used when diagramMode: live)
|
|
82
83
|
mermaid: "https://cdn.jsdelivr.net/npm/mermaid@11.12.2/dist/mermaid.min.js"
|
|
84
|
+
# Template blocks:
|
|
85
|
+
vue: "https://unpkg.com/vue@3/dist/vue.global.js"
|
|
86
|
+
vueSfcLoader: "https://cdn.jsdelivr.net/npm/vue3-sfc-loader/dist/vue3-sfc-loader.js"
|
|
87
|
+
svelteCompiler: "https://esm.sh/svelte@5/compiler"
|
|
88
|
+
svelteBase: "https://esm.sh/svelte@5/"
|
|
83
89
|
---
|
|
84
90
|
```
|
|
85
91
|
|
|
@@ -114,6 +120,96 @@ image:
|
|
|
114
120
|
selectorMode: stitch
|
|
115
121
|
```
|
|
116
122
|
|
|
123
|
+
## md2x Template Blocks
|
|
124
|
+
|
|
125
|
+
Besides diagram blocks (mermaid/dot/vega-lite/infographic), `md2x` also supports template blocks via:
|
|
126
|
+
|
|
127
|
+
````md
|
|
128
|
+
```md2x
|
|
129
|
+
{
|
|
130
|
+
type: 'vue', // "vue" | "html" | "svelte"
|
|
131
|
+
template: 'example.vue', // or "example.html" / "example.svelte"
|
|
132
|
+
data: [{ title: 't', message: 'm' }]
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
````
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
//example.vue
|
|
139
|
+
<script setup>
|
|
140
|
+
const data = templateData;
|
|
141
|
+
</script>
|
|
142
|
+
|
|
143
|
+
<template>
|
|
144
|
+
<div class="my-component">Hello md2x! This is vue template</div>
|
|
145
|
+
<div v-for="(item, index) in data" :key="index">
|
|
146
|
+
<h2>{{ item.title }}</h2>
|
|
147
|
+
<p>{{ item.message }}</p>
|
|
148
|
+
</div>
|
|
149
|
+
</template>
|
|
150
|
+
|
|
151
|
+
<style scoped>
|
|
152
|
+
.my-component {
|
|
153
|
+
color: red;
|
|
154
|
+
}
|
|
155
|
+
</style>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
```svelte
|
|
159
|
+
<!-- example.svelte (Svelte 5) -->
|
|
160
|
+
<script>
|
|
161
|
+
const data = templateData;
|
|
162
|
+
</script>
|
|
163
|
+
|
|
164
|
+
<div class="my-component">Hello md2x! This is svelte template</div>
|
|
165
|
+
{#each data as item, index}
|
|
166
|
+
<div>
|
|
167
|
+
<h2>{item.title}</h2>
|
|
168
|
+
<p>{item.message}</p>
|
|
169
|
+
</div>
|
|
170
|
+
{/each}
|
|
171
|
+
|
|
172
|
+
<style>
|
|
173
|
+
.my-component { color: red; }
|
|
174
|
+
</style>
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Config Fields
|
|
178
|
+
|
|
179
|
+
- `type`: `"vue"`, `"html"`, or `"svelte"` (Svelte 5)
|
|
180
|
+
- `template`: template file name/path
|
|
181
|
+
- if you only pass a filename (e.g. `example.vue`), it is treated as `${type}/${template}` (e.g. `vue/example.vue`)
|
|
182
|
+
- `data`: arbitrary JSON-serializable data (injected by replacing the `templateData` placeholder)
|
|
183
|
+
- `allowScripts` (optional, **unsafe**, html only): when exporting **images** in `diagramMode: "img"`, set `allowScripts: true` to execute inline `<script>` blocks before rendering to PNG.
|
|
184
|
+
- not supported: `<script type="module">`
|
|
185
|
+
- external `<script src="...">` is not supported for image rendering (use inline scripts)
|
|
186
|
+
|
|
187
|
+
### Svelte Notes (Svelte 5 + esm.sh)
|
|
188
|
+
|
|
189
|
+
- Svelte templates are compiled at runtime using the Svelte compiler, loaded from **esm.sh** via `import()`.
|
|
190
|
+
- This means Svelte template rendering requires network access (even in `diagramMode: "img"`), unless you override `cdn.svelteCompiler`/`cdn.svelteBase` to another ESM CDN that works in your environment.
|
|
191
|
+
- Templates are expected to be self-contained `.svelte` files (no preprocessors like TypeScript/Sass, and avoid local relative imports unless you provide an ESM-resolvable URL).
|
|
192
|
+
|
|
193
|
+
### Template Resolution (External Templates)
|
|
194
|
+
|
|
195
|
+
To load templates from outside the built-in `dist/templates`, use either:
|
|
196
|
+
|
|
197
|
+
- CLI: `--templates-dir /path/to/templates` (repeatable)
|
|
198
|
+
- Front matter: `templatesDir: /path/to/templates` (string or list)
|
|
199
|
+
|
|
200
|
+
### CDN Overrides (Live Mode)
|
|
201
|
+
|
|
202
|
+
When exporting **HTML/Image** with `diagramMode: live`, you can override CDN URLs in front matter:
|
|
203
|
+
|
|
204
|
+
```yaml
|
|
205
|
+
cdn:
|
|
206
|
+
vue: "https://unpkg.com/vue@3/dist/vue.global.js"
|
|
207
|
+
vueSfcLoader: "https://cdn.jsdelivr.net/npm/vue3-sfc-loader/dist/vue3-sfc-loader.js"
|
|
208
|
+
svelteCompiler: "https://esm.sh/svelte@5/compiler"
|
|
209
|
+
svelteBase: "https://esm.sh/svelte@5/"
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
|
|
117
213
|
## Usage
|
|
118
214
|
|
|
119
215
|
Export to PDF:
|
|
@@ -161,6 +257,22 @@ npx md2x -h
|
|
|
161
257
|
|
|
162
258
|
This repo includes an Express-based MCP server that exposes `md2x` as MCP tools over HTTP, so MCP clients can convert Markdown and download the generated HTML/PDF/DOCX from `/resources`.
|
|
163
259
|
|
|
260
|
+
## md2x Skill
|
|
261
|
+
|
|
262
|
+
This repo also includes a skill for driving `md2x` from an agent:
|
|
263
|
+
|
|
264
|
+
- Skill: `skills/md2x/SKILL.md`
|
|
265
|
+
- What it does: guides an agent to run `npx md2x ...`, pick formats/themes, and use front matter correctly.
|
|
266
|
+
- Install (example):
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
npx skills add larchliu/md2x
|
|
270
|
+
|
|
271
|
+
or
|
|
272
|
+
|
|
273
|
+
npx add-skill larchliu/md2x
|
|
274
|
+
```
|
|
275
|
+
|
|
164
276
|
Run:
|
|
165
277
|
|
|
166
278
|
```bash
|
|
@@ -177,7 +289,8 @@ Endpoints:
|
|
|
177
289
|
Tools:
|
|
178
290
|
|
|
179
291
|
- `markdown_to_html` / `markdown_to_pdf` / `markdown_to_docx` - Convert Markdown to HTML/PDF/DOCX
|
|
180
|
-
- `
|
|
292
|
+
- `markdown_to_image` - Convert Markdown to an image (`png`/`jpg`/`jpeg`/`webp`), may return multiple parts for very tall pages
|
|
293
|
+
- `markdown_convert` - Auto convert via `md2x.convert()` (front matter supported; includes image formats)
|
|
181
294
|
- `resources_upload` - Upload a file to `/resources` (e.g. images referenced by Markdown)
|
|
182
295
|
|
|
183
296
|
Notes:
|