md2x 0.5.2 → 0.6.0

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 CHANGED
@@ -1,9 +1,119 @@
1
1
  # md2x
2
2
 
3
- Markdown → PDF/DOCX/HTML converter (local, no server). Supports Mermaid/Graphviz/Infographic/Vega/HTML/SVG rendering, math, and code highlighting.
3
+ Markdown → PDF/DOCX/HTML/Image converter (local, no server). Supports Mermaid/Graphviz/Infographic/Vega/HTML/SVG rendering, math, and code highlighting.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/md2x.svg?style=flat-square)](https://www.npmjs.com/package/md2x)
6
6
 
7
+ ## CLI Options
8
+
9
+ | Option | Alias | Description | Default | Values |
10
+ |--------|-------|-------------|---------|--------|
11
+ | `--help` | `-h` | Show help message | - | - |
12
+ | `--version` | `-v` | Show version number | - | - |
13
+ | `--output` | `-o` | Output file path | Input name with format extension | File path |
14
+ | `--format` | `-f` | Output format | `pdf` | `pdf`, `docx`, `html`, `png`, `jpg/jpeg`, `webp` |
15
+ | `--theme` | `-t` | Theme name | `default` | See `--list-themes` |
16
+ | `--diagram-mode` | - | HTML/Image diagram rendering mode | `live` | `img`, `live`, `none` |
17
+ | `--hr-page-break` | - | Convert horizontal rules to page breaks | `true` for PDF/DOCX, `false` for HTML/Image | `true`, `false` |
18
+ | `--list-themes` | - | List all available themes | - | - |
19
+
20
+ ### Diagram Modes (HTML/Image)
21
+
22
+ - **`live`** (default): Render diagrams in the browser on load using online CDN scripts (Mermaid, @viz-js/viz, Vega-Lite, Infographic)
23
+ - **`img`**: Pre-render diagrams as embedded images (offline, stable; no CDN)
24
+ - **`none`**: Keep diagram source blocks only (no rendering)
25
+
26
+ ## Front Matter Options
27
+
28
+ When converting a markdown **file**, you can put options in YAML front matter (the CLI merges front matter with CLI flags; explicit CLI flags win).
29
+
30
+ ### Common (All Formats)
31
+
32
+ ```yaml
33
+ ---
34
+ format: pdf # pdf | docx | html | png | jpg | jpeg | webp
35
+ theme: default
36
+ hrAsPageBreak: true
37
+ ---
38
+ ```
39
+
40
+ ### PDF
41
+
42
+ ```yaml
43
+ ---
44
+ format: pdf
45
+ title: "My Doc" # used for PDF metadata/header templates
46
+ pdf:
47
+ format: A4 # A4 | Letter | Legal | A3 | A5
48
+ landscape: false
49
+ margin:
50
+ top: 1cm
51
+ bottom: 1cm
52
+ left: 1cm
53
+ right: 1cm
54
+ printBackground: true
55
+ scale: 1
56
+ displayHeaderFooter: false
57
+ headerTemplate: "<div style='font-size:10px;width:100%;text-align:center;'><span class='title'></span></div>"
58
+ footerTemplate: "<div style='font-size:10px;width:100%;text-align:center;'>Page <span class='pageNumber'></span> / <span class='totalPages'></span></div>"
59
+ ---
60
+ ```
61
+
62
+ ### DOCX
63
+
64
+ ```yaml
65
+ ---
66
+ format: docx
67
+ theme: default
68
+ hrAsPageBreak: true
69
+ ---
70
+ ```
71
+
72
+ ### HTML
73
+
74
+ ```yaml
75
+ ---
76
+ format: html
77
+ title: "My Doc"
78
+ standalone: true # full HTML document (default)
79
+ baseTag: true # emit <base href="file://.../"> for resolving relative paths (default)
80
+ diagramMode: live # img | live | none
81
+ cdn: # optional: override CDN URLs (used when diagramMode: live)
82
+ mermaid: "https://cdn.jsdelivr.net/npm/mermaid@11.12.2/dist/mermaid.min.js"
83
+ ---
84
+ ```
85
+
86
+ ### Image (PNG/JPEG/WebP)
87
+
88
+ ```yaml
89
+ ---
90
+ format: png
91
+ diagramMode: live # or "img" for offline (no CDN)
92
+ image:
93
+ # selector can be a string or an array of selectors (CSS selector list).
94
+ selector:
95
+ - 'div.md2x-diagram[data-md2x-diagram-kind="mermaid"]'
96
+ - 'div.md2x-diagram[data-md2x-diagram-kind="infographic"]'
97
+ # selectorMode: first | each | union | stitch (default: stitch)
98
+ # - union: capture the union bounding box (includes in-between page content)
99
+ # - stitch: stack matched elements and capture only them (no in-between content)
100
+ selectorMode: stitch
101
+ selectorGap: 16 # optional: vertical gap (px) between stitched elements
102
+ selectorPadding: 8 # optional: padding (px) around the stitched region
103
+ split: auto # optional: split very tall output into multiple images
104
+ ---
105
+ ```
106
+
107
+ When `image.split` produces multiple parts, outputs are written as `output.part-001.png`, `output.part-002.png`, ...
108
+
109
+ Diagram blocks are tagged with `data-md2x-diagram-kind` so you can target specific types via selectors:
110
+
111
+ ```yaml
112
+ image:
113
+ selector: 'div.md2x-diagram[data-md2x-diagram-kind="mermaid"]'
114
+ selectorMode: stitch
115
+ ```
116
+
7
117
  ## Usage
8
118
 
9
119
  Export to PDF:
@@ -23,21 +133,10 @@ Export to HTML:
23
133
  npx md2x input.md -f html
24
134
  ```
25
135
 
26
- HTML diagram modes:
136
+ Export to PNG:
27
137
 
28
138
  ```bash
29
- # Render diagrams in the browser on load (default)
30
- # - uses online CDN scripts (Mermaid/@viz-js/viz/Vega-Lite/Infographic)
31
- npx md2x input.md -f html --diagram-mode live
32
-
33
- # Pre-render diagrams as embedded images (offline, stable)
34
- npx md2x input.md -f html --diagram-mode img
35
-
36
- # Render diagrams in the browser on load (keeps source blocks)
37
- # Tip: Vega-Lite CDN major version is auto-selected from the spec $schema (v5 or v6).
38
-
39
- # Keep diagram source blocks only (no rendering)
40
- npx md2x input.md -f html --diagram-mode none
139
+ npx md2x input.md -f png -o output.png
41
140
  ```
42
141
 
43
142
  List themes:
@@ -58,6 +157,34 @@ Help:
58
157
  npx md2x -h
59
158
  ```
60
159
 
160
+ ## MCP server (Model Context Protocol)
161
+
162
+ 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
+
164
+ Run:
165
+
166
+ ```bash
167
+ pnpm -C mcp install
168
+ pnpm -C mcp start
169
+ ```
170
+
171
+ Endpoints:
172
+
173
+ - Streamable HTTP (recommended): `POST/GET/DELETE /mcp`
174
+ - Legacy HTTP+SSE: `GET /sse` and `POST /messages?sessionId=...`
175
+ - Resources (static files): `GET /resources/*`
176
+
177
+ Tools:
178
+
179
+ - `markdown_to_html` / `markdown_to_pdf` / `markdown_to_docx` - Convert Markdown to HTML/PDF/DOCX
180
+ - `markdown_convert` - Auto convert via `md2x.convert()` (front matter supported)
181
+ - `resources_upload` - Upload a file to `/resources` (e.g. images referenced by Markdown)
182
+
183
+ Notes:
184
+
185
+ - The conversion tools return an MCP `resource_link` pointing to the generated file URL.
186
+ - Config: `PORT` (default `3000`) and `MD2X_BASE_URL` (used to build the public `/resources` URL). See `mcp/README.md`.
187
+
61
188
  ## Puppeteer / Chrome install
62
189
 
63
190
  This package depends on `puppeteer`. On first install, Puppeteer downloads a compatible "Chrome for Testing" build (cached under your user directory). Set `PUPPETEER_SKIP_DOWNLOAD=1` to skip download and use a system Chrome via `PUPPETEER_EXECUTABLE_PATH`.