@masumdev/markforge 0.3.0 → 0.4.1

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/dist/index.d.mts CHANGED
@@ -1,3 +1,5 @@
1
+ import * as http from 'node:http';
2
+
1
3
  declare enum OutputFormat {
2
4
  DOCX = "docx",
3
5
  PDF = "pdf",
@@ -151,6 +153,243 @@ interface WatermarkOptions {
151
153
  rotate?: number;
152
154
  position?: "diagonal" | "center" | "top-right" | "bottom-right" | WatermarkPosition;
153
155
  }
156
+ declare enum CoverPagePreset {
157
+ MODERN = "modern",
158
+ CORPORATE_SPLIT = "corporate-split",
159
+ MINIMAL = "minimal",
160
+ CARD = "card"
161
+ }
162
+ type CoverPreset = "modern" | "corporate-split" | "minimal" | "card" | CoverPagePreset;
163
+ interface CoverPageConfig {
164
+ /**
165
+ * Whether the dedicated cover page is enabled.
166
+ * @default true
167
+ */
168
+ enabled?: boolean;
169
+ /**
170
+ * Cover page visual layout template.
171
+ * @default "modern"
172
+ */
173
+ preset?: CoverPreset;
174
+ /**
175
+ * Title shown on the cover page (falls back to document title).
176
+ */
177
+ title?: string;
178
+ /**
179
+ * Subtitle shown on the cover page (falls back to document subtitle).
180
+ */
181
+ subtitle?: string;
182
+ /**
183
+ * Author(s) shown on the cover page (falls back to document author).
184
+ */
185
+ author?: string | string[];
186
+ /**
187
+ * Organization / Company name shown on the cover page.
188
+ */
189
+ company?: string;
190
+ /**
191
+ * Document version shown on the cover page.
192
+ */
193
+ version?: string;
194
+ /**
195
+ * Date shown on the cover page (falls back to document date or current date).
196
+ */
197
+ date?: string | boolean;
198
+ /**
199
+ * Status / Confidentiality badge (e.g. "CONFIDENTIAL", "DRAFT", "TECHNICAL SPECIFICATION").
200
+ */
201
+ badge?: string;
202
+ /**
203
+ * Badge background and text colors.
204
+ */
205
+ badgeColor?: string;
206
+ badgeTextColor?: string;
207
+ /**
208
+ * Corporate logo image path, URL, or Base64 data URI.
209
+ */
210
+ logo?: string;
211
+ /**
212
+ * Width or height of the logo (e.g. 120, "120px", "3.5cm").
213
+ */
214
+ logoWidth?: number | string;
215
+ /**
216
+ * Custom background color or CSS gradient for the cover page.
217
+ */
218
+ bgGradient?: string;
219
+ backgroundColor?: string;
220
+ /**
221
+ * Custom typography colors.
222
+ */
223
+ textColor?: string;
224
+ titleColor?: string;
225
+ subtitleColor?: string;
226
+ accentColor?: string;
227
+ /**
228
+ * Contact details (for covers that render organization cards).
229
+ */
230
+ address?: string;
231
+ email?: string;
232
+ phone?: string;
233
+ website?: string;
234
+ social?: BackCoverSocial;
235
+ copyright?: string;
236
+ /**
237
+ * Custom footer notes at the bottom of the cover page.
238
+ */
239
+ footerText?: string;
240
+ }
241
+ type BackCoverPreset = "modern" | "corporate" | "minimal" | "contact-card";
242
+ interface BackCoverSocial {
243
+ github?: string;
244
+ twitter?: string;
245
+ linkedin?: string;
246
+ website?: string;
247
+ [key: string]: string | undefined;
248
+ }
249
+ interface BackCoverConfig {
250
+ /**
251
+ * Whether the standalone back cover / closing page is enabled.
252
+ * @default false
253
+ */
254
+ enabled?: boolean;
255
+ /**
256
+ * Visual layout preset for the back cover:
257
+ * - "modern": Accent colored background with centered logo, thank you typography, and contact footer.
258
+ * - "corporate": Navy/cyan split layout with comprehensive company details, legal notice, and social links.
259
+ * - "minimal": Clean white card with minimalist contact table and copyright line.
260
+ * - "contact-card": Floating elevated glassmorphic contact card with full metadata grid.
261
+ * @default "modern"
262
+ */
263
+ preset?: BackCoverPreset;
264
+ /**
265
+ * Headline title shown on the back cover.
266
+ * @default "Thank You"
267
+ */
268
+ title?: string;
269
+ /**
270
+ * Subtitle / closing statement shown on the back cover.
271
+ */
272
+ subtitle?: string;
273
+ /**
274
+ * Author / signatory shown on the closing page.
275
+ */
276
+ author?: string | string[];
277
+ /**
278
+ * Organization or company name (falls back to document company).
279
+ */
280
+ company?: string;
281
+ /**
282
+ * Document version shown on the back cover.
283
+ */
284
+ version?: string;
285
+ /**
286
+ * Date shown on the back cover.
287
+ */
288
+ date?: string | boolean;
289
+ /**
290
+ * Office address or headquarters location.
291
+ */
292
+ address?: string;
293
+ /**
294
+ * Official contact email address.
295
+ */
296
+ email?: string;
297
+ /**
298
+ * Official contact phone number.
299
+ */
300
+ phone?: string;
301
+ /**
302
+ * Official company website URL.
303
+ */
304
+ website?: string;
305
+ /**
306
+ * Social media links dictionary (e.g. { github: "https://github.com/masumrpg", ... }).
307
+ */
308
+ social?: BackCoverSocial;
309
+ /**
310
+ * Copyright notice at the bottom (supports tokens like {company}, {date}, {year}).
311
+ */
312
+ copyright?: string;
313
+ /**
314
+ * Custom footer text at the bottom.
315
+ */
316
+ footerText?: string;
317
+ /**
318
+ * Brand logo path, URL, or Base64 data URI.
319
+ */
320
+ logo?: string;
321
+ /**
322
+ * Logo width (e.g. 140, "140px", "3.5cm").
323
+ */
324
+ logoWidth?: number | string;
325
+ /**
326
+ * Status / confidentiality badge.
327
+ */
328
+ badge?: string;
329
+ /**
330
+ * Badge colors.
331
+ */
332
+ badgeColor?: string;
333
+ badgeTextColor?: string;
334
+ /**
335
+ * Custom CSS background gradient or solid hex color for the back cover.
336
+ */
337
+ bgGradient?: string;
338
+ backgroundColor?: string;
339
+ /**
340
+ * Custom typography colors.
341
+ */
342
+ textColor?: string;
343
+ titleColor?: string;
344
+ subtitleColor?: string;
345
+ accentColor?: string;
346
+ }
347
+ interface NumberHeadingsOptions {
348
+ /**
349
+ * Whether hierarchical heading numbering is enabled.
350
+ * @default true
351
+ */
352
+ enabled?: boolean;
353
+ /**
354
+ * Maximum heading level depth to number (e.g. 3 for H1..H3, 4 for H1..H4).
355
+ * @default 3
356
+ */
357
+ depth?: number;
358
+ /**
359
+ * Whether to skip numbering the main H1 document heading.
360
+ * @default false
361
+ */
362
+ skipH1?: boolean;
363
+ /**
364
+ * Custom prefix string prepended to all heading numbers.
365
+ * @default ""
366
+ */
367
+ prefix?: string;
368
+ }
369
+ type NumberHeadingsConfig = boolean | NumberHeadingsOptions;
370
+ interface PdfPermissions {
371
+ printing?: "highResolution" | "lowResolution" | "none" | boolean;
372
+ modifying?: boolean;
373
+ copying?: boolean;
374
+ annotating?: boolean;
375
+ fillingForms?: boolean;
376
+ contentAccessibility?: boolean;
377
+ documentAssembly?: boolean;
378
+ }
379
+ interface SecurityConfig {
380
+ /**
381
+ * Password required to open and view the document.
382
+ */
383
+ userPassword?: string;
384
+ /**
385
+ * Master password required to change document permissions.
386
+ */
387
+ ownerPassword?: string;
388
+ /**
389
+ * Granular permission restrictions on the PDF document.
390
+ */
391
+ permissions?: PdfPermissions;
392
+ }
154
393
  /**
155
394
  * Pure document metadata dictionary (author, title, date, version, etc.).
156
395
  */
@@ -162,7 +401,8 @@ interface DocumentMetadata {
162
401
  version?: string;
163
402
  company?: string;
164
403
  lang?: string;
165
- coverPage?: boolean;
404
+ coverPage?: boolean | CoverPageConfig;
405
+ backCover?: boolean | BackCoverConfig;
166
406
  [key: string]: unknown;
167
407
  }
168
408
  type SignatureAlign = "left" | "center" | "right" | "space-between";
@@ -288,6 +528,28 @@ interface DocumentLayoutConfig {
288
528
  * Path(s) to custom CSS stylesheets to inject into the document.
289
529
  */
290
530
  css?: string | string[];
531
+ /**
532
+ * Dedicated standalone Cover Page builder.
533
+ */
534
+ coverPage?: boolean | CoverPageConfig;
535
+ /**
536
+ * Dedicated standalone Back Cover / Closing Page builder.
537
+ */
538
+ backCover?: boolean | BackCoverConfig;
539
+ /**
540
+ * Hierarchical heading numbering (e.g. 1., 1.1, 1.1.1).
541
+ * @default false
542
+ */
543
+ numberHeadings?: NumberHeadingsConfig;
544
+ /**
545
+ * Document security and password protection for PDF outputs.
546
+ */
547
+ security?: SecurityConfig;
548
+ /**
549
+ * Whether LaTeX math equations ($inline$ and $$block$$) are parsed and rendered.
550
+ * @default true
551
+ */
552
+ math?: boolean;
291
553
  /**
292
554
  * Code syntax highlighting theme.
293
555
  * @default "github-dark"
@@ -372,9 +634,9 @@ declare function formatServerTimestamp(date?: Date): string;
372
634
  */
373
635
  declare function compileMarkdown(inputFilePathOrContent: string, userConfig?: MarkforgeConfig, onProgress?: (msg: string) => void): Promise<CompilationResult>;
374
636
 
375
- type MarkdownNodeType = "heading" | "paragraph" | "blockquote" | "callout" | "list" | "listItem" | "table" | "tableRow" | "tableCell" | "codeBlock" | "mermaid" | "htmlBlock" | "thematicBreak" | "image" | "toc";
637
+ type MarkdownNodeType = "heading" | "paragraph" | "blockquote" | "callout" | "list" | "listItem" | "table" | "tableRow" | "tableCell" | "codeBlock" | "mermaid" | "mathBlock" | "footnoteDef" | "columns" | "column" | "htmlBlock" | "thematicBreak" | "image" | "toc";
376
638
  interface MarkdownInlineSpan {
377
- type: "text" | "bold" | "italic" | "code" | "link" | "strikethrough" | "image" | "htmlInline";
639
+ type: "text" | "bold" | "italic" | "code" | "link" | "strikethrough" | "image" | "htmlInline" | "mathInline" | "footnoteRef";
378
640
  content: string;
379
641
  url?: string;
380
642
  title?: string;
@@ -383,6 +645,7 @@ interface MarkdownInlineSpan {
383
645
  height?: number | string;
384
646
  children?: MarkdownInlineSpan[];
385
647
  style?: Record<string, string>;
648
+ footnoteId?: string;
386
649
  }
387
650
  interface MarkdownASTNode {
388
651
  type: MarkdownNodeType;
@@ -399,6 +662,14 @@ interface MarkdownASTNode {
399
662
  rawHtml?: string;
400
663
  id?: string;
401
664
  style?: Record<string, string>;
665
+ columnsCount?: number;
666
+ columnGap?: string;
667
+ footnoteId?: string;
668
+ }
669
+ interface FootnoteDefinition {
670
+ id: string;
671
+ text: string;
672
+ inlines: MarkdownInlineSpan[];
402
673
  }
403
674
  interface ParsedMarkdownDocument {
404
675
  metadata: FrontmatterMetadata;
@@ -410,15 +681,24 @@ interface ParsedMarkdownDocument {
410
681
  level: number;
411
682
  }[];
412
683
  inlinedStyles: string[];
684
+ footnoteDefs: FootnoteDefinition[];
413
685
  }
414
686
  /**
415
- * Parses inline formatting (bold, italic, code, links, images, HTML spans)
687
+ * Parses inline formatting (bold, italic, code, links, images, math, footnotes, HTML spans)
416
688
  */
417
689
  declare function parseInlineSpans(text: string): MarkdownInlineSpan[];
418
690
  /**
419
691
  * Extracts slug from heading text for TOC & anchor links.
420
692
  */
421
693
  declare function slugify(text: string): string;
694
+ /**
695
+ * Applies hierarchical numbering to headings (e.g. "1.", "1.1.", "1.1.1.").
696
+ */
697
+ declare function applyHeadingNumbering(nodes: MarkdownASTNode[], tocEntries: {
698
+ id: string;
699
+ text: string;
700
+ level: number;
701
+ }[], options: NumberHeadingsOptions): void;
422
702
  /**
423
703
  * Parses raw markdown string into rich structured AST nodes.
424
704
  */
@@ -433,124 +713,6 @@ declare function parseMarginToTwip(margin?: string | number, defaultTwip?: numbe
433
713
  */
434
714
  declare function buildDocxDocument(doc: ParsedMarkdownDocument, config: MarkforgeConfig, baseDir?: string): Promise<Buffer>;
435
715
 
436
- /**
437
- * Escapes HTML characters safely.
438
- */
439
- declare function escapeHtml(str: string): string;
440
- /**
441
- * Converts Markdown inline spans to HTML markup.
442
- */
443
- declare function renderInlinesToHtml(spans?: MarkdownInlineSpan[], baseDir?: string): Promise<string>;
444
- /**
445
- * Builds standalone self-contained HTML from a parsed Markdown document.
446
- */
447
- declare function buildHtmlDocument(doc: ParsedMarkdownDocument, config: MarkforgeConfig, baseDir?: string): Promise<string>;
448
-
449
- /**
450
- * Finds available Chrome or Chromium binary for headless PDF rendering.
451
- */
452
- declare function findChromeExecutable(): string | null;
453
- /**
454
- * Injects CSS Paged Media styles into HTML for print & PDF formatting.
455
- */
456
- declare function injectPagedMediaStyles(html: string, config: MarkforgeConfig, metadata?: Record<string, unknown>): string;
457
- /**
458
- * Builds a true binary PDF document from parsed Markdown.
459
- */
460
- declare function buildPdfDocument(doc: ParsedMarkdownDocument, config: MarkforgeConfig, baseDir?: string): Promise<Buffer>;
461
-
462
- interface ResolvedImage {
463
- src: string;
464
- buffer: Buffer;
465
- mimeType: string;
466
- width?: number;
467
- height?: number;
468
- dataUri: string;
469
- isSvg: boolean;
470
- }
471
- /**
472
- * Infers MIME type from file extension or data URI header.
473
- */
474
- declare function getMimeType(filePathOrUrl: string): string;
475
- /**
476
- * Resolves an image source (relative path, remote URL, or base64 data URI) into a binary buffer.
477
- */
478
- declare function resolveImage(src: string, baseDir?: string): Promise<ResolvedImage | null>;
479
- /**
480
- * Inlines all image sources in an HTML string with Base64 data URIs.
481
- */
482
- declare function inlineHtmlImages(html: string, baseDir?: string): Promise<string>;
483
-
484
- /**
485
- * MarkForge Syntax Highlighter Engine
486
- * Provides tokenizer & styling for Markdown code blocks across DOCX, HTML, and PDF.
487
- */
488
- interface SyntaxToken {
489
- text: string;
490
- type: "keyword" | "string" | "comment" | "number" | "boolean" | "function" | "type" | "operator" | "punctuation" | "plain";
491
- colorHex: string;
492
- bold?: boolean;
493
- italic?: boolean;
494
- }
495
- declare const SYNTAX_COLORS: {
496
- keyword: string;
497
- string: string;
498
- comment: string;
499
- number: string;
500
- boolean: string;
501
- function: string;
502
- type: string;
503
- operator: string;
504
- punctuation: string;
505
- plain: string;
506
- };
507
- declare function tokenizeCodeLine(line: string, lang?: string, theme?: string): SyntaxToken[];
508
- /**
509
- * Converts a code snippet to syntax-highlighted HTML with colored span tokens.
510
- */
511
- declare function highlightCodeToHtml(code: string, lang?: string, theme?: string): string;
512
-
513
- /**
514
- * Renders Mermaid diagram definition into an SVG/PNG buffer for DOCX and HTML embedding.
515
- */
516
- declare function renderMermaidToPng(mermaidCode: string, _baseDir?: string): Promise<Buffer | null>;
517
-
518
- /**
519
- * Flagship corporate theme — full design system with Blu-by-BCA-Digital cyan palette.
520
- */
521
- declare const THEME_CORPORATE = "\n:root {\n --mf-bg: #ffffff;\n --mf-text: #0f172a;\n --mf-text-muted: #64748b;\n --mf-primary: #33CDCF;\n --mf-primary-dark: #009DA0;\n --mf-primary-light: #ECFDFD;\n --mf-border: #e2e8f0;\n --mf-card-bg: #f8fafc;\n --mf-code-bg: #0f172a;\n --mf-code-text: #f8fafc;\n --mf-font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif;\n --mf-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n}\nbody { background-color: var(--mf-bg); color: var(--mf-text); font-family: var(--mf-font-family); font-size: 15px; line-height: 1.65; margin: 0; padding: 2.5rem; }\n.document-container { max-width: 860px; margin: 0 auto; position: relative; z-index: 1; }\nh1, h2, h3, h4, h5, h6 { color: var(--mf-text); font-weight: 700; margin-top: 1.8rem; margin-bottom: 0.8rem; line-height: 1.25; }\nh1 { font-size: 2.2rem; border-bottom: 2px solid var(--mf-primary); padding-bottom: 0.5rem; }\nh2 { font-size: 1.6rem; color: var(--mf-primary-dark); border-bottom: 1px solid #CCFBF1; padding-bottom: 0.4rem; }\nh3 { font-size: 1.3rem; }\nh4 { font-size: 1.1rem; }\np { margin: 0.8rem 0; }\n";
522
- declare const THEME_DEFAULT = "\n:root {\n --mf-bg: #ffffff;\n --mf-text: #0f172a;\n --mf-text-muted: #64748b;\n --mf-primary: #33CDCF;\n --mf-primary-dark: #009DA0;\n --mf-primary-light: #ECFDFD;\n --mf-border: #e2e8f0;\n --mf-card-bg: #f8fafc;\n --mf-code-bg: #0f172a;\n --mf-code-text: #f8fafc;\n --mf-font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif;\n --mf-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n}\nbody { background-color: var(--mf-bg); color: var(--mf-text); font-family: var(--mf-font-family); font-size: 15px; line-height: 1.65; margin: 0; padding: 2.5rem; }\n.document-container { max-width: 860px; margin: 0 auto; position: relative; z-index: 1; }\nh1, h2, h3, h4, h5, h6 { color: var(--mf-text); font-weight: 700; margin-top: 1.8rem; margin-bottom: 0.8rem; line-height: 1.25; }\nh1 { font-size: 2.2rem; border-bottom: 2px solid var(--mf-primary); padding-bottom: 0.5rem; }\nh2 { font-size: 1.6rem; color: var(--mf-primary-dark); border-bottom: 1px solid #CCFBF1; padding-bottom: 0.4rem; }\nh3 { font-size: 1.3rem; }\nh4 { font-size: 1.1rem; }\np { margin: 0.8rem 0; }\n";
523
- declare const THEMES: Record<string, string>;
524
-
525
- /**
526
- * Resolves theme CSS based on preset name or custom ThemeProps object.
527
- */
528
- declare function generateThemeCss(theme?: MarkforgeTheme): string;
529
-
530
- /**
531
- * Type-safe configuration helper for markforge.config.ts
532
- */
533
- declare function defineConfig(config: MarkforgeConfig): MarkforgeConfig;
534
-
535
- declare const DEFAULT_CONFIG: Required<Omit<MarkforgeConfig, "outputDir" | "css" | "margins" | "header" | "footer" | "watermark" | "metadata" | "syntaxTheme" | "signatures">> & {
536
- outputDir?: string;
537
- css?: string | string[];
538
- margins?: MarkforgeConfig["margins"];
539
- header?: MarkforgeConfig["header"];
540
- footer?: MarkforgeConfig["footer"];
541
- signatures?: MarkforgeConfig["signatures"];
542
- watermark?: string;
543
- metadata?: MarkforgeConfig["metadata"];
544
- syntaxTheme?: string;
545
- };
546
- /**
547
- * Resolves and loads markforge configuration from disk.
548
- */
549
- declare function loadConfig(customPath?: string, startDir?: string): Promise<{
550
- config: MarkforgeConfig;
551
- configPath: string | null;
552
- }>;
553
-
554
716
  /**
555
717
  * Standard paper dimensions in Word Twips (1/20th of a point, 1440 twips = 1 inch).
556
718
  */
@@ -613,6 +775,81 @@ interface NormalizedSignatureBlock {
613
775
  spacingBefore: string;
614
776
  spacingBeforeTwip: number;
615
777
  }
778
+ interface NormalizedCoverPage {
779
+ enabled: boolean;
780
+ preset: "modern" | "corporate-split" | "minimal" | "card";
781
+ title: string;
782
+ subtitle?: string;
783
+ author?: string;
784
+ company?: string;
785
+ version?: string;
786
+ date?: string;
787
+ badge?: string;
788
+ badgeColor?: string;
789
+ badgeTextColor?: string;
790
+ logo?: string;
791
+ logoWidth?: number | string;
792
+ bgGradient?: string;
793
+ backgroundColor?: string;
794
+ textColor?: string;
795
+ titleColor?: string;
796
+ subtitleColor?: string;
797
+ accentColor?: string;
798
+ footerText?: string;
799
+ address?: string;
800
+ email?: string;
801
+ phone?: string;
802
+ website?: string;
803
+ social?: Record<string, string>;
804
+ copyright?: string;
805
+ }
806
+ interface NormalizedBackCover {
807
+ enabled: boolean;
808
+ preset: "modern" | "corporate" | "minimal" | "contact-card";
809
+ title: string;
810
+ subtitle?: string;
811
+ author?: string;
812
+ company?: string;
813
+ version?: string;
814
+ date?: string;
815
+ address?: string;
816
+ email?: string;
817
+ phone?: string;
818
+ website?: string;
819
+ social?: Record<string, string>;
820
+ copyright?: string;
821
+ footerText?: string;
822
+ badge?: string;
823
+ badgeColor?: string;
824
+ badgeTextColor?: string;
825
+ logo?: string;
826
+ logoWidth?: number | string;
827
+ bgGradient?: string;
828
+ backgroundColor?: string;
829
+ textColor?: string;
830
+ titleColor?: string;
831
+ subtitleColor?: string;
832
+ accentColor?: string;
833
+ }
834
+ interface NormalizedNumberHeadings {
835
+ enabled: boolean;
836
+ depth: number;
837
+ skipH1: boolean;
838
+ prefix: string;
839
+ }
840
+ interface NormalizedSecurity {
841
+ userPassword?: string;
842
+ ownerPassword?: string;
843
+ permissions?: {
844
+ printing?: "highResolution" | "lowResolution" | "none";
845
+ modifying?: boolean;
846
+ copying?: boolean;
847
+ annotating?: boolean;
848
+ fillingForms?: boolean;
849
+ contentAccessibility?: boolean;
850
+ documentAssembly?: boolean;
851
+ };
852
+ }
616
853
  interface ResolvedDocumentConfig {
617
854
  title: string;
618
855
  subtitle?: string;
@@ -634,26 +871,24 @@ interface ResolvedDocumentConfig {
634
871
  toc: boolean;
635
872
  signatures?: NormalizedSignatureBlock;
636
873
  watermark?: NormalizedWatermark;
874
+ coverPage?: NormalizedCoverPage;
875
+ backCover?: NormalizedBackCover;
876
+ numberHeadings?: NormalizedNumberHeadings;
877
+ security?: NormalizedSecurity;
878
+ math: boolean;
637
879
  css: string[];
638
880
  embedImages: boolean;
639
881
  bundleHtml: boolean;
640
882
  syntaxTheme: string;
641
883
  }
642
884
  /**
643
- * Replaces dynamic variables ({title}, {subtitle}, {author}, {version}, {date}, {company}) in text templates.
885
+ * Replaces dynamic variables ({title}, {subtitle}, {author}, {version}, {date}, {company}, {year}, and any custom metadata keys) in text templates.
644
886
  */
645
- declare function replaceDocumentTokens(template: string | undefined, meta: {
646
- title?: string;
647
- subtitle?: string;
648
- author?: string;
649
- version?: string;
650
- date?: string;
651
- company?: string;
652
- }): string;
887
+ declare function replaceDocumentTokens(template?: string, meta?: Record<string, unknown>): string;
653
888
  /**
654
- * Normalizes watermark configuration into a consistent structured object.
889
+ * Normalizes watermark configuration into a consistent structured object with dynamic token replacement.
655
890
  */
656
- declare function normalizeWatermark(rawWatermark?: string | WatermarkOptions | false): NormalizedWatermark | undefined;
891
+ declare function normalizeWatermark(rawWatermark?: string | WatermarkOptions | false, tokens?: Record<string, unknown>): NormalizedWatermark | undefined;
657
892
  /**
658
893
  * Normalizes an individual left, center, or right header/footer zone slot.
659
894
  */
@@ -680,6 +915,22 @@ declare function normalizeHeaderFooter(raw: HeaderFooterItem | undefined, meta:
680
915
  * Normalizes signature and approval block configuration.
681
916
  */
682
917
  declare function normalizeSignatures(raw?: SignatureBlockConfig | SignatureItem[], meta?: Record<string, unknown>): NormalizedSignatureBlock | undefined;
918
+ /**
919
+ * Normalizes Cover Page configuration with token replacement.
920
+ */
921
+ declare function normalizeCoverPage(rawCover?: boolean | CoverPageConfig | Record<string, unknown>, tokenCtx?: Record<string, unknown>): NormalizedCoverPage | undefined;
922
+ /**
923
+ * Normalizes Back Cover / Closing Page configuration with token replacement.
924
+ */
925
+ declare function normalizeBackCover(rawBack?: boolean | BackCoverConfig | Record<string, unknown>, tokenCtx?: Record<string, unknown>): NormalizedBackCover | undefined;
926
+ /**
927
+ * Normalizes numberHeadings configuration.
928
+ */
929
+ declare function normalizeNumberHeadings(raw?: NumberHeadingsConfig | Record<string, unknown>): NormalizedNumberHeadings | undefined;
930
+ /**
931
+ * Normalizes security / PDF password encryption configuration.
932
+ */
933
+ declare function normalizeSecurity(raw?: SecurityConfig | Record<string, unknown>): NormalizedSecurity | undefined;
683
934
  /**
684
935
  * Centralized Single Source of Truth for resolving document configuration.
685
936
  * Priority hierarchy: Frontmatter metadata > Project Config File / User Config > DEFAULT_CONFIG
@@ -687,8 +938,175 @@ declare function normalizeSignatures(raw?: SignatureBlockConfig | SignatureItem[
687
938
  declare function resolveDocumentConfig(frontmatter?: Record<string, unknown>, userConfig?: MarkforgeConfig): ResolvedDocumentConfig;
688
939
 
689
940
  /**
690
- * Dynamically resolved version — reads from the nearest package.json at runtime.
691
- * Falls back to the hardcoded FALLBACK_VERSION constant if not found.
941
+ * Escapes HTML characters safely.
942
+ */
943
+ declare function escapeHtml(str: string): string;
944
+ /**
945
+ * Renders inline Markdown spans (bold, italic, links, images, footnotes, math, etc.) to HTML with token replacement.
946
+ */
947
+ declare function renderInlinesToHtml(spans?: MarkdownInlineSpan[], baseDir?: string, tokens?: Record<string, unknown>): Promise<string>;
948
+ /**
949
+ * Renders an AST node array to HTML.
950
+ */
951
+ declare function renderNodesToHtml(nodes: MarkdownASTNode[], resolved: ResolvedDocumentConfig, baseDir?: string, tokens?: Record<string, unknown>): Promise<string>;
952
+ /**
953
+ * Renders the Cover Page HTML and returns { html, css }.
954
+ */
955
+ declare function renderCoverPageHtml(cover: NormalizedCoverPage, baseDir?: string): Promise<{
956
+ html: string;
957
+ css: string;
958
+ }>;
959
+ /**
960
+ * Renders the Back Cover / Closing Page HTML & CSS.
961
+ */
962
+ declare function renderBackCoverHtml(backCover: NormalizedBackCover, baseDir?: string): Promise<{
963
+ html: string;
964
+ css: string;
965
+ }>;
966
+ /**
967
+ * Builds standalone self-contained HTML from a parsed Markdown document.
968
+ */
969
+ declare function buildHtmlDocument(doc: ParsedMarkdownDocument, config: MarkforgeConfig, baseDir?: string): Promise<string>;
970
+
971
+ /**
972
+ * Finds available Chrome or Chromium binary for headless PDF rendering.
973
+ */
974
+ declare function findChromeExecutable(): string | null;
975
+ /**
976
+ * Injects CSS Paged Media styles into HTML for print & PDF formatting.
977
+ */
978
+ declare function injectPagedMediaStyles(html: string, config: MarkforgeConfig, metadata?: Record<string, unknown>): string;
979
+ /**
980
+ * Builds a true binary PDF document from parsed Markdown.
981
+ */
982
+ declare function buildPdfDocument(doc: ParsedMarkdownDocument, config: MarkforgeConfig, baseDir?: string): Promise<Buffer>;
983
+
984
+ interface ResolvedImage {
985
+ src: string;
986
+ buffer: Buffer;
987
+ mimeType: string;
988
+ width?: number;
989
+ height?: number;
990
+ dataUri: string;
991
+ isSvg: boolean;
992
+ }
993
+ /**
994
+ * Infers MIME type from file extension or data URI header.
995
+ */
996
+ declare function getMimeType(filePathOrUrl: string): string;
997
+ /**
998
+ * Resolves an image source (relative path, remote URL, or base64 data URI) into a binary buffer.
999
+ */
1000
+ declare function resolveImage(src: string, baseDir?: string): Promise<ResolvedImage | null>;
1001
+ /**
1002
+ * Inlines all image sources in an HTML string with Base64 data URIs.
1003
+ */
1004
+ declare function inlineHtmlImages(html: string, baseDir?: string): Promise<string>;
1005
+
1006
+ /**
1007
+ * MarkForge Syntax Highlighter Engine
1008
+ * Provides tokenizer & styling for Markdown code blocks across DOCX, HTML, and PDF.
1009
+ */
1010
+ interface SyntaxToken {
1011
+ text: string;
1012
+ type: "keyword" | "string" | "comment" | "number" | "boolean" | "function" | "type" | "operator" | "punctuation" | "plain";
1013
+ colorHex: string;
1014
+ bold?: boolean;
1015
+ italic?: boolean;
1016
+ }
1017
+ declare const SYNTAX_COLORS: {
1018
+ keyword: string;
1019
+ string: string;
1020
+ comment: string;
1021
+ number: string;
1022
+ boolean: string;
1023
+ function: string;
1024
+ type: string;
1025
+ operator: string;
1026
+ punctuation: string;
1027
+ plain: string;
1028
+ };
1029
+ declare function tokenizeCodeLine(line: string, lang?: string, theme?: string): SyntaxToken[];
1030
+ /**
1031
+ * Converts a code snippet to syntax-highlighted HTML with colored span tokens.
1032
+ */
1033
+ declare function highlightCodeToHtml(code: string, lang?: string, theme?: string): string;
1034
+
1035
+ /**
1036
+ * Renders Mermaid diagram definition into an SVG/PNG buffer for DOCX and HTML embedding.
1037
+ */
1038
+ declare function renderMermaidToPng(mermaidCode: string, _baseDir?: string): Promise<Buffer | null>;
1039
+
1040
+ /**
1041
+ * Renders a LaTeX math formula into clean HTML/MathML markup using KaTeX.
1042
+ */
1043
+ declare function renderMathToHtml(latex: string, displayMode?: boolean): string;
1044
+ /**
1045
+ * Minimal inlined KaTeX CSS required for rendering formulas without external network requests.
1046
+ */
1047
+ declare const KATEX_INLINE_CSS = "\n.katex { font: normal 1.21em KaTeX_Main, Times New Roman, serif; line-height: 1.2; text-indent: 0; text-rendering: auto; border-color: currentColor; }\n.katex * { -ms-high-contrast-adjust: none !important; }\n.katex .katex-html { display: inline-block; }\n.katex .katex-mathml { clip: rect(1px, 1px, 1px, 1px); border: 0; height: 1px; overflow: hidden; padding: 0; position: absolute; width: 1px; }\n.katex-display { display: block; margin: 1em 0; text-align: center; }\n.katex-display > .katex { display: inline-block; text-align: initial; }\n.katex .base { position: relative; white-space: nowrap; width: min-content; }\n.katex .strut { display: inline-block; }\n.katex .mord { display: inline-block; }\n.katex .mbin { display: inline-block; }\n.katex .mrel { display: inline-block; }\n.katex .mopen { display: inline-block; }\n.katex .mclose { display: inline-block; }\n.katex .mpunct { display: inline-block; }\n.katex .minner { display: inline-block; }\n.katex .mop { display: inline-block; }\n.katex .frac-line { width: 100%; border-bottom-style: solid; }\n.katex .vlist-t { display: inline-table; table-layout: fixed; }\n.katex .vlist-r { display: table-row; }\n.katex .vlist { display: table-cell; vertical-align: bottom; position: relative; }\n.katex .msupsub { text-align: left; }\n.katex .sqrt > .root { margin-left: 0.27777778em; margin-right: -0.55555556em; }\n";
1048
+
1049
+ /**
1050
+ * Flagship corporate theme — full design system with Blu-by-BCA-Digital cyan palette.
1051
+ */
1052
+ declare const THEME_CORPORATE = "\n:root {\n --mf-bg: #ffffff;\n --mf-text: #0f172a;\n --mf-text-muted: #64748b;\n --mf-primary: #33CDCF;\n --mf-primary-dark: #009DA0;\n --mf-primary-light: #ECFDFD;\n --mf-border: #e2e8f0;\n --mf-card-bg: #f8fafc;\n --mf-code-bg: #0f172a;\n --mf-code-text: #f8fafc;\n --mf-font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif;\n --mf-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n}\nbody { background-color: var(--mf-bg); color: var(--mf-text); font-family: var(--mf-font-family); font-size: 15px; line-height: 1.65; margin: 0; padding: 2.5rem; }\n.document-container { max-width: 860px; margin: 0 auto; position: relative; z-index: 1; }\nh1, h2, h3, h4, h5, h6 { color: var(--mf-primary-dark); font-weight: 700; margin-top: 1.8rem; margin-bottom: 0.8rem; line-height: 1.25; }\nh1 { font-size: 2.2rem; color: var(--mf-primary-dark); border-bottom: 2.5px solid var(--mf-primary); padding-bottom: 0.5rem; }\nh2 { font-size: 1.6rem; color: var(--mf-primary-dark); border-bottom: 1px solid #CCFBF1; padding-bottom: 0.4rem; }\nh3 { font-size: 1.3rem; color: var(--mf-primary-dark); }\nh4 { font-size: 1.1rem; color: var(--mf-primary-dark); }\nh5 { font-size: 1.0rem; color: var(--mf-primary-dark); }\nh6 { font-size: 0.9rem; color: var(--mf-primary-dark); }\np { margin: 0.8rem 0; }\n";
1053
+ declare const THEME_DEFAULT = "\n:root {\n --mf-bg: #ffffff;\n --mf-text: #0f172a;\n --mf-text-muted: #64748b;\n --mf-primary: #33CDCF;\n --mf-primary-dark: #009DA0;\n --mf-primary-light: #ECFDFD;\n --mf-border: #e2e8f0;\n --mf-card-bg: #f8fafc;\n --mf-code-bg: #0f172a;\n --mf-code-text: #f8fafc;\n --mf-font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif;\n --mf-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n}\nbody { background-color: var(--mf-bg); color: var(--mf-text); font-family: var(--mf-font-family); font-size: 15px; line-height: 1.65; margin: 0; padding: 2.5rem; }\n.document-container { max-width: 860px; margin: 0 auto; position: relative; z-index: 1; }\nh1, h2, h3, h4, h5, h6 { color: var(--mf-primary-dark); font-weight: 700; margin-top: 1.8rem; margin-bottom: 0.8rem; line-height: 1.25; }\nh1 { font-size: 2.2rem; color: var(--mf-primary-dark); border-bottom: 2.5px solid var(--mf-primary); padding-bottom: 0.5rem; }\nh2 { font-size: 1.6rem; color: var(--mf-primary-dark); border-bottom: 1px solid #CCFBF1; padding-bottom: 0.4rem; }\nh3 { font-size: 1.3rem; color: var(--mf-primary-dark); }\nh4 { font-size: 1.1rem; color: var(--mf-primary-dark); }\nh5 { font-size: 1.0rem; color: var(--mf-primary-dark); }\nh6 { font-size: 0.9rem; color: var(--mf-primary-dark); }\np { margin: 0.8rem 0; }\n";
1054
+ declare const THEMES: Record<string, string>;
1055
+
1056
+ /**
1057
+ * Resolves theme CSS based on preset name or custom ThemeProps object.
1058
+ */
1059
+ declare function generateThemeCss(theme?: MarkforgeTheme): string;
1060
+
1061
+ interface PreviewServerOptions {
1062
+ filePath: string;
1063
+ port?: number;
1064
+ open?: boolean;
1065
+ config?: MarkforgeConfig;
1066
+ }
1067
+ interface PreviewServerInstance {
1068
+ server: http.Server;
1069
+ port: number;
1070
+ url: string;
1071
+ close: () => Promise<void>;
1072
+ }
1073
+ /**
1074
+ * Launches an interactive dual-pane Markdown Editor & Live-Reload Preview Server.
1075
+ * Left Pane: Code Editor with line numbers, shortcut triggers, auto-save, and formatting toolbar.
1076
+ * Right Pane: Real-time rendered document preview iframe with scroll preservation.
1077
+ */
1078
+ declare function startPreviewServer(options: PreviewServerOptions): Promise<PreviewServerInstance>;
1079
+
1080
+ /**
1081
+ * Type-safe configuration helper for markforge.config.ts
1082
+ */
1083
+ declare function defineConfig(config: MarkforgeConfig): MarkforgeConfig;
1084
+
1085
+ declare const DEFAULT_CONFIG: Required<Omit<MarkforgeConfig, "outputDir" | "css" | "margins" | "header" | "footer" | "watermark" | "metadata" | "syntaxTheme" | "signatures" | "coverPage" | "backCover" | "numberHeadings" | "security">> & {
1086
+ outputDir?: string;
1087
+ css?: string | string[];
1088
+ margins?: MarkforgeConfig["margins"];
1089
+ header?: MarkforgeConfig["header"];
1090
+ footer?: MarkforgeConfig["footer"];
1091
+ signatures?: MarkforgeConfig["signatures"];
1092
+ coverPage?: MarkforgeConfig["coverPage"];
1093
+ backCover?: MarkforgeConfig["backCover"];
1094
+ numberHeadings?: MarkforgeConfig["numberHeadings"];
1095
+ security?: MarkforgeConfig["security"];
1096
+ watermark?: string;
1097
+ metadata?: MarkforgeConfig["metadata"];
1098
+ syntaxTheme?: string;
1099
+ };
1100
+ /**
1101
+ * Resolves and loads markforge configuration from disk.
1102
+ */
1103
+ declare function loadConfig(customPath?: string, startDir?: string): Promise<{
1104
+ config: MarkforgeConfig;
1105
+ configPath: string | null;
1106
+ }>;
1107
+
1108
+ /**
1109
+ * Dynamically resolved version — reads strictly from the nearest package.json at runtime.
692
1110
  */
693
1111
  declare const MARKFORGE_VERSION: string;
694
1112
  /**
@@ -696,4 +1114,4 @@ declare const MARKFORGE_VERSION: string;
696
1114
  */
697
1115
  declare function getMarkforgeVersion(fromDir?: string): string;
698
1116
 
699
- export { type CompilationResult, DEFAULT_CONFIG, type DocumentLayoutConfig, type DocumentMetadata, type DocumentOrientation, type FrontmatterMetadata, type GeneratedOutputFile, type HeaderFooterItem, type HeaderFooterSlot, MARKFORGE_VERSION, type MarkdownASTNode, type MarkdownInlineSpan, type MarkdownNodeType, type MarkforgeConfig, type MarkforgeFormat, type MarkforgeTheme, type NormalizedHeaderFooter, type NormalizedHeaderFooterZone, type NormalizedMargins, type NormalizedSignatureBlock, type NormalizedSignatureItem, type NormalizedWatermark, Orientation, OutputFormat, PAPER_DIMENSIONS_TWIP, type PageMargins, type PaperSize, PaperSizeEnum, type ParsedMarkdownDocument, type ResolvedDocumentConfig, type ResolvedImage, SYNTAX_COLORS, type SignatureAlign, type SignatureBlockConfig, type SignatureItem, type SignatureStyle, SyntaxTheme, type SyntaxToken, THEMES, THEME_CORPORATE, THEME_DEFAULT, Theme, type ThemeProps, type WatermarkOptions, WatermarkPosition, buildDocxDocument, buildHtmlDocument, buildPdfDocument, compileMarkdown, defineConfig, escapeHtml, findChromeExecutable, formatServerTimestamp, generateThemeCss, getMarkforgeVersion, getMimeType, highlightCodeToHtml, injectPagedMediaStyles, inlineHtmlImages, loadConfig, compileMarkdown as markforge, normalizeHeaderFooter, normalizeHeaderFooterSlot, normalizeSignatures, normalizeWatermark, parseInlineSpans, parseMarginToTwip, parseMarkdownDocument, renderInlinesToHtml, renderMermaidToPng, replaceDocumentTokens, resolveDocumentConfig, resolveImage, slugify, tokenizeCodeLine };
1117
+ export { type BackCoverConfig, type BackCoverPreset, type BackCoverSocial, type CompilationResult, type CoverPageConfig, CoverPagePreset, DEFAULT_CONFIG, type DocumentLayoutConfig, type DocumentMetadata, type DocumentOrientation, type FootnoteDefinition, type FrontmatterMetadata, type GeneratedOutputFile, type HeaderFooterItem, type HeaderFooterSlot, KATEX_INLINE_CSS, MARKFORGE_VERSION, type MarkdownASTNode, type MarkdownInlineSpan, type MarkdownNodeType, type MarkforgeConfig, type MarkforgeFormat, type MarkforgeTheme, type NormalizedBackCover, type NormalizedCoverPage, type NormalizedHeaderFooter, type NormalizedHeaderFooterZone, type NormalizedMargins, type NormalizedNumberHeadings, type NormalizedSecurity, type NormalizedSignatureBlock, type NormalizedSignatureItem, type NormalizedWatermark, type NumberHeadingsConfig, Orientation, OutputFormat, PAPER_DIMENSIONS_TWIP, type PageMargins, type PaperSize, PaperSizeEnum, type ParsedMarkdownDocument, type PdfPermissions, type PreviewServerInstance, type PreviewServerOptions, type ResolvedDocumentConfig, type ResolvedImage, SYNTAX_COLORS, type SecurityConfig, type SignatureAlign, type SignatureBlockConfig, type SignatureItem, type SignatureStyle, SyntaxTheme, type SyntaxToken, THEMES, THEME_CORPORATE, THEME_DEFAULT, Theme, type ThemeProps, type WatermarkOptions, WatermarkPosition, applyHeadingNumbering, buildDocxDocument, buildHtmlDocument, buildPdfDocument, compileMarkdown, defineConfig, escapeHtml, findChromeExecutable, formatServerTimestamp, generateThemeCss, getMarkforgeVersion, getMimeType, highlightCodeToHtml, injectPagedMediaStyles, inlineHtmlImages, loadConfig, compileMarkdown as markforge, normalizeBackCover, normalizeCoverPage, normalizeHeaderFooter, normalizeHeaderFooterSlot, normalizeNumberHeadings, normalizeSecurity, normalizeSignatures, normalizeWatermark, parseInlineSpans, parseMarginToTwip, parseMarkdownDocument as parseMarkdown, parseMarkdownDocument, renderBackCoverHtml, renderCoverPageHtml, renderInlinesToHtml, renderMathToHtml, renderMermaidToPng, renderNodesToHtml, replaceDocumentTokens, resolveDocumentConfig, resolveImage, slugify, startPreviewServer, tokenizeCodeLine };