@masumdev/markforge 0.1.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/LICENSE +21 -0
- package/README.md +308 -0
- package/dist/cli.mjs +2554 -0
- package/dist/index.d.mts +344 -0
- package/dist/index.d.ts +344 -0
- package/dist/index.js +2475 -0
- package/dist/index.mjs +2439 -0
- package/package.json +79 -0
- package/schema.json +116 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ma'sum
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# @masumdev/markforge
|
|
4
|
+
|
|
5
|
+
**Modern, high-performance Markdown & MDX multi-format publishing engine & CLI.**
|
|
6
|
+
Convert Markdown into pixel-perfect **DOCX**, **PDF**, and **HTML** with syntax highlighting, Mermaid diagrams, callout boxes, and a beautiful Ink terminal UI.
|
|
7
|
+
|
|
8
|
+
[](https://www.npmjs.com/package/@masumdev/markforge)
|
|
9
|
+
[](https://opensource.org/licenses/MIT)
|
|
10
|
+
[](https://www.typescriptlang.org/)
|
|
11
|
+
[](https://bun.sh)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## β¨ Features
|
|
18
|
+
|
|
19
|
+
| Feature | Description |
|
|
20
|
+
| :--- | :--- |
|
|
21
|
+
| π **Multi-Format Output** | Generate `.docx`, `.pdf`, and `.html` from a single Markdown source |
|
|
22
|
+
| π¨ **Mermaid Diagrams** | Full Mermaid.js support β flowcharts, sequence, gantt, class diagrams |
|
|
23
|
+
| π’ **Callout / Alert Boxes** | GitHub-style `> [!NOTE]`, `> [!TIP]`, `> [!WARNING]`, `> [!CAUTION]`, `> [!IMPORTANT]` |
|
|
24
|
+
| π **Dual Syntax Highlighting** | Dark theme for PDF/HTML, Light theme for DOCX β 100% readable in both |
|
|
25
|
+
| πΌοΈ **Image Inlining Engine** | Auto-resolves local paths, remote URLs, Base64 URIs, and SVGs |
|
|
26
|
+
| π **Auto Table of Contents** | Anchored TOC generated from heading structure |
|
|
27
|
+
| π **Header & Footer Zones** | Left / Center / Right multi-zone headers and footers per format |
|
|
28
|
+
| π¨ **Curated Themes** | `default`, `academic`, `github`, `corporate`, `minimal`, `dracula` |
|
|
29
|
+
| π§ **Watermark Support** | Optional configurable watermark (position, opacity, text) β off by default |
|
|
30
|
+
| βοΈ **Type-Safe Config** | `markforge.config.ts`, `.markforgerc.json`, or YAML with JSON Schema |
|
|
31
|
+
| π **Programmatic API** | Full TypeScript API for Node.js & Bun integration |
|
|
32
|
+
| π₯οΈ **Ink Terminal UI** | Rich interactive TUI with progress indicators and build summary |
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## π¦ Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Global CLI
|
|
40
|
+
npm install -g @masumdev/markforge
|
|
41
|
+
bun add -g @masumdev/markforge
|
|
42
|
+
|
|
43
|
+
# Dev dependency
|
|
44
|
+
npm install -D @masumdev/markforge
|
|
45
|
+
bun add -d @masumdev/markforge
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## π Quick Start
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# Convert to DOCX + PDF (default)
|
|
54
|
+
markforge document.md
|
|
55
|
+
|
|
56
|
+
# Specify output formats
|
|
57
|
+
markforge document.md --to docx,pdf,html -o ./dist
|
|
58
|
+
|
|
59
|
+
# Use a theme and custom CSS
|
|
60
|
+
markforge report.md --theme academic --css ./styles/corp.css
|
|
61
|
+
|
|
62
|
+
# Force Table of Contents
|
|
63
|
+
markforge specification.md --toc
|
|
64
|
+
|
|
65
|
+
# Watch mode
|
|
66
|
+
markforge document.md --watch
|
|
67
|
+
```
|
|
68
|
+
|
|
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)
|
|
123
|
+
|
|
124
|
+
### Table of Contents
|
|
125
|
+
|
|
126
|
+
Add `toc: true` in frontmatter or use `--toc` CLI flag to auto-generate:
|
|
127
|
+
|
|
128
|
+
```markdown
|
|
129
|
+
---
|
|
130
|
+
toc: true
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
# My Document
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## π Frontmatter Reference
|
|
139
|
+
|
|
140
|
+
```markdown
|
|
141
|
+
---
|
|
142
|
+
title: "Enterprise Architecture Specification"
|
|
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
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## βοΈ Configuration (`markforge.config.ts`)
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
import { defineConfig } from "@masumdev/markforge";
|
|
172
|
+
|
|
173
|
+
export default defineConfig({
|
|
174
|
+
to: ["docx", "pdf", "html"],
|
|
175
|
+
outputDir: "./dist/documents",
|
|
176
|
+
theme: "default",
|
|
177
|
+
orientation: "portrait",
|
|
178
|
+
paperSize: "A4",
|
|
179
|
+
margins: {
|
|
180
|
+
top: "2.5cm",
|
|
181
|
+
bottom: "2.5cm",
|
|
182
|
+
left: "3cm",
|
|
183
|
+
right: "3cm",
|
|
184
|
+
},
|
|
185
|
+
header: {
|
|
186
|
+
left: "My Organization",
|
|
187
|
+
center: "{title}",
|
|
188
|
+
right: "v{version}",
|
|
189
|
+
},
|
|
190
|
+
footer: {
|
|
191
|
+
left: "Confidential",
|
|
192
|
+
right: "Page {page} of {pages}",
|
|
193
|
+
},
|
|
194
|
+
toc: true,
|
|
195
|
+
embedImages: true,
|
|
196
|
+
watermark: {
|
|
197
|
+
enabled: false, // disabled by default β enable to add branding
|
|
198
|
+
text: "DRAFT",
|
|
199
|
+
opacity: 0.07,
|
|
200
|
+
position: "diagonal",
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## π» Programmatic API
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
import { markforge, compileMarkdown } from "@masumdev/markforge";
|
|
211
|
+
|
|
212
|
+
// High-level: compile file β write to disk
|
|
213
|
+
const result = await markforge("./specification.md", {
|
|
214
|
+
to: ["docx", "pdf", "html"],
|
|
215
|
+
outputDir: "./dist",
|
|
216
|
+
theme: "academic",
|
|
217
|
+
metadata: {
|
|
218
|
+
title: "System Architecture Specification",
|
|
219
|
+
author: "Ma'sum",
|
|
220
|
+
version: "2.4.0",
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
console.log(`β Generated ${result.files.length} files in ${result.durationMs}ms`);
|
|
225
|
+
|
|
226
|
+
for (const file of result.files) {
|
|
227
|
+
console.log(` [${file.format.toUpperCase()}] ${file.filePath} β ${file.sizeBytes} bytes`);
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import { compileMarkdown, buildPdfDocument, buildDocxDocument, buildHtmlDocument } from "@masumdev/markforge";
|
|
233
|
+
|
|
234
|
+
// Low-level: parse β build each format independently
|
|
235
|
+
const parsed = await compileMarkdown("./report.md");
|
|
236
|
+
|
|
237
|
+
const pdfBuffer = await buildPdfDocument(parsed.doc, parsed.config, parsed.baseDir);
|
|
238
|
+
const docxBuffer = await buildDocxDocument(parsed.doc, parsed.config, parsed.baseDir);
|
|
239
|
+
const htmlString = await buildHtmlDocument(parsed.doc, parsed.config, parsed.baseDir);
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## π¨ Built-in Themes
|
|
245
|
+
|
|
246
|
+
| Theme | Description | Best For |
|
|
247
|
+
| :--- | :--- | :--- |
|
|
248
|
+
| `default` | Blu by BCA Digital cyan palette, modern sans-serif | Tech docs, specifications |
|
|
249
|
+
| `academic` | Serif typography (Merriweather/Georgia), justified text | Papers, reports, theses |
|
|
250
|
+
| `github` | GitHub Markdown rendering style | READMEs, open-source docs |
|
|
251
|
+
| `corporate` | Clean professional layout | Business documents |
|
|
252
|
+
| `minimal` | Minimal whitespace-focused design | Simple notes |
|
|
253
|
+
| `dracula` | Dark-mode inspired color scheme | Developer docs |
|
|
254
|
+
|
|
255
|
+
All themes automatically inherit shared component styles (callouts, code blocks, tables, badges) via the `THEME_COMPONENTS` base layer.
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## π₯οΈ CLI Flags
|
|
260
|
+
|
|
261
|
+
| Flag | Alias | Description | Default |
|
|
262
|
+
| :--- | :---: | :--- | :--- |
|
|
263
|
+
| `--to <formats>` | `-t` | Comma-separated output formats: `docx`, `pdf`, `html` | `docx,pdf` |
|
|
264
|
+
| `--output <dir>` | `-o` | Output directory | Same as input file dir |
|
|
265
|
+
| `--theme <name>` | | Built-in theme name | `default` |
|
|
266
|
+
| `--css <path...>` | | Custom CSS file(s) to inject | |
|
|
267
|
+
| `--toc` | | Force Table of Contents generation | `false` |
|
|
268
|
+
| `--config <path>` | `-c` | Config file path (`markforge.config.ts`, `.json`, `.yaml`) | Auto-discovered |
|
|
269
|
+
| `--watch` | `-w` | Watch input and re-compile on change | `false` |
|
|
270
|
+
| `--version` | `-V` | Print version and exit | |
|
|
271
|
+
| `--help` | `-h` | Show help | |
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## ποΈ Architecture
|
|
276
|
+
|
|
277
|
+
```
|
|
278
|
+
Markdown / MDX source
|
|
279
|
+
β
|
|
280
|
+
βΌ
|
|
281
|
+
βββββββββββββββ
|
|
282
|
+
β AST Parser β β Frontmatter + Node tree
|
|
283
|
+
ββββββββ¬βββββββ
|
|
284
|
+
β
|
|
285
|
+
βββββββΌββββββ
|
|
286
|
+
β β β
|
|
287
|
+
βΌ βΌ βΌ
|
|
288
|
+
DOCX PDF HTML
|
|
289
|
+
Builder Builder Builder
|
|
290
|
+
β β β
|
|
291
|
+
β Chromium β
|
|
292
|
+
β (headlessβ
|
|
293
|
+
β PDF) β
|
|
294
|
+
βΌ βΌ βΌ
|
|
295
|
+
.docx .pdf .html
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
**Sub-systems:**
|
|
299
|
+
- `imageResolver` β Local / URL / Base64 / SVG asset resolution
|
|
300
|
+
- `mermaidRenderer` β Headless Mermaid.js diagram rasterization
|
|
301
|
+
- `syntaxHighlighter` β Dual dark/light theme tokenizer (no external deps)
|
|
302
|
+
- `htmlThemes` β `THEME_COMPONENTS` base + per-theme typography overrides
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
## π License
|
|
307
|
+
|
|
308
|
+
MIT Β© [Ma'sum](https://github.com/masumrpg)
|