@masumdev/markforge 0.2.4 β 0.2.5
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 +203 -302
- package/dist/{App-IJVCGBJM.mjs β App-GNRUPFM7.mjs} +899 -323
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +309 -62
- package/dist/index.d.ts +309 -62
- package/dist/index.js +1149 -483
- package/dist/index.mjs +1137 -484
- package/package.json +1 -1
- package/schema.json +198 -36
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
# @masumdev/markforge
|
|
4
4
|
|
|
5
|
-
**
|
|
6
|
-
Convert Markdown into pixel-perfect **DOCX**, **PDF**, and **HTML** with syntax highlighting, Mermaid diagrams, callout boxes, and
|
|
5
|
+
**Enterprise Markdown & MDX Multi-Format Publishing Engine & CLI.**
|
|
6
|
+
Convert Markdown into pixel-perfect **DOCX**, **PDF**, and **HTML** with native typography, syntax highlighting, Mermaid diagrams, callout boxes, customizable `ThemeProps`, and an interactive Ink terminal UI.
|
|
7
7
|
|
|
8
8
|
[](https://www.npmjs.com/package/@masumdev/markforge)
|
|
9
9
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -18,381 +18,282 @@ Convert Markdown into pixel-perfect **DOCX**, **PDF**, and **HTML** with syntax
|
|
|
18
18
|
|
|
19
19
|
| Feature | Description |
|
|
20
20
|
| :--- | :--- |
|
|
21
|
-
| π **Multi-Format Output** | Generate `.docx`, `.pdf`, and `.html` from a single Markdown source |
|
|
22
|
-
| π¨ **
|
|
23
|
-
|
|
|
24
|
-
|
|
|
25
|
-
|
|
|
26
|
-
|
|
|
27
|
-
|
|
|
28
|
-
|
|
|
29
|
-
| π§ **Watermark
|
|
30
|
-
| βοΈ **Type-Safe Config** | `markforge.config.ts
|
|
31
|
-
| π **Programmatic API** |
|
|
32
|
-
| π₯οΈ **Ink Terminal UI** |
|
|
21
|
+
| π **Multi-Format Output** | Generate `.docx`, `.pdf`, and `.html` from a single Markdown source simultaneously |
|
|
22
|
+
| π¨ **Theme.CORPORATE & ThemeProps** | Flagship cyan corporate design system + full custom colors & fonts via `ThemeProps` |
|
|
23
|
+
| π **Per-Zone Header & Footer** | Granular color, font size, font family, bold & italic controls per `left`, `center`, `right` slot |
|
|
24
|
+
| π **Mermaid Diagrams** | Full Mermaid.js diagram engine β flowcharts, sequence, state, class, gantt |
|
|
25
|
+
| π’ **Callout / Alert Boxes** | GitHub-style `> [!NOTE]`, `> [!TIP]`, `> [!IMPORTANT]`, `> [!WARNING]`, `> [!CAUTION]` |
|
|
26
|
+
| π **Syntax Highlighting** | Tokenized multi-language code blocks (`dracula`, `github-dark`, `monokai`, `nord`, etc.) |
|
|
27
|
+
| πΌοΈ **Image Inlining Engine** | Resolves local files, remote URLs, Base64 data URIs, and SVGs into embedded assets |
|
|
28
|
+
| π **Auto Table of Contents** | Anchored TOC generated from heading structure (`#` to `####`) |
|
|
29
|
+
| π§ **Non-Intrusive Watermark** | Background-layer watermark with custom text, color, opacity, rotation, and position |
|
|
30
|
+
| βοΈ **Type-Safe Config** | `markforge.config.ts` with Enums, `.markforgerc.json`, or YAML with JSON Schema |
|
|
31
|
+
| π **Programmatic API** | High-level `compileMarkdown()` and low-level AST document builders for Node.js & Bun |
|
|
32
|
+
| π₯οΈ **Ink Terminal UI** | Interactive TUI with live spinners, progress tracking, and compilation metrics |
|
|
33
33
|
|
|
34
34
|
---
|
|
35
35
|
|
|
36
36
|
## π¦ Installation
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
|
-
# Global CLI
|
|
39
|
+
# Global CLI Installation
|
|
40
40
|
npm install -g @masumdev/markforge
|
|
41
|
+
# or with bun:
|
|
41
42
|
bun add -g @masumdev/markforge
|
|
42
43
|
|
|
43
|
-
#
|
|
44
|
+
# Project Local Dependency
|
|
44
45
|
npm install -D @masumdev/markforge
|
|
46
|
+
# or with bun:
|
|
45
47
|
bun add -d @masumdev/markforge
|
|
46
48
|
```
|
|
47
49
|
|
|
48
50
|
---
|
|
49
51
|
|
|
50
|
-
##
|
|
52
|
+
## π» CLI Usage
|
|
51
53
|
|
|
52
54
|
```bash
|
|
53
|
-
#
|
|
55
|
+
# Basic conversion to DOCX and PDF (defaults)
|
|
54
56
|
markforge document.md
|
|
55
57
|
|
|
56
|
-
# Specify output
|
|
58
|
+
# Specify target formats and output folder
|
|
57
59
|
markforge document.md --to docx,pdf,html -o ./dist
|
|
58
60
|
|
|
59
|
-
# Use
|
|
60
|
-
markforge
|
|
61
|
+
# Use custom CSS styling and force Table of Contents
|
|
62
|
+
markforge specification.md --css ./styles/custom.css --toc
|
|
61
63
|
|
|
62
|
-
#
|
|
63
|
-
markforge
|
|
64
|
+
# Watch mode for live re-compilation
|
|
65
|
+
markforge report.md --watch
|
|
64
66
|
|
|
65
|
-
#
|
|
66
|
-
markforge document.md --
|
|
67
|
+
# Launch local preview server and open in browser
|
|
68
|
+
markforge document.md --serve --port 4000 --open
|
|
67
69
|
```
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
## ποΈ Markdown Source Features
|
|
72
|
-
|
|
73
|
-
### Callout / Alert Boxes
|
|
74
|
-
|
|
75
|
-
MarkForge supports GitHub-style alert syntax with full color-coded styling in all output formats:
|
|
76
|
-
|
|
77
|
-
```markdown
|
|
78
|
-
> [!NOTE]
|
|
79
|
-
> This is a note β rendered with cyan left border.
|
|
80
|
-
|
|
81
|
-
> [!TIP]
|
|
82
|
-
> This is a tip β rendered with green styling.
|
|
83
|
-
|
|
84
|
-
> [!IMPORTANT]
|
|
85
|
-
> Critical information β rendered with purple styling.
|
|
86
|
-
|
|
87
|
-
> [!WARNING]
|
|
88
|
-
> A warning β rendered with amber/yellow styling.
|
|
89
|
-
|
|
90
|
-
> [!CAUTION]
|
|
91
|
-
> High-risk action β rendered with red styling.
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### Mermaid Diagrams
|
|
95
|
-
|
|
96
|
-
Mermaid code blocks are automatically rendered into images embedded in all output formats:
|
|
97
|
-
|
|
98
|
-
````markdown
|
|
99
|
-
```mermaid
|
|
100
|
-
flowchart LR
|
|
101
|
-
A[Markdown Source] --> B[AST Parser]
|
|
102
|
-
B --> C[DOCX Builder]
|
|
103
|
-
B --> D[PDF Builder]
|
|
104
|
-
B --> E[HTML Builder]
|
|
105
|
-
```
|
|
106
|
-
````
|
|
107
|
-
|
|
108
|
-
### Syntax-Highlighted Code Blocks
|
|
109
|
-
|
|
110
|
-
All common languages are supported with proper token coloring:
|
|
111
|
-
|
|
112
|
-
````markdown
|
|
113
|
-
```typescript
|
|
114
|
-
import { markforge } from "@masumdev/markforge";
|
|
115
|
-
|
|
116
|
-
const result = await markforge("./spec.md", { to: ["pdf", "docx"] });
|
|
117
|
-
```
|
|
118
|
-
````
|
|
119
|
-
|
|
120
|
-
**Dual-theme coloring:**
|
|
121
|
-
- **PDF / HTML**: VS Code Dark+ palette (bright colors on dark background)
|
|
122
|
-
- **DOCX**: GitHub Light palette (deep colors on white background)
|
|
71
|
+
### CLI Flags Reference
|
|
123
72
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
subtitle: "Cloud & Edge Infrastructure β Q3 2026"
|
|
144
|
-
author: "Ma'sum"
|
|
145
|
-
version: "2.4.0"
|
|
146
|
-
date: "2026-08-27"
|
|
147
|
-
theme: "default" # default | academic | github | corporate | minimal | dracula
|
|
148
|
-
toc: true # auto-generate Table of Contents
|
|
149
|
-
orientation: "portrait" # portrait | landscape
|
|
150
|
-
paperSize: "A4" # A4 | letter | legal
|
|
151
|
-
watermark:
|
|
152
|
-
enabled: false # no watermark by default
|
|
153
|
-
text: "CONFIDENTIAL"
|
|
154
|
-
opacity: 0.08
|
|
155
|
-
position: "diagonal" # diagonal | center | top-left | top-right | bottom-left | bottom-right
|
|
156
|
-
header:
|
|
157
|
-
left: "My Company"
|
|
158
|
-
center: "{title}"
|
|
159
|
-
right: "Version {version}"
|
|
160
|
-
footer:
|
|
161
|
-
left: "Confidential"
|
|
162
|
-
right: "Page {page} of {pages}"
|
|
163
|
-
---
|
|
164
|
-
```
|
|
73
|
+
| Flag | Alias | Description | Default |
|
|
74
|
+
| :--- | :---: | :--- | :--- |
|
|
75
|
+
| `<file>` | | Markdown input file path | **Required** |
|
|
76
|
+
| `--to <formats...>` | `-t` | Output formats: `docx`, `pdf`, `html`, `png` | `docx,pdf` |
|
|
77
|
+
| `--output <dir>` | `-o` | Output directory | Same as input file |
|
|
78
|
+
| `--config <file>` | `-c` | Explicit configuration file path | Auto-discovered |
|
|
79
|
+
| `--theme <name>` | | Visual theme preset (`corporate`, `default`) | `corporate` |
|
|
80
|
+
| `--css <files...>` | | Custom CSS stylesheets to inject | `undefined` |
|
|
81
|
+
| `--orientation <type>` | | Page orientation (`portrait`, `landscape`) | `portrait` |
|
|
82
|
+
| `--paper-size <size>` | | Standard paper size (`A4`, `Letter`, `Legal`, `A3`, `A5`) | `A4` |
|
|
83
|
+
| `--toc` | | Force Table of Contents generation | `false` |
|
|
84
|
+
| `--watermark <text>` | | Document watermark text | `undefined` |
|
|
85
|
+
| `--syntax-theme <theme>`| | Code syntax highlighting theme | `github-dark` |
|
|
86
|
+
| `--watch` | `-w` | Watch input file and re-compile on change | `false` |
|
|
87
|
+
| `--serve` | | Start local HTTP preview server | `false` |
|
|
88
|
+
| `--port <number>` | `-p` | Local preview server port | `4000` |
|
|
89
|
+
| `--open` | | Automatically open browser on preview | `false` |
|
|
90
|
+
| `--version` | `-V` | Output version number | |
|
|
91
|
+
| `--help` | `-h` | Display CLI help menu | |
|
|
165
92
|
|
|
166
93
|
---
|
|
167
94
|
|
|
168
|
-
## βοΈ Configuration
|
|
95
|
+
## βοΈ Configuration (`markforge.config.ts`)
|
|
169
96
|
|
|
170
|
-
MarkForge
|
|
171
|
-
|
|
172
|
-
### 1. TypeScript (`markforge.config.ts`)
|
|
97
|
+
MarkForge supports type-safe configuration with full TypeScript Enums:
|
|
173
98
|
|
|
174
99
|
```typescript
|
|
175
|
-
import {
|
|
100
|
+
import {
|
|
101
|
+
defineConfig,
|
|
102
|
+
OutputFormat,
|
|
103
|
+
Theme,
|
|
104
|
+
Orientation,
|
|
105
|
+
PaperSizeEnum,
|
|
106
|
+
SyntaxTheme,
|
|
107
|
+
WatermarkPosition,
|
|
108
|
+
} from "@masumdev/markforge";
|
|
176
109
|
|
|
177
110
|
export default defineConfig({
|
|
178
|
-
//
|
|
179
|
-
to: [
|
|
180
|
-
|
|
111
|
+
// Target output formats
|
|
112
|
+
to: [OutputFormat.DOCX, OutputFormat.PDF, OutputFormat.HTML],
|
|
113
|
+
|
|
114
|
+
// Output destination directory
|
|
115
|
+
outputDir: ".temp/output-docs",
|
|
181
116
|
|
|
182
|
-
//
|
|
183
|
-
theme:
|
|
117
|
+
// Visual document theme (Theme.CORPORATE preset or a custom ThemeProps object)
|
|
118
|
+
theme: Theme.CORPORATE,
|
|
184
119
|
|
|
185
|
-
//
|
|
186
|
-
|
|
120
|
+
// Page orientation & standard physical paper size
|
|
121
|
+
orientation: Orientation.PORTRAIT,
|
|
122
|
+
paperSize: PaperSizeEnum.A4,
|
|
187
123
|
|
|
188
|
-
//
|
|
189
|
-
orientation: "portrait", // "portrait" | "landscape"
|
|
190
|
-
paperSize: "A4", // "A4" | "Letter" | "Legal" | "A3" | "A5"
|
|
124
|
+
// Document page margins
|
|
191
125
|
margins: {
|
|
192
|
-
top: "
|
|
126
|
+
top: "3cm",
|
|
193
127
|
bottom: "2.5cm",
|
|
194
|
-
left: "
|
|
195
|
-
right: "
|
|
128
|
+
left: "2.5cm",
|
|
129
|
+
right: "2.5cm",
|
|
196
130
|
},
|
|
197
131
|
|
|
198
|
-
//
|
|
132
|
+
// Running headers with dynamic tokens & per-zone slot styling
|
|
199
133
|
header: {
|
|
200
|
-
left:
|
|
201
|
-
|
|
202
|
-
|
|
134
|
+
left: {
|
|
135
|
+
text: "{company} - {title}",
|
|
136
|
+
color: "#0D998D",
|
|
137
|
+
fontSize: 9,
|
|
138
|
+
fontFamily: "Inter, Segoe UI, sans-serif",
|
|
139
|
+
bold: true,
|
|
140
|
+
},
|
|
141
|
+
center: "Internal Technical Guide",
|
|
142
|
+
right: {
|
|
143
|
+
text: "v{version}",
|
|
144
|
+
color: "#94A3B8",
|
|
145
|
+
fontSize: 8.5,
|
|
146
|
+
italic: true,
|
|
147
|
+
},
|
|
148
|
+
divider: true,
|
|
149
|
+
dividerColor: "#CBD5E1",
|
|
203
150
|
},
|
|
151
|
+
|
|
152
|
+
// Running footers with dynamic page numbering & per-zone slot styling
|
|
204
153
|
footer: {
|
|
205
|
-
left:
|
|
206
|
-
|
|
154
|
+
left: {
|
|
155
|
+
text: "Author: {author}",
|
|
156
|
+
color: "#64748B",
|
|
157
|
+
fontSize: 8.5,
|
|
158
|
+
},
|
|
159
|
+
center: {
|
|
160
|
+
text: "{date}",
|
|
161
|
+
color: "#94A3B8",
|
|
162
|
+
fontSize: 8.5,
|
|
163
|
+
italic: true,
|
|
164
|
+
},
|
|
165
|
+
right: {
|
|
166
|
+
text: "Page {page} of {pages}",
|
|
167
|
+
color: "#0D998D",
|
|
168
|
+
fontSize: 9,
|
|
169
|
+
bold: true,
|
|
170
|
+
},
|
|
171
|
+
divider: true,
|
|
172
|
+
dividerColor: "#CBD5E1",
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
// Automatic Table of Contents
|
|
176
|
+
toc: true,
|
|
177
|
+
|
|
178
|
+
// Watermark configuration (placed at lowest background layer)
|
|
179
|
+
watermark: {
|
|
180
|
+
text: "CONFIDENTIAL DRAFT",
|
|
181
|
+
color: "#E11D48",
|
|
182
|
+
opacity: 0.1,
|
|
183
|
+
fontSize: 52,
|
|
184
|
+
rotate: -45,
|
|
185
|
+
position: WatermarkPosition.DIAGONAL,
|
|
207
186
|
},
|
|
208
187
|
|
|
209
|
-
//
|
|
210
|
-
|
|
211
|
-
embedImages: true, // Embed/inline all images as Base64 data URIs
|
|
212
|
-
bundleHtml: true, // Self-contained HTML with embedded styles and scripts
|
|
213
|
-
syntaxTheme: "github-dark", // "github-dark" | "github-light" | "dracula" | "monokai" | "nord"
|
|
188
|
+
// Syntax highlighting theme
|
|
189
|
+
syntaxTheme: SyntaxTheme.DRACULA,
|
|
214
190
|
|
|
215
|
-
//
|
|
216
|
-
|
|
191
|
+
// Asset embedding & bundling flags
|
|
192
|
+
embedImages: true,
|
|
193
|
+
bundleHtml: true,
|
|
217
194
|
|
|
218
|
-
//
|
|
195
|
+
// Global document metadata
|
|
219
196
|
metadata: {
|
|
220
|
-
title: "
|
|
221
|
-
|
|
197
|
+
title: "Unified Platform Architecture & Document Suite",
|
|
198
|
+
subtitle: "Enterprise Specification & Feature Validation Guide",
|
|
199
|
+
author: "Masum RPG",
|
|
200
|
+
company: "Masum Dev Technologies",
|
|
222
201
|
version: "1.0.0",
|
|
223
|
-
|
|
202
|
+
date: "2026-08-29",
|
|
203
|
+
lang: "en",
|
|
224
204
|
},
|
|
225
|
-
|
|
226
|
-
// Server & watch options
|
|
227
|
-
watch: false,
|
|
228
|
-
serve: false,
|
|
229
|
-
port: 4000,
|
|
230
|
-
open: false,
|
|
231
205
|
});
|
|
232
206
|
```
|
|
233
207
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
Adding `$schema` enables **instant autocompletion and validation** in VS Code, WebStorm, and other IDEs:
|
|
237
|
-
|
|
238
|
-
```json
|
|
239
|
-
{
|
|
240
|
-
"$schema": "https://raw.githubusercontent.com/masumdev/react-native-library/main/packages/markforge/schema.json",
|
|
241
|
-
"to": ["docx", "pdf", "html"],
|
|
242
|
-
"outputDir": "./dist/documents",
|
|
243
|
-
"theme": "academic",
|
|
244
|
-
"orientation": "portrait",
|
|
245
|
-
"paperSize": "A4",
|
|
246
|
-
"margins": {
|
|
247
|
-
"top": "2.5cm",
|
|
248
|
-
"bottom": "2.5cm",
|
|
249
|
-
"left": "3cm",
|
|
250
|
-
"right": "3cm"
|
|
251
|
-
},
|
|
252
|
-
"header": {
|
|
253
|
-
"left": "Enterprise Architecture",
|
|
254
|
-
"right": "{title}"
|
|
255
|
-
},
|
|
256
|
-
"footer": {
|
|
257
|
-
"left": "Confidential",
|
|
258
|
-
"right": "Page {page} of {pages}"
|
|
259
|
-
},
|
|
260
|
-
"toc": true,
|
|
261
|
-
"embedImages": true,
|
|
262
|
-
"syntaxTheme": "github-dark",
|
|
263
|
-
"watermark": "CONFIDENTIAL"
|
|
264
|
-
}
|
|
265
|
-
```
|
|
208
|
+
---
|
|
266
209
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
```yaml
|
|
270
|
-
to:
|
|
271
|
-
- docx
|
|
272
|
-
- pdf
|
|
273
|
-
- html
|
|
274
|
-
outputDir: ./dist/documents
|
|
275
|
-
theme: academic
|
|
276
|
-
orientation: portrait
|
|
277
|
-
paperSize: A4
|
|
278
|
-
margins:
|
|
279
|
-
top: 2.5cm
|
|
280
|
-
bottom: 2.5cm
|
|
281
|
-
left: 3cm
|
|
282
|
-
right: 3cm
|
|
283
|
-
header:
|
|
284
|
-
left: Enterprise Architecture
|
|
285
|
-
right: "{title}"
|
|
286
|
-
footer:
|
|
287
|
-
left: Confidential
|
|
288
|
-
right: "Page {page} of {pages}"
|
|
289
|
-
toc: true
|
|
290
|
-
embedImages: true
|
|
291
|
-
watermark: CONFIDENTIAL
|
|
292
|
-
```
|
|
210
|
+
## π¨ Custom Theme Customization (`ThemeProps`)
|
|
293
211
|
|
|
212
|
+
You can completely rebrand all document styling by passing a `ThemeProps` object:
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
import { defineConfig } from "@masumdev/markforge";
|
|
216
|
+
|
|
217
|
+
export default defineConfig({
|
|
218
|
+
theme: {
|
|
219
|
+
primaryColor: "#0D998D",
|
|
220
|
+
primaryDark: "#008073",
|
|
221
|
+
primaryLight: "#D9F1F0",
|
|
222
|
+
backgroundColor: "#0F172A",
|
|
223
|
+
textColor: "#E2E8F0",
|
|
224
|
+
textMuted: "#94A3B8",
|
|
225
|
+
borderColor: "#334155",
|
|
226
|
+
cardBackground: "#1E293B",
|
|
227
|
+
codeBackground: "#020617",
|
|
228
|
+
codeText: "#E2E8F0",
|
|
229
|
+
fontFamily: "'Inter', sans-serif",
|
|
230
|
+
fontMono: "'Fira Code', monospace",
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
```
|
|
294
234
|
|
|
295
235
|
---
|
|
296
236
|
|
|
297
|
-
##
|
|
237
|
+
## π Programmatic API
|
|
238
|
+
|
|
239
|
+
### High-Level API (`compileMarkdown` / `markforge`)
|
|
298
240
|
|
|
299
241
|
```typescript
|
|
300
|
-
import {
|
|
242
|
+
import { compileMarkdown, OutputFormat } from "@masumdev/markforge";
|
|
301
243
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
to: ["docx", "pdf", "html"],
|
|
244
|
+
const result = await compileMarkdown("./specification.md", {
|
|
245
|
+
to: [OutputFormat.DOCX, OutputFormat.PDF, OutputFormat.HTML],
|
|
305
246
|
outputDir: "./dist",
|
|
306
|
-
|
|
247
|
+
toc: true,
|
|
307
248
|
metadata: {
|
|
308
|
-
title: "
|
|
309
|
-
author: "
|
|
310
|
-
version: "
|
|
249
|
+
title: "API Reference Manual",
|
|
250
|
+
author: "Masum Dev",
|
|
251
|
+
version: "1.0.0",
|
|
311
252
|
},
|
|
312
253
|
});
|
|
313
254
|
|
|
314
|
-
console.log(`β
|
|
315
|
-
|
|
255
|
+
console.log(`β Compiled ${result.files.length} documents in ${result.durationMs}ms:`);
|
|
316
256
|
for (const file of result.files) {
|
|
317
|
-
console.log(` [${file.format.toUpperCase()}] ${file.filePath}
|
|
257
|
+
console.log(` [${file.format.toUpperCase()}] ${file.filePath} (${file.sizeBytes} bytes)`);
|
|
318
258
|
}
|
|
319
259
|
```
|
|
320
260
|
|
|
321
|
-
|
|
322
|
-
import { compileMarkdown, buildPdfDocument, buildDocxDocument, buildHtmlDocument } from "@masumdev/markforge";
|
|
323
|
-
|
|
324
|
-
// Low-level: parse β build each format independently
|
|
325
|
-
const parsed = await compileMarkdown("./report.md");
|
|
326
|
-
|
|
327
|
-
const pdfBuffer = await buildPdfDocument(parsed.doc, parsed.config, parsed.baseDir);
|
|
328
|
-
const docxBuffer = await buildDocxDocument(parsed.doc, parsed.config, parsed.baseDir);
|
|
329
|
-
const htmlString = await buildHtmlDocument(parsed.doc, parsed.config, parsed.baseDir);
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
---
|
|
333
|
-
|
|
334
|
-
## π¨ Built-in Themes
|
|
335
|
-
|
|
336
|
-
| Theme | Description | Best For |
|
|
337
|
-
| :--- | :--- | :--- |
|
|
338
|
-
| `default` | Blu by BCA Digital cyan palette, modern sans-serif | Tech docs, specifications |
|
|
339
|
-
| `academic` | Serif typography (Merriweather/Georgia), justified text | Papers, reports, theses |
|
|
340
|
-
| `github` | GitHub Markdown rendering style | READMEs, open-source docs |
|
|
341
|
-
| `corporate` | Clean professional layout | Business documents |
|
|
342
|
-
| `minimal` | Minimal whitespace-focused design | Simple notes |
|
|
343
|
-
| `dracula` | Dark-mode inspired color scheme | Developer docs |
|
|
344
|
-
|
|
345
|
-
All themes automatically inherit shared component styles (callouts, code blocks, tables, badges) via the `THEME_COMPONENTS` base layer.
|
|
346
|
-
|
|
347
|
-
---
|
|
348
|
-
|
|
349
|
-
## π₯οΈ CLI Flags
|
|
261
|
+
### Low-Level API (AST & Individual Document Builders)
|
|
350
262
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
β Chromium β
|
|
382
|
-
β (headlessβ
|
|
383
|
-
β PDF) β
|
|
384
|
-
βΌ βΌ βΌ
|
|
385
|
-
.docx .pdf .html
|
|
263
|
+
```typescript
|
|
264
|
+
import * as fs from "node:fs";
|
|
265
|
+
import {
|
|
266
|
+
parseMarkdownDocument,
|
|
267
|
+
buildDocxDocument,
|
|
268
|
+
buildPdfDocument,
|
|
269
|
+
buildHtmlDocument,
|
|
270
|
+
Theme,
|
|
271
|
+
} from "@masumdev/markforge";
|
|
272
|
+
|
|
273
|
+
const markdownContent = fs.readFileSync("./report.md", "utf-8");
|
|
274
|
+
|
|
275
|
+
// 1. Parse Markdown into structured AST
|
|
276
|
+
const doc = parseMarkdownDocument(markdownContent);
|
|
277
|
+
|
|
278
|
+
const config = {
|
|
279
|
+
theme: Theme.CORPORATE,
|
|
280
|
+
toc: true,
|
|
281
|
+
margins: { top: "2.5cm", bottom: "2.5cm", left: "2.5cm", right: "2.5cm" },
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
// 2. Build formats independently into binary buffers or HTML strings
|
|
285
|
+
const docxBuffer = await buildDocxDocument(doc, config);
|
|
286
|
+
const pdfBuffer = await buildPdfDocument(doc, config);
|
|
287
|
+
const htmlString = await buildHtmlDocument(doc, config);
|
|
288
|
+
|
|
289
|
+
// 3. Write output files
|
|
290
|
+
fs.writeFileSync("./dist/report.docx", docxBuffer);
|
|
291
|
+
fs.writeFileSync("./dist/report.pdf", pdfBuffer);
|
|
292
|
+
fs.writeFileSync("./dist/report.html", htmlString, "utf-8");
|
|
386
293
|
```
|
|
387
294
|
|
|
388
|
-
**Sub-systems:**
|
|
389
|
-
- `imageResolver` β Local / URL / Base64 / SVG asset resolution
|
|
390
|
-
- `mermaidRenderer` β Headless Mermaid.js diagram rasterization
|
|
391
|
-
- `syntaxHighlighter` β Dual dark/light theme tokenizer (no external deps)
|
|
392
|
-
- `htmlThemes` β `THEME_COMPONENTS` base + per-theme typography overrides
|
|
393
|
-
|
|
394
295
|
---
|
|
395
296
|
|
|
396
297
|
## π License
|
|
397
298
|
|
|
398
|
-
MIT Β© [
|
|
299
|
+
MIT Β© [Masum Dev](https://github.com/masumdev)
|