@masumdev/markforge 0.2.4 → 0.3.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 +229 -298
- package/dist/{App-IJVCGBJM.mjs → App-AM2CWXHJ.mjs} +1413 -378
- package/dist/{chunk-NGC2ZAWZ.mjs → chunk-HKB4CSPZ.mjs} +1 -1
- package/dist/cli.mjs +2 -2
- package/dist/index.d.mts +409 -59
- package/dist/index.d.ts +409 -59
- package/dist/index.js +1533 -479
- package/dist/index.mjs +1520 -480
- 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,312 @@ 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)
|
|
123
|
-
|
|
124
|
-
### Table of Contents
|
|
125
|
-
|
|
126
|
-
Add `toc: true` in frontmatter or use `--toc` CLI flag to auto-generate:
|
|
71
|
+
### CLI Flags Reference
|
|
127
72
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
version
|
|
146
|
-
|
|
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: "
|
|
197
|
+
title: "Unified Platform Architecture & Document Suite",
|
|
198
|
+
subtitle: "Enterprise Specification & Feature Validation Guide",
|
|
221
199
|
author: "Ma'sum",
|
|
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
|
-
### 2. JSON with `$schema` (`markforge.config.json`)
|
|
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
|
-
```
|
|
266
|
-
|
|
267
|
-
### 3. YAML (`markforge.config.yaml` / `.markforgerc.yaml`)
|
|
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
|
-
```
|
|
293
|
-
|
|
294
|
-
|
|
295
208
|
---
|
|
296
209
|
|
|
297
|
-
##
|
|
210
|
+
## Custom Theme Customization (`ThemeProps`)
|
|
211
|
+
|
|
212
|
+
You can completely rebrand all document styling by passing a `ThemeProps` object:
|
|
298
213
|
|
|
299
214
|
```typescript
|
|
300
|
-
import {
|
|
215
|
+
import { defineConfig } from "@masumdev/markforge";
|
|
301
216
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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",
|
|
311
231
|
},
|
|
312
232
|
});
|
|
313
|
-
|
|
314
|
-
console.log(`✓ Generated ${result.files.length} files in ${result.durationMs}ms`);
|
|
315
|
-
|
|
316
|
-
for (const file of result.files) {
|
|
317
|
-
console.log(` [${file.format.toUpperCase()}] ${file.filePath} — ${file.sizeBytes} bytes`);
|
|
318
|
-
}
|
|
319
|
-
```
|
|
320
|
-
|
|
321
|
-
```typescript
|
|
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
233
|
```
|
|
331
234
|
|
|
332
235
|
---
|
|
333
236
|
|
|
334
|
-
##
|
|
237
|
+
## Signatures & Approval Blocks (`signatures`)
|
|
335
238
|
|
|
336
|
-
|
|
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 |
|
|
239
|
+
Add formal signature sign-offs (*Lembar Pengesahan / Tanda Tangan*) with 1-4 slots:
|
|
344
240
|
|
|
345
|
-
|
|
241
|
+
```typescript
|
|
242
|
+
export default defineConfig({
|
|
243
|
+
signatures: {
|
|
244
|
+
align: "space-between", // "left" | "center" | "right" | "space-between"
|
|
245
|
+
style: "line", // "line" | "box" | "clean"
|
|
246
|
+
borderColor: "#CBD5E1",
|
|
247
|
+
items: [
|
|
248
|
+
{
|
|
249
|
+
title: "Prepared by",
|
|
250
|
+
name: "{author}",
|
|
251
|
+
role: "Lead Platform Architect",
|
|
252
|
+
date: "{date}",
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
title: "Approved by",
|
|
256
|
+
name: "Dr. Alexander Wright",
|
|
257
|
+
role: "Chief Technology Officer",
|
|
258
|
+
date: "{date}",
|
|
259
|
+
},
|
|
260
|
+
],
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
```
|
|
346
264
|
|
|
347
265
|
---
|
|
348
266
|
|
|
349
|
-
##
|
|
267
|
+
## Programmatic API
|
|
350
268
|
|
|
351
|
-
|
|
352
|
-
| :--- | :---: | :--- | :--- |
|
|
353
|
-
| `--to <formats>` | `-t` | Comma-separated output formats: `docx`, `pdf`, `html` | `docx,pdf` |
|
|
354
|
-
| `--output <dir>` | `-o` | Output directory | Same as input file dir |
|
|
355
|
-
| `--theme <name>` | | Built-in theme name | `default` |
|
|
356
|
-
| `--css <path...>` | | Custom CSS file(s) to inject | |
|
|
357
|
-
| `--toc` | | Force Table of Contents generation | `false` |
|
|
358
|
-
| `--config <path>` | `-c` | Config file path (`markforge.config.ts`, `.json`, `.yaml`) | Auto-discovered |
|
|
359
|
-
| `--watch` | `-w` | Watch input and re-compile on change | `false` |
|
|
360
|
-
| `--version` | `-V` | Print version and exit | |
|
|
361
|
-
| `--help` | `-h` | Show help | |
|
|
269
|
+
### High-Level API (`compileMarkdown` / `markforge`)
|
|
362
270
|
|
|
363
|
-
|
|
271
|
+
```typescript
|
|
272
|
+
import { compileMarkdown, OutputFormat } from "@masumdev/markforge";
|
|
364
273
|
|
|
365
|
-
|
|
274
|
+
const result = await compileMarkdown("./specification.md", {
|
|
275
|
+
to: [OutputFormat.DOCX, OutputFormat.PDF, OutputFormat.HTML],
|
|
276
|
+
outputDir: "./dist",
|
|
277
|
+
toc: true,
|
|
278
|
+
metadata: {
|
|
279
|
+
title: "API Reference Manual",
|
|
280
|
+
author: "Ma'sum",
|
|
281
|
+
version: "1.0.0",
|
|
282
|
+
},
|
|
283
|
+
});
|
|
366
284
|
|
|
285
|
+
console.log(`✓ Compiled ${result.files.length} documents in ${result.durationMs}ms:`);
|
|
286
|
+
for (const file of result.files) {
|
|
287
|
+
console.log(` [${file.format.toUpperCase()}] ${file.filePath} (${file.sizeBytes} bytes)`);
|
|
288
|
+
}
|
|
367
289
|
```
|
|
368
|
-
Markdown / MDX source
|
|
369
|
-
│
|
|
370
|
-
▼
|
|
371
|
-
┌─────────────┐
|
|
372
|
-
│ AST Parser │ → Frontmatter + Node tree
|
|
373
|
-
└──────┬──────┘
|
|
374
|
-
│
|
|
375
|
-
┌─────┼─────┐
|
|
376
|
-
│ │ │
|
|
377
|
-
▼ ▼ ▼
|
|
378
|
-
DOCX PDF HTML
|
|
379
|
-
Builder Builder Builder
|
|
380
|
-
│ │ │
|
|
381
|
-
│ Chromium │
|
|
382
|
-
│ (headless│
|
|
383
|
-
│ PDF) │
|
|
384
|
-
▼ ▼ ▼
|
|
385
|
-
.docx .pdf .html
|
|
386
|
-
```
|
|
387
290
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
291
|
+
### Low-Level API (AST & Individual Document Builders)
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
import * as fs from "node:fs";
|
|
295
|
+
import {
|
|
296
|
+
parseMarkdownDocument,
|
|
297
|
+
buildDocxDocument,
|
|
298
|
+
buildPdfDocument,
|
|
299
|
+
buildHtmlDocument,
|
|
300
|
+
Theme,
|
|
301
|
+
} from "@masumdev/markforge";
|
|
302
|
+
|
|
303
|
+
const markdownContent = fs.readFileSync("./report.md", "utf-8");
|
|
304
|
+
|
|
305
|
+
// 1. Parse Markdown into structured AST
|
|
306
|
+
const doc = parseMarkdownDocument(markdownContent);
|
|
307
|
+
|
|
308
|
+
const config = {
|
|
309
|
+
theme: Theme.CORPORATE,
|
|
310
|
+
toc: true,
|
|
311
|
+
margins: { top: "2.5cm", bottom: "2.5cm", left: "2.5cm", right: "2.5cm" },
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
// 2. Build formats independently into binary buffers or HTML strings
|
|
315
|
+
const docxBuffer = await buildDocxDocument(doc, config);
|
|
316
|
+
const pdfBuffer = await buildPdfDocument(doc, config);
|
|
317
|
+
const htmlString = await buildHtmlDocument(doc, config);
|
|
318
|
+
|
|
319
|
+
// 3. Write output files
|
|
320
|
+
fs.writeFileSync("./dist/report.docx", docxBuffer);
|
|
321
|
+
fs.writeFileSync("./dist/report.pdf", pdfBuffer);
|
|
322
|
+
fs.writeFileSync("./dist/report.html", htmlString, "utf-8");
|
|
323
|
+
```
|
|
393
324
|
|
|
394
325
|
---
|
|
395
326
|
|
|
396
|
-
##
|
|
327
|
+
## License
|
|
397
328
|
|
|
398
329
|
MIT © [Ma'sum](https://github.com/masumrpg)
|