@masumdev/markforge 0.3.0 → 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/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,210 @@ 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
+ /**
220
+ * Custom text color for cover typography.
221
+ */
222
+ textColor?: string;
223
+ /**
224
+ * Custom footer notes at the bottom of the cover page.
225
+ */
226
+ footerText?: string;
227
+ }
228
+ type BackCoverPreset = "modern" | "corporate" | "minimal" | "contact-card";
229
+ interface BackCoverSocial {
230
+ github?: string;
231
+ twitter?: string;
232
+ linkedin?: string;
233
+ website?: string;
234
+ [key: string]: string | undefined;
235
+ }
236
+ interface BackCoverConfig {
237
+ /**
238
+ * Whether the standalone back cover / closing page is enabled.
239
+ * @default false
240
+ */
241
+ enabled?: boolean;
242
+ /**
243
+ * Visual layout preset for the back cover:
244
+ * - "modern": Accent colored background with centered logo, thank you typography, and contact footer.
245
+ * - "corporate": Navy/cyan split layout with comprehensive company details, legal notice, and social links.
246
+ * - "minimal": Clean white card with minimalist contact table and copyright line.
247
+ * - "contact-card": Floating elevated glassmorphic contact card with full metadata grid.
248
+ * @default "modern"
249
+ */
250
+ preset?: BackCoverPreset;
251
+ /**
252
+ * Headline title shown on the back cover.
253
+ * @default "Thank You"
254
+ */
255
+ title?: string;
256
+ /**
257
+ * Subtitle / closing statement shown on the back cover.
258
+ */
259
+ subtitle?: string;
260
+ /**
261
+ * Organization or company name (falls back to document company).
262
+ */
263
+ company?: string;
264
+ /**
265
+ * Office address or headquarters location.
266
+ */
267
+ address?: string;
268
+ /**
269
+ * Official contact email address.
270
+ */
271
+ email?: string;
272
+ /**
273
+ * Official contact phone number.
274
+ */
275
+ phone?: string;
276
+ /**
277
+ * Official company website URL.
278
+ */
279
+ website?: string;
280
+ /**
281
+ * Social media links dictionary (e.g. { github: "https://github.com/masumrpg", ... }).
282
+ */
283
+ social?: BackCoverSocial;
284
+ /**
285
+ * Copyright notice at the bottom (supports tokens like {company}, {date}, {year}).
286
+ */
287
+ copyright?: string;
288
+ /**
289
+ * Brand logo path, URL, or Base64 data URI.
290
+ */
291
+ logo?: string;
292
+ /**
293
+ * Logo width (e.g. 140, "140px", "3.5cm").
294
+ */
295
+ logoWidth?: number | string;
296
+ /**
297
+ * Status / confidentiality badge.
298
+ */
299
+ badge?: string;
300
+ /**
301
+ * Badge colors.
302
+ */
303
+ badgeColor?: string;
304
+ badgeTextColor?: string;
305
+ /**
306
+ * Custom CSS background gradient or solid hex color for the back cover.
307
+ */
308
+ bgGradient?: string;
309
+ /**
310
+ * Custom text color for back cover typography.
311
+ */
312
+ textColor?: string;
313
+ }
314
+ interface NumberHeadingsOptions {
315
+ /**
316
+ * Whether hierarchical heading numbering is enabled.
317
+ * @default true
318
+ */
319
+ enabled?: boolean;
320
+ /**
321
+ * Maximum heading level depth to number (e.g. 3 for H1..H3, 4 for H1..H4).
322
+ * @default 3
323
+ */
324
+ depth?: number;
325
+ /**
326
+ * Whether to skip numbering the main H1 document heading.
327
+ * @default false
328
+ */
329
+ skipH1?: boolean;
330
+ /**
331
+ * Custom prefix string prepended to all heading numbers.
332
+ * @default ""
333
+ */
334
+ prefix?: string;
335
+ }
336
+ type NumberHeadingsConfig = boolean | NumberHeadingsOptions;
337
+ interface PdfPermissions {
338
+ printing?: "highResolution" | "lowResolution" | "none" | boolean;
339
+ modifying?: boolean;
340
+ copying?: boolean;
341
+ annotating?: boolean;
342
+ fillingForms?: boolean;
343
+ contentAccessibility?: boolean;
344
+ documentAssembly?: boolean;
345
+ }
346
+ interface SecurityConfig {
347
+ /**
348
+ * Password required to open and view the document.
349
+ */
350
+ userPassword?: string;
351
+ /**
352
+ * Master password required to change document permissions.
353
+ */
354
+ ownerPassword?: string;
355
+ /**
356
+ * Granular permission restrictions on the PDF document.
357
+ */
358
+ permissions?: PdfPermissions;
359
+ }
154
360
  /**
155
361
  * Pure document metadata dictionary (author, title, date, version, etc.).
156
362
  */
@@ -162,7 +368,8 @@ interface DocumentMetadata {
162
368
  version?: string;
163
369
  company?: string;
164
370
  lang?: string;
165
- coverPage?: boolean;
371
+ coverPage?: boolean | CoverPageConfig;
372
+ backCover?: boolean | BackCoverConfig;
166
373
  [key: string]: unknown;
167
374
  }
168
375
  type SignatureAlign = "left" | "center" | "right" | "space-between";
@@ -288,6 +495,28 @@ interface DocumentLayoutConfig {
288
495
  * Path(s) to custom CSS stylesheets to inject into the document.
289
496
  */
290
497
  css?: string | string[];
498
+ /**
499
+ * Dedicated standalone Cover Page builder.
500
+ */
501
+ coverPage?: boolean | CoverPageConfig;
502
+ /**
503
+ * Dedicated standalone Back Cover / Closing Page builder.
504
+ */
505
+ backCover?: boolean | BackCoverConfig;
506
+ /**
507
+ * Hierarchical heading numbering (e.g. 1., 1.1, 1.1.1).
508
+ * @default false
509
+ */
510
+ numberHeadings?: NumberHeadingsConfig;
511
+ /**
512
+ * Document security and password protection for PDF outputs.
513
+ */
514
+ security?: SecurityConfig;
515
+ /**
516
+ * Whether LaTeX math equations ($inline$ and $$block$$) are parsed and rendered.
517
+ * @default true
518
+ */
519
+ math?: boolean;
291
520
  /**
292
521
  * Code syntax highlighting theme.
293
522
  * @default "github-dark"
@@ -372,9 +601,9 @@ declare function formatServerTimestamp(date?: Date): string;
372
601
  */
373
602
  declare function compileMarkdown(inputFilePathOrContent: string, userConfig?: MarkforgeConfig, onProgress?: (msg: string) => void): Promise<CompilationResult>;
374
603
 
375
- type MarkdownNodeType = "heading" | "paragraph" | "blockquote" | "callout" | "list" | "listItem" | "table" | "tableRow" | "tableCell" | "codeBlock" | "mermaid" | "htmlBlock" | "thematicBreak" | "image" | "toc";
604
+ type MarkdownNodeType = "heading" | "paragraph" | "blockquote" | "callout" | "list" | "listItem" | "table" | "tableRow" | "tableCell" | "codeBlock" | "mermaid" | "mathBlock" | "footnoteDef" | "columns" | "column" | "htmlBlock" | "thematicBreak" | "image" | "toc";
376
605
  interface MarkdownInlineSpan {
377
- type: "text" | "bold" | "italic" | "code" | "link" | "strikethrough" | "image" | "htmlInline";
606
+ type: "text" | "bold" | "italic" | "code" | "link" | "strikethrough" | "image" | "htmlInline" | "mathInline" | "footnoteRef";
378
607
  content: string;
379
608
  url?: string;
380
609
  title?: string;
@@ -383,6 +612,7 @@ interface MarkdownInlineSpan {
383
612
  height?: number | string;
384
613
  children?: MarkdownInlineSpan[];
385
614
  style?: Record<string, string>;
615
+ footnoteId?: string;
386
616
  }
387
617
  interface MarkdownASTNode {
388
618
  type: MarkdownNodeType;
@@ -399,6 +629,14 @@ interface MarkdownASTNode {
399
629
  rawHtml?: string;
400
630
  id?: string;
401
631
  style?: Record<string, string>;
632
+ columnsCount?: number;
633
+ columnGap?: string;
634
+ footnoteId?: string;
635
+ }
636
+ interface FootnoteDefinition {
637
+ id: string;
638
+ text: string;
639
+ inlines: MarkdownInlineSpan[];
402
640
  }
403
641
  interface ParsedMarkdownDocument {
404
642
  metadata: FrontmatterMetadata;
@@ -410,9 +648,10 @@ interface ParsedMarkdownDocument {
410
648
  level: number;
411
649
  }[];
412
650
  inlinedStyles: string[];
651
+ footnoteDefs: FootnoteDefinition[];
413
652
  }
414
653
  /**
415
- * Parses inline formatting (bold, italic, code, links, images, HTML spans)
654
+ * Parses inline formatting (bold, italic, code, links, images, math, footnotes, HTML spans)
416
655
  */
417
656
  declare function parseInlineSpans(text: string): MarkdownInlineSpan[];
418
657
  /**
@@ -433,124 +672,6 @@ declare function parseMarginToTwip(margin?: string | number, defaultTwip?: numbe
433
672
  */
434
673
  declare function buildDocxDocument(doc: ParsedMarkdownDocument, config: MarkforgeConfig, baseDir?: string): Promise<Buffer>;
435
674
 
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
675
  /**
555
676
  * Standard paper dimensions in Word Twips (1/20th of a point, 1440 twips = 1 inch).
556
677
  */
@@ -613,6 +734,63 @@ interface NormalizedSignatureBlock {
613
734
  spacingBefore: string;
614
735
  spacingBeforeTwip: number;
615
736
  }
737
+ interface NormalizedCoverPage {
738
+ enabled: boolean;
739
+ preset: "modern" | "corporate-split" | "minimal" | "card";
740
+ title: string;
741
+ subtitle?: string;
742
+ author?: string;
743
+ company?: string;
744
+ version?: string;
745
+ date?: string;
746
+ badge?: string;
747
+ badgeColor?: string;
748
+ badgeTextColor?: string;
749
+ logo?: string;
750
+ logoWidth?: number | string;
751
+ bgGradient?: string;
752
+ textColor?: string;
753
+ footerText?: string;
754
+ }
755
+ interface NormalizedBackCover {
756
+ enabled: boolean;
757
+ preset: "modern" | "corporate" | "minimal" | "contact-card";
758
+ title: string;
759
+ subtitle?: string;
760
+ company?: string;
761
+ address?: string;
762
+ email?: string;
763
+ phone?: string;
764
+ website?: string;
765
+ social?: Record<string, string>;
766
+ copyright?: string;
767
+ badge?: string;
768
+ badgeColor?: string;
769
+ badgeTextColor?: string;
770
+ logo?: string;
771
+ logoWidth?: number | string;
772
+ bgGradient?: string;
773
+ textColor?: string;
774
+ }
775
+ interface NormalizedNumberHeadings {
776
+ enabled: boolean;
777
+ depth: number;
778
+ skipH1: boolean;
779
+ prefix: string;
780
+ }
781
+ interface NormalizedSecurity {
782
+ userPassword?: string;
783
+ ownerPassword?: string;
784
+ permissions?: {
785
+ printing?: "highResolution" | "lowResolution" | "none";
786
+ modifying?: boolean;
787
+ copying?: boolean;
788
+ annotating?: boolean;
789
+ fillingForms?: boolean;
790
+ contentAccessibility?: boolean;
791
+ documentAssembly?: boolean;
792
+ };
793
+ }
616
794
  interface ResolvedDocumentConfig {
617
795
  title: string;
618
796
  subtitle?: string;
@@ -634,6 +812,11 @@ interface ResolvedDocumentConfig {
634
812
  toc: boolean;
635
813
  signatures?: NormalizedSignatureBlock;
636
814
  watermark?: NormalizedWatermark;
815
+ coverPage?: NormalizedCoverPage;
816
+ backCover?: NormalizedBackCover;
817
+ numberHeadings?: NormalizedNumberHeadings;
818
+ security?: NormalizedSecurity;
819
+ math: boolean;
637
820
  css: string[];
638
821
  embedImages: boolean;
639
822
  bundleHtml: boolean;
@@ -649,6 +832,8 @@ declare function replaceDocumentTokens(template: string | undefined, meta: {
649
832
  version?: string;
650
833
  date?: string;
651
834
  company?: string;
835
+ year?: string;
836
+ [key: string]: string | undefined;
652
837
  }): string;
653
838
  /**
654
839
  * Normalizes watermark configuration into a consistent structured object.
@@ -680,12 +865,210 @@ declare function normalizeHeaderFooter(raw: HeaderFooterItem | undefined, meta:
680
865
  * Normalizes signature and approval block configuration.
681
866
  */
682
867
  declare function normalizeSignatures(raw?: SignatureBlockConfig | SignatureItem[], meta?: Record<string, unknown>): NormalizedSignatureBlock | undefined;
868
+ /**
869
+ * Normalizes Cover Page configuration with token replacement.
870
+ */
871
+ declare function normalizeCoverPage(rawCover?: boolean | CoverPageConfig | Record<string, unknown>, tokenCtx?: {
872
+ title?: string;
873
+ subtitle?: string;
874
+ author?: string;
875
+ version?: string;
876
+ date?: string;
877
+ company?: string;
878
+ }): NormalizedCoverPage | undefined;
879
+ /**
880
+ * Normalizes Back Cover / Closing Page configuration with token replacement.
881
+ */
882
+ declare function normalizeBackCover(rawBack?: boolean | BackCoverConfig | Record<string, unknown>, tokenCtx?: {
883
+ title?: string;
884
+ subtitle?: string;
885
+ author?: string;
886
+ version?: string;
887
+ date?: string;
888
+ company?: string;
889
+ }): NormalizedBackCover | undefined;
890
+ /**
891
+ * Normalizes numberHeadings configuration.
892
+ */
893
+ declare function normalizeNumberHeadings(raw?: NumberHeadingsConfig | Record<string, unknown>): NormalizedNumberHeadings | undefined;
894
+ /**
895
+ * Normalizes security / PDF password encryption configuration.
896
+ */
897
+ declare function normalizeSecurity(raw?: SecurityConfig | Record<string, unknown>): NormalizedSecurity | undefined;
683
898
  /**
684
899
  * Centralized Single Source of Truth for resolving document configuration.
685
900
  * Priority hierarchy: Frontmatter metadata > Project Config File / User Config > DEFAULT_CONFIG
686
901
  */
687
902
  declare function resolveDocumentConfig(frontmatter?: Record<string, unknown>, userConfig?: MarkforgeConfig): ResolvedDocumentConfig;
688
903
 
904
+ /**
905
+ * Escapes HTML characters safely.
906
+ */
907
+ declare function escapeHtml(str: string): string;
908
+ /**
909
+ * Converts Markdown inline spans to HTML markup.
910
+ */
911
+ declare function renderInlinesToHtml(spans?: MarkdownInlineSpan[], baseDir?: string): Promise<string>;
912
+ /**
913
+ * Renders an AST node array to HTML.
914
+ */
915
+ declare function renderNodesToHtml(nodes: MarkdownASTNode[], resolved: ResolvedDocumentConfig, baseDir?: string): Promise<string>;
916
+ /**
917
+ * Renders the Cover Page HTML and returns { html, css }.
918
+ */
919
+ declare function renderCoverPageHtml(cover: NormalizedCoverPage, baseDir?: string): Promise<{
920
+ html: string;
921
+ css: string;
922
+ }>;
923
+ /**
924
+ * Renders the Back Cover / Closing Page HTML & CSS.
925
+ */
926
+ declare function renderBackCoverHtml(backCover: NormalizedBackCover, baseDir?: string): Promise<{
927
+ html: string;
928
+ css: string;
929
+ }>;
930
+ /**
931
+ * Builds standalone self-contained HTML from a parsed Markdown document.
932
+ */
933
+ declare function buildHtmlDocument(doc: ParsedMarkdownDocument, config: MarkforgeConfig, baseDir?: string): Promise<string>;
934
+
935
+ /**
936
+ * Finds available Chrome or Chromium binary for headless PDF rendering.
937
+ */
938
+ declare function findChromeExecutable(): string | null;
939
+ /**
940
+ * Injects CSS Paged Media styles into HTML for print & PDF formatting.
941
+ */
942
+ declare function injectPagedMediaStyles(html: string, config: MarkforgeConfig, metadata?: Record<string, unknown>): string;
943
+ /**
944
+ * Builds a true binary PDF document from parsed Markdown.
945
+ */
946
+ declare function buildPdfDocument(doc: ParsedMarkdownDocument, config: MarkforgeConfig, baseDir?: string): Promise<Buffer>;
947
+
948
+ interface ResolvedImage {
949
+ src: string;
950
+ buffer: Buffer;
951
+ mimeType: string;
952
+ width?: number;
953
+ height?: number;
954
+ dataUri: string;
955
+ isSvg: boolean;
956
+ }
957
+ /**
958
+ * Infers MIME type from file extension or data URI header.
959
+ */
960
+ declare function getMimeType(filePathOrUrl: string): string;
961
+ /**
962
+ * Resolves an image source (relative path, remote URL, or base64 data URI) into a binary buffer.
963
+ */
964
+ declare function resolveImage(src: string, baseDir?: string): Promise<ResolvedImage | null>;
965
+ /**
966
+ * Inlines all image sources in an HTML string with Base64 data URIs.
967
+ */
968
+ declare function inlineHtmlImages(html: string, baseDir?: string): Promise<string>;
969
+
970
+ /**
971
+ * MarkForge Syntax Highlighter Engine
972
+ * Provides tokenizer & styling for Markdown code blocks across DOCX, HTML, and PDF.
973
+ */
974
+ interface SyntaxToken {
975
+ text: string;
976
+ type: "keyword" | "string" | "comment" | "number" | "boolean" | "function" | "type" | "operator" | "punctuation" | "plain";
977
+ colorHex: string;
978
+ bold?: boolean;
979
+ italic?: boolean;
980
+ }
981
+ declare const SYNTAX_COLORS: {
982
+ keyword: string;
983
+ string: string;
984
+ comment: string;
985
+ number: string;
986
+ boolean: string;
987
+ function: string;
988
+ type: string;
989
+ operator: string;
990
+ punctuation: string;
991
+ plain: string;
992
+ };
993
+ declare function tokenizeCodeLine(line: string, lang?: string, theme?: string): SyntaxToken[];
994
+ /**
995
+ * Converts a code snippet to syntax-highlighted HTML with colored span tokens.
996
+ */
997
+ declare function highlightCodeToHtml(code: string, lang?: string, theme?: string): string;
998
+
999
+ /**
1000
+ * Renders Mermaid diagram definition into an SVG/PNG buffer for DOCX and HTML embedding.
1001
+ */
1002
+ declare function renderMermaidToPng(mermaidCode: string, _baseDir?: string): Promise<Buffer | null>;
1003
+
1004
+ /**
1005
+ * Renders a LaTeX math formula into clean HTML/MathML markup using KaTeX.
1006
+ */
1007
+ declare function renderMathToHtml(latex: string, displayMode?: boolean): string;
1008
+ /**
1009
+ * Minimal inlined KaTeX CSS required for rendering formulas without external network requests.
1010
+ */
1011
+ 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";
1012
+
1013
+ /**
1014
+ * Flagship corporate theme — full design system with Blu-by-BCA-Digital cyan palette.
1015
+ */
1016
+ 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";
1017
+ 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";
1018
+ declare const THEMES: Record<string, string>;
1019
+
1020
+ /**
1021
+ * Resolves theme CSS based on preset name or custom ThemeProps object.
1022
+ */
1023
+ declare function generateThemeCss(theme?: MarkforgeTheme): string;
1024
+
1025
+ interface PreviewServerOptions {
1026
+ filePath: string;
1027
+ port?: number;
1028
+ open?: boolean;
1029
+ config?: MarkforgeConfig;
1030
+ }
1031
+ interface PreviewServerInstance {
1032
+ server: http.Server;
1033
+ port: number;
1034
+ url: string;
1035
+ close: () => Promise<void>;
1036
+ }
1037
+ /**
1038
+ * Launches an interactive dual-pane Markdown Editor & Live-Reload Preview Server.
1039
+ * Left Pane: Code Editor with line numbers, shortcut triggers, auto-save, and formatting toolbar.
1040
+ * Right Pane: Real-time rendered document preview iframe with scroll preservation.
1041
+ */
1042
+ declare function startPreviewServer(options: PreviewServerOptions): Promise<PreviewServerInstance>;
1043
+
1044
+ /**
1045
+ * Type-safe configuration helper for markforge.config.ts
1046
+ */
1047
+ declare function defineConfig(config: MarkforgeConfig): MarkforgeConfig;
1048
+
1049
+ declare const DEFAULT_CONFIG: Required<Omit<MarkforgeConfig, "outputDir" | "css" | "margins" | "header" | "footer" | "watermark" | "metadata" | "syntaxTheme" | "signatures" | "coverPage" | "backCover" | "numberHeadings" | "security">> & {
1050
+ outputDir?: string;
1051
+ css?: string | string[];
1052
+ margins?: MarkforgeConfig["margins"];
1053
+ header?: MarkforgeConfig["header"];
1054
+ footer?: MarkforgeConfig["footer"];
1055
+ signatures?: MarkforgeConfig["signatures"];
1056
+ coverPage?: MarkforgeConfig["coverPage"];
1057
+ backCover?: MarkforgeConfig["backCover"];
1058
+ numberHeadings?: MarkforgeConfig["numberHeadings"];
1059
+ security?: MarkforgeConfig["security"];
1060
+ watermark?: string;
1061
+ metadata?: MarkforgeConfig["metadata"];
1062
+ syntaxTheme?: string;
1063
+ };
1064
+ /**
1065
+ * Resolves and loads markforge configuration from disk.
1066
+ */
1067
+ declare function loadConfig(customPath?: string, startDir?: string): Promise<{
1068
+ config: MarkforgeConfig;
1069
+ configPath: string | null;
1070
+ }>;
1071
+
689
1072
  /**
690
1073
  * Dynamically resolved version — reads from the nearest package.json at runtime.
691
1074
  * Falls back to the hardcoded FALLBACK_VERSION constant if not found.
@@ -696,4 +1079,4 @@ declare const MARKFORGE_VERSION: string;
696
1079
  */
697
1080
  declare function getMarkforgeVersion(fromDir?: string): string;
698
1081
 
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 };
1082
+ 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, 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 };