@masumdev/markforge 0.2.3 → 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 CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  # @masumdev/markforge
4
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.
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
  [![npm version](https://img.shields.io/npm/v/@masumdev/markforge.svg?style=flat-square&color=33CDCF)](https://www.npmjs.com/package/@masumdev/markforge)
9
9
  [![License: MIT](https://img.shields.io/badge/License-MIT-33CDCF.svg?style=flat-square)](https://opensource.org/licenses/MIT)
@@ -18,291 +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
- | 🎨 **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 |
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
- # Dev dependency
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
- ## 🚀 Quick Start
52
+ ## 💻 CLI Usage
51
53
 
52
54
  ```bash
53
- # Convert to DOCX + PDF (default)
55
+ # Basic conversion to DOCX and PDF (defaults)
54
56
  markforge document.md
55
57
 
56
- # Specify output formats
58
+ # Specify target formats and output folder
57
59
  markforge document.md --to docx,pdf,html -o ./dist
58
60
 
59
- # Use a theme and custom CSS
60
- markforge report.md --theme academic --css ./styles/corp.css
61
+ # Use custom CSS styling and force Table of Contents
62
+ markforge specification.md --css ./styles/custom.css --toc
61
63
 
62
- # Force Table of Contents
63
- markforge specification.md --toc
64
+ # Watch mode for live re-compilation
65
+ markforge report.md --watch
64
66
 
65
- # Watch mode
66
- markforge document.md --watch
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
71
+ ### CLI Flags Reference
74
72
 
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.
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 | |
80
92
 
81
- > [!TIP]
82
- > This is a tip — rendered with green styling.
93
+ ---
83
94
 
84
- > [!IMPORTANT]
85
- > Critical information — rendered with purple styling.
95
+ ## ⚙️ Configuration (`markforge.config.ts`)
86
96
 
87
- > [!WARNING]
88
- > A warning — rendered with amber/yellow styling.
97
+ MarkForge supports type-safe configuration with full TypeScript Enums:
89
98
 
90
- > [!CAUTION]
91
- > High-risk action — rendered with red styling.
92
- ```
99
+ ```typescript
100
+ import {
101
+ defineConfig,
102
+ OutputFormat,
103
+ Theme,
104
+ Orientation,
105
+ PaperSizeEnum,
106
+ SyntaxTheme,
107
+ WatermarkPosition,
108
+ } from "@masumdev/markforge";
93
109
 
94
- ### Mermaid Diagrams
110
+ export default defineConfig({
111
+ // Target output formats
112
+ to: [OutputFormat.DOCX, OutputFormat.PDF, OutputFormat.HTML],
95
113
 
96
- Mermaid code blocks are automatically rendered into images embedded in all output formats:
114
+ // Output destination directory
115
+ outputDir: ".temp/output-docs",
97
116
 
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
- ````
117
+ // Visual document theme (Theme.CORPORATE preset or a custom ThemeProps object)
118
+ theme: Theme.CORPORATE,
107
119
 
108
- ### Syntax-Highlighted Code Blocks
120
+ // Page orientation & standard physical paper size
121
+ orientation: Orientation.PORTRAIT,
122
+ paperSize: PaperSizeEnum.A4,
109
123
 
110
- All common languages are supported with proper token coloring:
124
+ // Document page margins
125
+ margins: {
126
+ top: "3cm",
127
+ bottom: "2.5cm",
128
+ left: "2.5cm",
129
+ right: "2.5cm",
130
+ },
111
131
 
112
- ````markdown
113
- ```typescript
114
- import { markforge } from "@masumdev/markforge";
132
+ // Running headers with dynamic tokens & per-zone slot styling
133
+ header: {
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",
150
+ },
115
151
 
116
- const result = await markforge("./spec.md", { to: ["pdf", "docx"] });
117
- ```
118
- ````
152
+ // Running footers with dynamic page numbering & per-zone slot styling
153
+ footer: {
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
+ },
119
174
 
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)
175
+ // Automatic Table of Contents
176
+ toc: true,
123
177
 
124
- ### Table of Contents
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,
186
+ },
125
187
 
126
- Add `toc: true` in frontmatter or use `--toc` CLI flag to auto-generate:
188
+ // Syntax highlighting theme
189
+ syntaxTheme: SyntaxTheme.DRACULA,
127
190
 
128
- ```markdown
129
- ---
130
- toc: true
131
- ---
191
+ // Asset embedding & bundling flags
192
+ embedImages: true,
193
+ bundleHtml: true,
132
194
 
133
- # My Document
195
+ // Global document metadata
196
+ metadata: {
197
+ title: "Unified Platform Architecture & Document Suite",
198
+ subtitle: "Enterprise Specification & Feature Validation Guide",
199
+ author: "Masum RPG",
200
+ company: "Masum Dev Technologies",
201
+ version: "1.0.0",
202
+ date: "2026-08-29",
203
+ lang: "en",
204
+ },
205
+ });
134
206
  ```
135
207
 
136
208
  ---
137
209
 
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
- ---
210
+ ## 🎨 Custom Theme Customization (`ThemeProps`)
167
211
 
168
- ## ⚙️ Configuration (`markforge.config.ts`)
212
+ You can completely rebrand all document styling by passing a `ThemeProps` object:
169
213
 
170
214
  ```typescript
171
215
  import { defineConfig } from "@masumdev/markforge";
172
216
 
173
217
  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",
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",
201
231
  },
202
232
  });
203
233
  ```
204
234
 
205
235
  ---
206
236
 
207
- ## 💻 Programmatic API
237
+ ## 🚀 Programmatic API
238
+
239
+ ### High-Level API (`compileMarkdown` / `markforge`)
208
240
 
209
241
  ```typescript
210
- import { markforge, compileMarkdown } from "@masumdev/markforge";
242
+ import { compileMarkdown, OutputFormat } from "@masumdev/markforge";
211
243
 
212
- // High-level: compile file write to disk
213
- const result = await markforge("./specification.md", {
214
- to: ["docx", "pdf", "html"],
244
+ const result = await compileMarkdown("./specification.md", {
245
+ to: [OutputFormat.DOCX, OutputFormat.PDF, OutputFormat.HTML],
215
246
  outputDir: "./dist",
216
- theme: "academic",
247
+ toc: true,
217
248
  metadata: {
218
- title: "System Architecture Specification",
219
- author: "Ma'sum",
220
- version: "2.4.0",
249
+ title: "API Reference Manual",
250
+ author: "Masum Dev",
251
+ version: "1.0.0",
221
252
  },
222
253
  });
223
254
 
224
- console.log(`✓ Generated ${result.files.length} files in ${result.durationMs}ms`);
225
-
255
+ console.log(`✓ Compiled ${result.files.length} documents in ${result.durationMs}ms:`);
226
256
  for (const file of result.files) {
227
- console.log(` [${file.format.toUpperCase()}] ${file.filePath} ${file.sizeBytes} bytes`);
257
+ console.log(` [${file.format.toUpperCase()}] ${file.filePath} (${file.sizeBytes} bytes)`);
228
258
  }
229
259
  ```
230
260
 
231
- ```typescript
232
- import { compileMarkdown, buildPdfDocument, buildDocxDocument, buildHtmlDocument } from "@masumdev/markforge";
261
+ ### Low-Level API (AST & Individual Document Builders)
233
262
 
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
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");
296
293
  ```
297
294
 
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
295
  ---
305
296
 
306
297
  ## 📄 License
307
298
 
308
- MIT © [Ma'sum](https://github.com/masumrpg)
299
+ MIT © [Masum Dev](https://github.com/masumdev)