@masumdev/markforge 0.2.5 → 0.4.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
@@ -3,7 +3,7 @@
3
3
  # @masumdev/markforge
4
4
 
5
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.
6
+ Convert Markdown into pixel-perfect **DOCX**, **PDF**, and **HTML** with native typography, syntax highlighting, Mermaid diagrams, callout boxes, customizable `ThemeProps`, AES-256 PDF encryption, 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)
@@ -14,26 +14,35 @@ Convert Markdown into pixel-perfect **DOCX**, **PDF**, and **HTML** with native
14
14
 
15
15
  ---
16
16
 
17
- ## Features
17
+ ## Features
18
18
 
19
19
  | Feature | Description |
20
20
  | :--- | :--- |
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 |
21
+ | **Multi-Format Output** | Generate `.docx`, `.pdf`, and `.html` from a single Markdown source simultaneously |
22
+ | **Theme.CORPORATE & ThemeProps** | Flagship cyan corporate design system plus full custom colors and fonts via `ThemeProps` |
23
+ | **Cover Page Builder** | Four professional cover page presets (`modern`, `corporate-split`, `minimal`, `card`) with company logo |
24
+ | **Back Cover / Closing Page** | Dedicated closing page with company details, contact info, social links, and copyright notice |
25
+ | **Math & LaTeX Equations** | Native KaTeX math rendering for inline (`$E=mc^2$`) and display blocks (`$$\sum_{i=1}^n x_i$$`) |
26
+ | **Multi-Column Directives** | Flexible multi-column layouts (`:::columns 2` and `:::col`) across HTML, PDF, and DOCX |
27
+ | **Section Numbering** | Automated hierarchical decimal numbering (`1.`, `1.1.`, `1.1.1.`) with configurable depth |
28
+ | **Footnotes & Endnotes** | Full academic footnotes (`[^1]` and `[^1]: description`) with backlinks and DOCX notes |
29
+ | **AES-256 PDF Security** | ISO 32000-2 standard PDF encryption with user/owner passwords and granular permissions |
30
+ | **100% Unselectable Watermark** | Chromium-rendered Image XObject watermark preventing any cursor selection interference |
31
+ | **Per-Zone Header & Footer** | Granular color, font size, font family, bold, and italic controls per `left`, `center`, `right` slot |
32
+ | **Mermaid Diagrams** | Full Mermaid.js diagram engine for flowcharts, sequence diagrams, gantt charts, and class models |
33
+ | **Callout / Alert Boxes** | GitHub-style `> [!NOTE]`, `> [!TIP]`, `> [!IMPORTANT]`, `> [!WARNING]`, `> [!CAUTION]` |
34
+ | **Syntax Highlighting** | Tokenized multi-language code blocks (`dracula`, `github-dark`, `monokai`, `nord`, etc.) |
35
+ | **Image Inlining Engine** | Resolves local files, remote URLs, Base64 data URIs, and SVGs into self-contained embedded assets |
36
+ | **Signatures & Approvals** | Multi-signatory approval blocks with customizable alignment, border styles, and signature images |
37
+ | **Live-Reload Preview Server** | Real-time HTTP preview server (`--serve`) with Server-Sent Events (SSE) and scroll sync |
38
+ | **Windows Corporate Compliance** | Native Microsoft Edge detection, clean isolated process arguments, and `windowsHide` support |
39
+ | **Type-Safe Config** | `markforge.config.ts` with Enums, `.markforgerc.json`, or YAML with JSON Schema |
40
+ | **Programmatic API** | High-level `compileMarkdown()` and low-level AST document builders for Node.js and Bun |
41
+ | **Ink Terminal UI** | Interactive TUI with live progress tracking, timers, and compilation metrics |
33
42
 
34
43
  ---
35
44
 
36
- ## 📦 Installation
45
+ ## Installation
37
46
 
38
47
  ```bash
39
48
  # Global CLI Installation
@@ -49,7 +58,7 @@ bun add -d @masumdev/markforge
49
58
 
50
59
  ---
51
60
 
52
- ## 💻 CLI Usage
61
+ ## CLI Usage
53
62
 
54
63
  ```bash
55
64
  # Basic conversion to DOCX and PDF (defaults)
@@ -58,8 +67,8 @@ markforge document.md
58
67
  # Specify target formats and output folder
59
68
  markforge document.md --to docx,pdf,html -o ./dist
60
69
 
61
- # Use custom CSS styling and force Table of Contents
62
- markforge specification.md --css ./styles/custom.css --toc
70
+ # Use custom configuration file
71
+ markforge specification.md -c ./markforge.config.ts
63
72
 
64
73
  # Watch mode for live re-compilation
65
74
  markforge report.md --watch
@@ -76,7 +85,7 @@ markforge document.md --serve --port 4000 --open
76
85
  | `--to <formats...>` | `-t` | Output formats: `docx`, `pdf`, `html`, `png` | `docx,pdf` |
77
86
  | `--output <dir>` | `-o` | Output directory | Same as input file |
78
87
  | `--config <file>` | `-c` | Explicit configuration file path | Auto-discovered |
79
- | `--theme <name>` | | Visual theme preset (`corporate`, `default`) | `corporate` |
88
+ | `--theme <name>` | | Visual theme preset (`corporate`, `default`, `academic`, `github`, `minimal`) | `corporate` |
80
89
  | `--css <files...>` | | Custom CSS stylesheets to inject | `undefined` |
81
90
  | `--orientation <type>` | | Page orientation (`portrait`, `landscape`) | `portrait` |
82
91
  | `--paper-size <size>` | | Standard paper size (`A4`, `Letter`, `Legal`, `A3`, `A5`) | `A4` |
@@ -92,9 +101,9 @@ markforge document.md --serve --port 4000 --open
92
101
 
93
102
  ---
94
103
 
95
- ## ⚙️ Configuration (`markforge.config.ts`)
104
+ ## Configuration (`markforge.config.ts`)
96
105
 
97
- MarkForge supports type-safe configuration with full TypeScript Enums:
106
+ MarkForge supports type-safe configuration with TypeScript Enums:
98
107
 
99
108
  ```typescript
100
109
  import {
@@ -104,24 +113,23 @@ import {
104
113
  Orientation,
105
114
  PaperSizeEnum,
106
115
  SyntaxTheme,
107
- WatermarkPosition,
116
+ SignatureAlign,
117
+ SignatureStyle,
108
118
  } from "@masumdev/markforge";
109
119
 
110
120
  export default defineConfig({
111
121
  // Target output formats
112
122
  to: [OutputFormat.DOCX, OutputFormat.PDF, OutputFormat.HTML],
113
123
 
114
- // Output destination directory
115
- outputDir: ".temp/output-docs",
124
+ // Destination folder
125
+ outputDir: ".temp/output",
116
126
 
117
- // Visual document theme (Theme.CORPORATE preset or a custom ThemeProps object)
127
+ // Theme preset or custom ThemeProps
118
128
  theme: Theme.CORPORATE,
119
129
 
120
- // Page orientation & standard physical paper size
130
+ // Page geometry
121
131
  orientation: Orientation.PORTRAIT,
122
132
  paperSize: PaperSizeEnum.A4,
123
-
124
- // Document page margins
125
133
  margins: {
126
134
  top: "3cm",
127
135
  bottom: "2.5cm",
@@ -129,16 +137,46 @@ export default defineConfig({
129
137
  right: "2.5cm",
130
138
  },
131
139
 
132
- // Running headers with dynamic tokens & per-zone slot styling
140
+ // Cover Page Builder
141
+ coverPage: {
142
+ enabled: true,
143
+ preset: "modern",
144
+ logo: "./assets/company-logo.png",
145
+ logoWidth: 140,
146
+ badge: "CONFIDENTIAL SPECIFICATION",
147
+ badgeColor: "#ECFDFD",
148
+ badgeTextColor: "#0D998D",
149
+ footerText: "Proprietary Document - Authorized Personnel Only",
150
+ },
151
+
152
+ // Back Cover / Closing Page
153
+ backCover: {
154
+ enabled: true,
155
+ preset: "corporate",
156
+ logo: "./assets/company-logo.png",
157
+ logoWidth: 120,
158
+ title: "Thank You",
159
+ subtitle: "Enterprise Cross-Platform Document Solutions",
160
+ company: "Masum Dev Technologies",
161
+ address: "Jakarta, Indonesia",
162
+ email: "contact@masumdev.com",
163
+ phone: "+62 812 3456 7890",
164
+ website: "https://react-native-library-docs.netlify.app",
165
+ social: {
166
+ github: "https://github.com/masumrpg",
167
+ },
168
+ copyright: "Copyright (c) {year} {company}. All Rights Reserved.",
169
+ },
170
+
171
+ // Running headers with per-zone styling & tokens
133
172
  header: {
134
173
  left: {
135
174
  text: "{company} - {title}",
136
175
  color: "#0D998D",
137
176
  fontSize: 9,
138
- fontFamily: "Inter, Segoe UI, sans-serif",
139
177
  bold: true,
140
178
  },
141
- center: "Internal Technical Guide",
179
+ center: "Technical Specification",
142
180
  right: {
143
181
  text: "v{version}",
144
182
  color: "#94A3B8",
@@ -149,7 +187,7 @@ export default defineConfig({
149
187
  dividerColor: "#CBD5E1",
150
188
  },
151
189
 
152
- // Running footers with dynamic page numbering & per-zone slot styling
190
+ // Running footers with dynamic page numbers
153
191
  footer: {
154
192
  left: {
155
193
  text: "Author: {author}",
@@ -172,128 +210,147 @@ export default defineConfig({
172
210
  dividerColor: "#CBD5E1",
173
211
  },
174
212
 
175
- // Automatic Table of Contents
213
+ // Table of Contents & Heading Numbering
176
214
  toc: true,
215
+ tocTitle: "TABLE OF CONTENTS",
216
+ tocDepth: 3,
217
+ numberHeadings: {
218
+ enabled: true,
219
+ depth: 3,
220
+ skipH1: false,
221
+ },
222
+
223
+ // Math equation rendering
224
+ math: true,
225
+
226
+ // PDF Document Security & AES-256 Encryption
227
+ security: {
228
+ userPassword: "masumdev_secret", // Password required to open document
229
+ ownerPassword: "masumdev_admin", // Master password to edit permissions
230
+ permissions: {
231
+ printing: "highResolution",
232
+ modifying: false,
233
+ copying: true,
234
+ annotating: true,
235
+ fillingForms: true,
236
+ contentAccessibility: true,
237
+ documentAssembly: false,
238
+ },
239
+ },
177
240
 
178
- // Watermark configuration (placed at lowest background layer)
241
+ // Unselectable diagonal watermark
179
242
  watermark: {
180
243
  text: "CONFIDENTIAL DRAFT",
181
244
  color: "#E11D48",
182
245
  opacity: 0.1,
183
246
  fontSize: 52,
184
247
  rotate: -45,
185
- position: WatermarkPosition.DIAGONAL,
186
248
  },
187
249
 
188
- // Syntax highlighting theme
189
- syntaxTheme: SyntaxTheme.DRACULA,
250
+ // Document signatures and approval block
251
+ signatureBlock: {
252
+ align: SignatureAlign.SPACE_BETWEEN,
253
+ style: SignatureStyle.BOX,
254
+ spacingBefore: "2.5cm",
255
+ items: [
256
+ {
257
+ title: "Prepared By",
258
+ name: "{author}",
259
+ role: "Principal Mobile Architect",
260
+ date: "{date}",
261
+ },
262
+ {
263
+ title: "Approved By",
264
+ name: "Enterprise Architecture Board",
265
+ role: "Chief Technology Officer",
266
+ date: "{date}",
267
+ },
268
+ ],
269
+ },
190
270
 
191
- // Asset embedding & bundling flags
192
- embedImages: true,
193
- bundleHtml: true,
271
+ // Code syntax highlighting
272
+ syntaxTheme: SyntaxTheme.GITHUB_DARK,
194
273
 
195
- // Global document metadata
274
+ // Fallback metadata dictionary
196
275
  metadata: {
197
- title: "Unified Platform Architecture & Document Suite",
198
- subtitle: "Enterprise Specification & Feature Validation Guide",
199
- author: "Masum RPG",
276
+ title: "Document Reference Manual",
277
+ author: "Ma'sum (@masumrpg)",
200
278
  company: "Masum Dev Technologies",
201
279
  version: "1.0.0",
202
- date: "2026-08-29",
203
- lang: "en",
280
+ date: "2026-08-30",
204
281
  },
205
282
  });
206
283
  ```
207
284
 
208
285
  ---
209
286
 
210
- ## 🎨 Custom Theme Customization (`ThemeProps`)
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
- ```
287
+ ## Complete Configuration Properties Reference
288
+
289
+ | Property | Type | Default | Description |
290
+ | :--- | :--- | :--- | :--- |
291
+ | `to` | `OutputFormat[]` | `['docx', 'pdf']` | Array of target document formats (`docx`, `pdf`, `html`, `png`) |
292
+ | `outputDir` | `string` | `'.'` | Output destination directory |
293
+ | `clean` | `boolean` | `false` | Remove stale output files in destination directory before compilation |
294
+ | `theme` | `Theme \| ThemeProps` | `Theme.CORPORATE` | Built-in theme preset or custom `ThemeProps` design tokens |
295
+ | `orientation` | `Orientation` | `'portrait'` | Page orientation (`portrait`, `landscape`) |
296
+ | `paperSize` | `PaperSizeEnum` | `'A4'` | Standard paper size (`A4`, `Letter`, `Legal`, `A3`, `A5`) |
297
+ | `margins` | `PageMargins` | `{ top: '2.5cm', ... }` | Page margins with units (`cm`, `mm`, `in`, `pt`) |
298
+ | `header` | `HeaderFooterConfig` | `undefined` | Header configuration with slots (`left`, `center`, `right`) and divider |
299
+ | `footer` | `HeaderFooterConfig` | `undefined` | Footer configuration with slots (`left`, `center`, `right`) and divider |
300
+ | `toc` | `boolean` | `true` | Generate automated Table of Contents |
301
+ | `tocTitle` | `string` | `'TABLE OF CONTENTS'`| Header title for the Table of Contents |
302
+ | `tocDepth` | `number` | `3` | Maximum heading level included in Table of Contents (1 to 6) |
303
+ | `numberHeadings` | `boolean \| object` | `false` | Automated hierarchical decimal numbering for headings (`1.`, `1.1.`, etc.) |
304
+ | `coverPage` | `boolean \| object` | `false` | Isolated front cover page builder with presets and company logo |
305
+ | `backCover` | `boolean \| object` | `false` | Isolated closing back cover page builder with corporate contact info |
306
+ | `signatureBlock` | `object` | `undefined` | Formal multi-signatory approval and signing block |
307
+ | `math` | `boolean` | `false` | KaTeX LaTeX math equation rendering (`$inline$` and `$$block$$`) |
308
+ | `security` | `object` | `undefined` | ISO 32000-2 AES-256 PDF encryption, user/owner passwords, and permissions |
309
+ | `watermark` | `string \| object` | `undefined` | 100% unselectable diagonal watermark configuration |
310
+ | `syntaxTheme` | `SyntaxTheme` | `'github-dark'` | Code syntax highlighting color palette |
311
+ | `css` | `string \| string[]` | `undefined` | Custom CSS files to inject |
312
+ | `customCss` | `string` | `undefined` | Raw CSS string injected directly into the document head |
313
+ | `breakBeforeHeadings` | `number[]` | `[1]` | Heading levels that trigger an automatic page break (`1` = H1) |
314
+ | `embedImages` | `boolean` | `true` | Base64-encode and inline all remote and local images |
315
+ | `metadata` | `object` | `{}` | Document metadata dictionary for dynamic `{token}` interpolation |
234
316
 
235
317
  ---
236
318
 
237
- ## 🚀 Programmatic API
319
+ ## Programmatic API
238
320
 
239
- ### High-Level API (`compileMarkdown` / `markforge`)
321
+ MarkForge provides both high-level compilation functions and low-level AST builders:
240
322
 
241
323
  ```typescript
242
- import { compileMarkdown, OutputFormat } from "@masumdev/markforge";
243
-
244
- const result = await compileMarkdown("./specification.md", {
245
- to: [OutputFormat.DOCX, OutputFormat.PDF, OutputFormat.HTML],
246
- outputDir: "./dist",
247
- toc: true,
248
- metadata: {
249
- title: "API Reference Manual",
250
- author: "Masum Dev",
251
- version: "1.0.0",
252
- },
253
- });
254
-
255
- console.log(`✓ Compiled ${result.files.length} documents in ${result.durationMs}ms:`);
256
- for (const file of result.files) {
257
- console.log(` [${file.format.toUpperCase()}] ${file.filePath} (${file.sizeBytes} bytes)`);
258
- }
259
- ```
260
-
261
- ### Low-Level API (AST & Individual Document Builders)
262
-
263
- ```typescript
264
- import * as fs from "node:fs";
265
324
  import {
266
- parseMarkdownDocument,
325
+ compileMarkdown,
326
+ parseMarkdown,
267
327
  buildDocxDocument,
268
328
  buildPdfDocument,
269
329
  buildHtmlDocument,
270
330
  Theme,
271
331
  } from "@masumdev/markforge";
272
332
 
273
- const markdownContent = fs.readFileSync("./report.md", "utf-8");
333
+ // High-level compilation to disk
334
+ const result = await compileMarkdown("./document.md", {
335
+ to: ["docx", "pdf", "html"],
336
+ outputDir: "./dist",
337
+ theme: Theme.CORPORATE,
338
+ });
274
339
 
275
- // 1. Parse Markdown into structured AST
276
- const doc = parseMarkdownDocument(markdownContent);
340
+ console.log("Compiled files:", result.outputFiles);
341
+ console.log("Duration:", result.durationMs, "ms");
277
342
 
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");
343
+ // Low-level in-memory AST compilation
344
+ const rawMarkdown = "# Executive Summary\n\nHigh-performance document engine.";
345
+ const doc = parseMarkdown(rawMarkdown);
346
+
347
+ const docxBuffer = await buildDocxDocument(doc, { theme: Theme.CORPORATE });
348
+ const pdfBuffer = await buildPdfDocument(doc, { theme: Theme.CORPORATE });
349
+ const htmlString = await buildHtmlDocument(doc, { theme: Theme.CORPORATE });
293
350
  ```
294
351
 
295
352
  ---
296
353
 
297
- ## 📄 License
354
+ ## License
298
355
 
299
- MIT © [Masum Dev](https://github.com/masumdev)
356
+ MIT License. Designed and maintained by **Ma'sum** ([@masumrpg](https://github.com/masumrpg)).