@masumdev/markforge 0.1.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/LICENSE +21 -0
- package/README.md +308 -0
- package/dist/cli.mjs +2554 -0
- package/dist/index.d.mts +344 -0
- package/dist/index.d.ts +344 -0
- package/dist/index.js +2475 -0
- package/dist/index.mjs +2439 -0
- package/package.json +79 -0
- package/schema.json +116 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
type MarkforgeFormat = "docx" | "pdf" | "html" | "png";
|
|
2
|
+
type MarkforgeTheme = "default" | "academic" | "github" | "corporate" | "minimal" | "dracula" | (string & {});
|
|
3
|
+
type DocumentOrientation = "portrait" | "landscape";
|
|
4
|
+
type PaperSize = "A4" | "Letter" | "Legal" | "A3" | "A5";
|
|
5
|
+
interface PageMargins {
|
|
6
|
+
top?: string | number;
|
|
7
|
+
bottom?: string | number;
|
|
8
|
+
left?: string | number;
|
|
9
|
+
right?: string | number;
|
|
10
|
+
}
|
|
11
|
+
interface HeaderFooterItem {
|
|
12
|
+
left?: string;
|
|
13
|
+
center?: string;
|
|
14
|
+
right?: string;
|
|
15
|
+
font?: string;
|
|
16
|
+
size?: number;
|
|
17
|
+
color?: string;
|
|
18
|
+
divider?: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface WatermarkOptions {
|
|
21
|
+
text: string;
|
|
22
|
+
color?: string;
|
|
23
|
+
opacity?: number;
|
|
24
|
+
fontSize?: number;
|
|
25
|
+
rotate?: number;
|
|
26
|
+
position?: "diagonal" | "center" | "top-right" | "bottom-right";
|
|
27
|
+
}
|
|
28
|
+
interface FrontmatterMetadata {
|
|
29
|
+
title?: string;
|
|
30
|
+
subtitle?: string;
|
|
31
|
+
author?: string | string[];
|
|
32
|
+
date?: string;
|
|
33
|
+
version?: string;
|
|
34
|
+
theme?: MarkforgeTheme;
|
|
35
|
+
orientation?: DocumentOrientation;
|
|
36
|
+
paperSize?: PaperSize;
|
|
37
|
+
margins?: PageMargins;
|
|
38
|
+
header?: HeaderFooterItem;
|
|
39
|
+
footer?: HeaderFooterItem;
|
|
40
|
+
toc?: boolean;
|
|
41
|
+
watermark?: string | WatermarkOptions | false;
|
|
42
|
+
css?: string | string[];
|
|
43
|
+
coverPage?: boolean;
|
|
44
|
+
lang?: string;
|
|
45
|
+
[key: string]: unknown;
|
|
46
|
+
}
|
|
47
|
+
interface MarkforgeConfig {
|
|
48
|
+
/**
|
|
49
|
+
* Target format(s) to compile markdown to.
|
|
50
|
+
* @default ["docx", "pdf"]
|
|
51
|
+
*/
|
|
52
|
+
to?: MarkforgeFormat | MarkforgeFormat[];
|
|
53
|
+
/**
|
|
54
|
+
* Output directory where compiled documents will be saved.
|
|
55
|
+
* Defaults to the same directory as the input file.
|
|
56
|
+
*/
|
|
57
|
+
outputDir?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Built-in visual theme name.
|
|
60
|
+
* @default "default"
|
|
61
|
+
*/
|
|
62
|
+
theme?: MarkforgeTheme;
|
|
63
|
+
/**
|
|
64
|
+
* Path(s) to custom CSS stylesheets to inject into the document.
|
|
65
|
+
*/
|
|
66
|
+
css?: string | string[];
|
|
67
|
+
/**
|
|
68
|
+
* Page orientation.
|
|
69
|
+
* @default "portrait"
|
|
70
|
+
*/
|
|
71
|
+
orientation?: DocumentOrientation;
|
|
72
|
+
/**
|
|
73
|
+
* Paper size.
|
|
74
|
+
* @default "A4"
|
|
75
|
+
*/
|
|
76
|
+
paperSize?: PaperSize;
|
|
77
|
+
/**
|
|
78
|
+
* Custom page margins.
|
|
79
|
+
*/
|
|
80
|
+
margins?: PageMargins;
|
|
81
|
+
/**
|
|
82
|
+
* Header template configuration.
|
|
83
|
+
*/
|
|
84
|
+
header?: HeaderFooterItem;
|
|
85
|
+
/**
|
|
86
|
+
* Footer template configuration.
|
|
87
|
+
*/
|
|
88
|
+
footer?: HeaderFooterItem;
|
|
89
|
+
/**
|
|
90
|
+
* Whether to automatically generate a Table of Contents (TOC).
|
|
91
|
+
* @default false
|
|
92
|
+
*/
|
|
93
|
+
toc?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Optional watermark configuration to display across pages.
|
|
96
|
+
* By default, no watermark is displayed.
|
|
97
|
+
*/
|
|
98
|
+
watermark?: string | WatermarkOptions | false;
|
|
99
|
+
/**
|
|
100
|
+
* Whether to embed all images (local and remote) directly into the document.
|
|
101
|
+
* @default true
|
|
102
|
+
*/
|
|
103
|
+
embedImages?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Custom metadata overrides for title, author, date, etc.
|
|
106
|
+
*/
|
|
107
|
+
metadata?: Partial<FrontmatterMetadata>;
|
|
108
|
+
/**
|
|
109
|
+
* Watch files and automatically recompile on changes.
|
|
110
|
+
* @default false
|
|
111
|
+
*/
|
|
112
|
+
watch?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Start local HTTP preview server.
|
|
115
|
+
* @default false
|
|
116
|
+
*/
|
|
117
|
+
serve?: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Port for the local preview server.
|
|
120
|
+
* @default 4000
|
|
121
|
+
*/
|
|
122
|
+
port?: number;
|
|
123
|
+
/**
|
|
124
|
+
* Automatically open the document in the default browser upon compilation.
|
|
125
|
+
* @default false
|
|
126
|
+
*/
|
|
127
|
+
open?: boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Whether to generate standalone self-contained HTML bundle.
|
|
130
|
+
* @default true
|
|
131
|
+
*/
|
|
132
|
+
bundleHtml?: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Code syntax highlighting theme.
|
|
135
|
+
* @default "github-dark"
|
|
136
|
+
*/
|
|
137
|
+
syntaxTheme?: string;
|
|
138
|
+
}
|
|
139
|
+
interface GeneratedOutputFile {
|
|
140
|
+
format: MarkforgeFormat;
|
|
141
|
+
filePath: string;
|
|
142
|
+
fileName: string;
|
|
143
|
+
sizeBytes: number;
|
|
144
|
+
}
|
|
145
|
+
interface CompilationResult {
|
|
146
|
+
inputFile: string;
|
|
147
|
+
durationMs: number;
|
|
148
|
+
metadata: FrontmatterMetadata;
|
|
149
|
+
files: GeneratedOutputFile[];
|
|
150
|
+
errors: string[];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Formats local timestamp with timezone offset.
|
|
155
|
+
*/
|
|
156
|
+
declare function formatServerTimestamp(date?: Date): string;
|
|
157
|
+
/**
|
|
158
|
+
* Compiles a markdown or MDX file into the specified document formats.
|
|
159
|
+
*/
|
|
160
|
+
declare function compileMarkdown(inputFilePathOrContent: string, userConfig?: MarkforgeConfig, onProgress?: (msg: string) => void): Promise<CompilationResult>;
|
|
161
|
+
|
|
162
|
+
type MarkdownNodeType = "heading" | "paragraph" | "blockquote" | "callout" | "list" | "listItem" | "table" | "tableRow" | "tableCell" | "codeBlock" | "mermaid" | "htmlBlock" | "thematicBreak" | "image" | "toc";
|
|
163
|
+
interface MarkdownInlineSpan {
|
|
164
|
+
type: "text" | "bold" | "italic" | "code" | "link" | "strikethrough" | "image" | "htmlInline";
|
|
165
|
+
content: string;
|
|
166
|
+
url?: string;
|
|
167
|
+
title?: string;
|
|
168
|
+
alt?: string;
|
|
169
|
+
width?: number | string;
|
|
170
|
+
height?: number | string;
|
|
171
|
+
children?: MarkdownInlineSpan[];
|
|
172
|
+
style?: Record<string, string>;
|
|
173
|
+
}
|
|
174
|
+
interface MarkdownASTNode {
|
|
175
|
+
type: MarkdownNodeType;
|
|
176
|
+
level?: number;
|
|
177
|
+
ordered?: boolean;
|
|
178
|
+
checked?: boolean;
|
|
179
|
+
language?: string;
|
|
180
|
+
calloutType?: "NOTE" | "TIP" | "IMPORTANT" | "WARNING" | "CAUTION";
|
|
181
|
+
align?: ("left" | "center" | "right" | null)[];
|
|
182
|
+
isHeader?: boolean;
|
|
183
|
+
inlines?: MarkdownInlineSpan[];
|
|
184
|
+
text?: string;
|
|
185
|
+
children?: MarkdownASTNode[];
|
|
186
|
+
rawHtml?: string;
|
|
187
|
+
id?: string;
|
|
188
|
+
style?: Record<string, string>;
|
|
189
|
+
}
|
|
190
|
+
interface ParsedMarkdownDocument {
|
|
191
|
+
metadata: FrontmatterMetadata;
|
|
192
|
+
content: string;
|
|
193
|
+
nodes: MarkdownASTNode[];
|
|
194
|
+
tocEntries: {
|
|
195
|
+
id: string;
|
|
196
|
+
text: string;
|
|
197
|
+
level: number;
|
|
198
|
+
}[];
|
|
199
|
+
inlinedStyles: string[];
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Parses inline formatting (bold, italic, code, links, images, HTML spans)
|
|
203
|
+
*/
|
|
204
|
+
declare function parseInlineSpans(text: string): MarkdownInlineSpan[];
|
|
205
|
+
/**
|
|
206
|
+
* Extracts slug from heading text for TOC & anchor links.
|
|
207
|
+
*/
|
|
208
|
+
declare function slugify(text: string): string;
|
|
209
|
+
/**
|
|
210
|
+
* Parses raw markdown string into rich structured AST nodes.
|
|
211
|
+
*/
|
|
212
|
+
declare function parseMarkdownDocument(rawMarkdown: string): ParsedMarkdownDocument;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Converts CSS margin string (e.g. "2.5cm", "1in", "20mm", 1440) to Word Twips.
|
|
216
|
+
*/
|
|
217
|
+
declare function parseMarginToTwip(margin?: string | number, defaultTwip?: number): number;
|
|
218
|
+
/**
|
|
219
|
+
* Builds a complete docx.Document from a parsed Markdown document.
|
|
220
|
+
*/
|
|
221
|
+
declare function buildDocxDocument(doc: ParsedMarkdownDocument, config: MarkforgeConfig, baseDir?: string): Promise<Buffer>;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Escapes HTML characters safely.
|
|
225
|
+
*/
|
|
226
|
+
declare function escapeHtml(str: string): string;
|
|
227
|
+
/**
|
|
228
|
+
* Converts Markdown inline spans to HTML markup.
|
|
229
|
+
*/
|
|
230
|
+
declare function renderInlinesToHtml(spans?: MarkdownInlineSpan[], baseDir?: string): Promise<string>;
|
|
231
|
+
/**
|
|
232
|
+
* Builds standalone self-contained HTML from a parsed Markdown document.
|
|
233
|
+
*/
|
|
234
|
+
declare function buildHtmlDocument(doc: ParsedMarkdownDocument, config: MarkforgeConfig, baseDir?: string): Promise<string>;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Finds available Chrome or Chromium binary for headless PDF rendering.
|
|
238
|
+
*/
|
|
239
|
+
declare function findChromeExecutable(): string | null;
|
|
240
|
+
/**
|
|
241
|
+
* Injects CSS Paged Media styles into HTML for print & PDF formatting.
|
|
242
|
+
*/
|
|
243
|
+
declare function injectPagedMediaStyles(html: string, config: MarkforgeConfig, metadata?: Record<string, unknown>): string;
|
|
244
|
+
/**
|
|
245
|
+
* Builds a true binary PDF document from parsed Markdown.
|
|
246
|
+
*/
|
|
247
|
+
declare function buildPdfDocument(doc: ParsedMarkdownDocument, config: MarkforgeConfig, baseDir?: string): Promise<Buffer>;
|
|
248
|
+
|
|
249
|
+
interface ResolvedImage {
|
|
250
|
+
src: string;
|
|
251
|
+
buffer: Buffer;
|
|
252
|
+
mimeType: string;
|
|
253
|
+
width?: number;
|
|
254
|
+
height?: number;
|
|
255
|
+
dataUri: string;
|
|
256
|
+
isSvg: boolean;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Infers MIME type from file extension or data URI header.
|
|
260
|
+
*/
|
|
261
|
+
declare function getMimeType(filePathOrUrl: string): string;
|
|
262
|
+
/**
|
|
263
|
+
* Resolves an image source (relative path, remote URL, or base64 data URI) into a binary buffer.
|
|
264
|
+
*/
|
|
265
|
+
declare function resolveImage(src: string, baseDir?: string): Promise<ResolvedImage | null>;
|
|
266
|
+
/**
|
|
267
|
+
* Inlines all image sources in an HTML string with Base64 data URIs.
|
|
268
|
+
*/
|
|
269
|
+
declare function inlineHtmlImages(html: string, baseDir?: string): Promise<string>;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* MarkForge Syntax Highlighter Engine
|
|
273
|
+
* Provides tokenizer & styling for Markdown code blocks across DOCX, HTML, and PDF.
|
|
274
|
+
*/
|
|
275
|
+
interface SyntaxToken {
|
|
276
|
+
text: string;
|
|
277
|
+
type: "keyword" | "string" | "comment" | "number" | "boolean" | "function" | "type" | "operator" | "punctuation" | "plain";
|
|
278
|
+
colorHex: string;
|
|
279
|
+
bold?: boolean;
|
|
280
|
+
italic?: boolean;
|
|
281
|
+
}
|
|
282
|
+
declare const SYNTAX_COLORS: {
|
|
283
|
+
keyword: string;
|
|
284
|
+
string: string;
|
|
285
|
+
comment: string;
|
|
286
|
+
number: string;
|
|
287
|
+
boolean: string;
|
|
288
|
+
function: string;
|
|
289
|
+
type: string;
|
|
290
|
+
operator: string;
|
|
291
|
+
punctuation: string;
|
|
292
|
+
plain: string;
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Tokenizes a single line of code into styled tokens based on language.
|
|
296
|
+
*/
|
|
297
|
+
declare function tokenizeCodeLine(line: string, lang?: string, theme?: "dark" | "light"): SyntaxToken[];
|
|
298
|
+
/**
|
|
299
|
+
* Converts a code snippet to syntax-highlighted HTML with colored span tokens.
|
|
300
|
+
*/
|
|
301
|
+
declare function highlightCodeToHtml(code: string, lang?: string): string;
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Renders Mermaid diagram definition into an SVG/PNG buffer for DOCX and HTML embedding.
|
|
305
|
+
*/
|
|
306
|
+
declare function renderMermaidToPng(mermaidCode: string, _baseDir?: string): Promise<Buffer | null>;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Default theme — full design system with Blu-by-BCA-Digital cyan palette.
|
|
310
|
+
*/
|
|
311
|
+
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, Oxygen, Ubuntu, Cantarell, 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; }\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 #33CDCF; padding-bottom: 0.5rem; }\nh2 { font-size: 1.6rem; color: #009DA0; 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";
|
|
312
|
+
/**
|
|
313
|
+
* Academic theme — serif typography for formal papers/reports.
|
|
314
|
+
*/
|
|
315
|
+
declare const THEME_ACADEMIC = "\n:root {\n --mf-bg: #ffffff;\n --mf-text: #1a1a1a;\n --mf-text-muted: #555;\n --mf-primary: #33CDCF;\n --mf-primary-dark: #009DA0;\n --mf-primary-light: #ECFDFD;\n --mf-border: #ccc;\n --mf-card-bg: #f9f9f9;\n --mf-code-bg: #1e1e1e;\n --mf-code-text: #d4d4d4;\n --mf-font-family: \"Merriweather\", \"Georgia\", \"Times New Roman\", serif;\n --mf-font-mono: \"Courier New\", Courier, monospace;\n}\nbody { font-family: var(--mf-font-family); font-size: 16px; line-height: 1.8; padding: 3rem; color: var(--mf-text); }\n.document-container { max-width: 780px; margin: 0 auto; text-align: justify; }\nh1, h2, h3 { font-family: \"Times New Roman\", Times, serif; font-weight: bold; text-align: left; }\nh1 { font-size: 2rem; border-bottom: 1px solid #000; padding-bottom: 0.3rem; }\nh2 { font-size: 1.4rem; border-bottom: 1px solid #ccc; padding-bottom: 0.2rem; }\nh3 { font-size: 1.2rem; }\np { margin: 0.9rem 0; }\n";
|
|
316
|
+
declare const THEMES: Record<string, string>;
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Type-safe configuration helper for markforge.config.ts
|
|
320
|
+
*/
|
|
321
|
+
declare function defineConfig(config: MarkforgeConfig): MarkforgeConfig;
|
|
322
|
+
|
|
323
|
+
declare const DEFAULT_CONFIG: Required<Omit<MarkforgeConfig, "outputDir" | "css" | "margins" | "header" | "footer" | "watermark" | "metadata" | "syntaxTheme">> & {
|
|
324
|
+
outputDir?: string;
|
|
325
|
+
css?: string | string[];
|
|
326
|
+
margins?: MarkforgeConfig["margins"];
|
|
327
|
+
header?: MarkforgeConfig["header"];
|
|
328
|
+
footer?: MarkforgeConfig["footer"];
|
|
329
|
+
watermark?: string;
|
|
330
|
+
metadata?: MarkforgeConfig["metadata"];
|
|
331
|
+
syntaxTheme?: string;
|
|
332
|
+
};
|
|
333
|
+
/**
|
|
334
|
+
* Resolves and loads markforge configuration from disk.
|
|
335
|
+
*/
|
|
336
|
+
declare function loadConfig(customPath?: string, cwd?: string): Promise<{
|
|
337
|
+
config: MarkforgeConfig;
|
|
338
|
+
configPath: string | null;
|
|
339
|
+
}>;
|
|
340
|
+
|
|
341
|
+
declare const MARKFORGE_VERSION = "0.1.0";
|
|
342
|
+
declare function getMarkforgeVersion(fromDir?: string): string;
|
|
343
|
+
|
|
344
|
+
export { type CompilationResult, DEFAULT_CONFIG, type DocumentOrientation, type FrontmatterMetadata, type GeneratedOutputFile, type HeaderFooterItem, MARKFORGE_VERSION, type MarkdownASTNode, type MarkdownInlineSpan, type MarkdownNodeType, type MarkforgeConfig, type MarkforgeFormat, type MarkforgeTheme, type PageMargins, type PaperSize, type ParsedMarkdownDocument, type ResolvedImage, SYNTAX_COLORS, type SyntaxToken, THEMES, THEME_ACADEMIC, THEME_DEFAULT, type WatermarkOptions, buildDocxDocument, buildHtmlDocument, buildPdfDocument, compileMarkdown, defineConfig, escapeHtml, findChromeExecutable, formatServerTimestamp, getMarkforgeVersion, getMimeType, highlightCodeToHtml, injectPagedMediaStyles, inlineHtmlImages, loadConfig, compileMarkdown as markforge, parseInlineSpans, parseMarginToTwip, parseMarkdownDocument, renderInlinesToHtml, renderMermaidToPng, resolveImage, slugify, tokenizeCodeLine };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
type MarkforgeFormat = "docx" | "pdf" | "html" | "png";
|
|
2
|
+
type MarkforgeTheme = "default" | "academic" | "github" | "corporate" | "minimal" | "dracula" | (string & {});
|
|
3
|
+
type DocumentOrientation = "portrait" | "landscape";
|
|
4
|
+
type PaperSize = "A4" | "Letter" | "Legal" | "A3" | "A5";
|
|
5
|
+
interface PageMargins {
|
|
6
|
+
top?: string | number;
|
|
7
|
+
bottom?: string | number;
|
|
8
|
+
left?: string | number;
|
|
9
|
+
right?: string | number;
|
|
10
|
+
}
|
|
11
|
+
interface HeaderFooterItem {
|
|
12
|
+
left?: string;
|
|
13
|
+
center?: string;
|
|
14
|
+
right?: string;
|
|
15
|
+
font?: string;
|
|
16
|
+
size?: number;
|
|
17
|
+
color?: string;
|
|
18
|
+
divider?: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface WatermarkOptions {
|
|
21
|
+
text: string;
|
|
22
|
+
color?: string;
|
|
23
|
+
opacity?: number;
|
|
24
|
+
fontSize?: number;
|
|
25
|
+
rotate?: number;
|
|
26
|
+
position?: "diagonal" | "center" | "top-right" | "bottom-right";
|
|
27
|
+
}
|
|
28
|
+
interface FrontmatterMetadata {
|
|
29
|
+
title?: string;
|
|
30
|
+
subtitle?: string;
|
|
31
|
+
author?: string | string[];
|
|
32
|
+
date?: string;
|
|
33
|
+
version?: string;
|
|
34
|
+
theme?: MarkforgeTheme;
|
|
35
|
+
orientation?: DocumentOrientation;
|
|
36
|
+
paperSize?: PaperSize;
|
|
37
|
+
margins?: PageMargins;
|
|
38
|
+
header?: HeaderFooterItem;
|
|
39
|
+
footer?: HeaderFooterItem;
|
|
40
|
+
toc?: boolean;
|
|
41
|
+
watermark?: string | WatermarkOptions | false;
|
|
42
|
+
css?: string | string[];
|
|
43
|
+
coverPage?: boolean;
|
|
44
|
+
lang?: string;
|
|
45
|
+
[key: string]: unknown;
|
|
46
|
+
}
|
|
47
|
+
interface MarkforgeConfig {
|
|
48
|
+
/**
|
|
49
|
+
* Target format(s) to compile markdown to.
|
|
50
|
+
* @default ["docx", "pdf"]
|
|
51
|
+
*/
|
|
52
|
+
to?: MarkforgeFormat | MarkforgeFormat[];
|
|
53
|
+
/**
|
|
54
|
+
* Output directory where compiled documents will be saved.
|
|
55
|
+
* Defaults to the same directory as the input file.
|
|
56
|
+
*/
|
|
57
|
+
outputDir?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Built-in visual theme name.
|
|
60
|
+
* @default "default"
|
|
61
|
+
*/
|
|
62
|
+
theme?: MarkforgeTheme;
|
|
63
|
+
/**
|
|
64
|
+
* Path(s) to custom CSS stylesheets to inject into the document.
|
|
65
|
+
*/
|
|
66
|
+
css?: string | string[];
|
|
67
|
+
/**
|
|
68
|
+
* Page orientation.
|
|
69
|
+
* @default "portrait"
|
|
70
|
+
*/
|
|
71
|
+
orientation?: DocumentOrientation;
|
|
72
|
+
/**
|
|
73
|
+
* Paper size.
|
|
74
|
+
* @default "A4"
|
|
75
|
+
*/
|
|
76
|
+
paperSize?: PaperSize;
|
|
77
|
+
/**
|
|
78
|
+
* Custom page margins.
|
|
79
|
+
*/
|
|
80
|
+
margins?: PageMargins;
|
|
81
|
+
/**
|
|
82
|
+
* Header template configuration.
|
|
83
|
+
*/
|
|
84
|
+
header?: HeaderFooterItem;
|
|
85
|
+
/**
|
|
86
|
+
* Footer template configuration.
|
|
87
|
+
*/
|
|
88
|
+
footer?: HeaderFooterItem;
|
|
89
|
+
/**
|
|
90
|
+
* Whether to automatically generate a Table of Contents (TOC).
|
|
91
|
+
* @default false
|
|
92
|
+
*/
|
|
93
|
+
toc?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Optional watermark configuration to display across pages.
|
|
96
|
+
* By default, no watermark is displayed.
|
|
97
|
+
*/
|
|
98
|
+
watermark?: string | WatermarkOptions | false;
|
|
99
|
+
/**
|
|
100
|
+
* Whether to embed all images (local and remote) directly into the document.
|
|
101
|
+
* @default true
|
|
102
|
+
*/
|
|
103
|
+
embedImages?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Custom metadata overrides for title, author, date, etc.
|
|
106
|
+
*/
|
|
107
|
+
metadata?: Partial<FrontmatterMetadata>;
|
|
108
|
+
/**
|
|
109
|
+
* Watch files and automatically recompile on changes.
|
|
110
|
+
* @default false
|
|
111
|
+
*/
|
|
112
|
+
watch?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Start local HTTP preview server.
|
|
115
|
+
* @default false
|
|
116
|
+
*/
|
|
117
|
+
serve?: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Port for the local preview server.
|
|
120
|
+
* @default 4000
|
|
121
|
+
*/
|
|
122
|
+
port?: number;
|
|
123
|
+
/**
|
|
124
|
+
* Automatically open the document in the default browser upon compilation.
|
|
125
|
+
* @default false
|
|
126
|
+
*/
|
|
127
|
+
open?: boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Whether to generate standalone self-contained HTML bundle.
|
|
130
|
+
* @default true
|
|
131
|
+
*/
|
|
132
|
+
bundleHtml?: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Code syntax highlighting theme.
|
|
135
|
+
* @default "github-dark"
|
|
136
|
+
*/
|
|
137
|
+
syntaxTheme?: string;
|
|
138
|
+
}
|
|
139
|
+
interface GeneratedOutputFile {
|
|
140
|
+
format: MarkforgeFormat;
|
|
141
|
+
filePath: string;
|
|
142
|
+
fileName: string;
|
|
143
|
+
sizeBytes: number;
|
|
144
|
+
}
|
|
145
|
+
interface CompilationResult {
|
|
146
|
+
inputFile: string;
|
|
147
|
+
durationMs: number;
|
|
148
|
+
metadata: FrontmatterMetadata;
|
|
149
|
+
files: GeneratedOutputFile[];
|
|
150
|
+
errors: string[];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Formats local timestamp with timezone offset.
|
|
155
|
+
*/
|
|
156
|
+
declare function formatServerTimestamp(date?: Date): string;
|
|
157
|
+
/**
|
|
158
|
+
* Compiles a markdown or MDX file into the specified document formats.
|
|
159
|
+
*/
|
|
160
|
+
declare function compileMarkdown(inputFilePathOrContent: string, userConfig?: MarkforgeConfig, onProgress?: (msg: string) => void): Promise<CompilationResult>;
|
|
161
|
+
|
|
162
|
+
type MarkdownNodeType = "heading" | "paragraph" | "blockquote" | "callout" | "list" | "listItem" | "table" | "tableRow" | "tableCell" | "codeBlock" | "mermaid" | "htmlBlock" | "thematicBreak" | "image" | "toc";
|
|
163
|
+
interface MarkdownInlineSpan {
|
|
164
|
+
type: "text" | "bold" | "italic" | "code" | "link" | "strikethrough" | "image" | "htmlInline";
|
|
165
|
+
content: string;
|
|
166
|
+
url?: string;
|
|
167
|
+
title?: string;
|
|
168
|
+
alt?: string;
|
|
169
|
+
width?: number | string;
|
|
170
|
+
height?: number | string;
|
|
171
|
+
children?: MarkdownInlineSpan[];
|
|
172
|
+
style?: Record<string, string>;
|
|
173
|
+
}
|
|
174
|
+
interface MarkdownASTNode {
|
|
175
|
+
type: MarkdownNodeType;
|
|
176
|
+
level?: number;
|
|
177
|
+
ordered?: boolean;
|
|
178
|
+
checked?: boolean;
|
|
179
|
+
language?: string;
|
|
180
|
+
calloutType?: "NOTE" | "TIP" | "IMPORTANT" | "WARNING" | "CAUTION";
|
|
181
|
+
align?: ("left" | "center" | "right" | null)[];
|
|
182
|
+
isHeader?: boolean;
|
|
183
|
+
inlines?: MarkdownInlineSpan[];
|
|
184
|
+
text?: string;
|
|
185
|
+
children?: MarkdownASTNode[];
|
|
186
|
+
rawHtml?: string;
|
|
187
|
+
id?: string;
|
|
188
|
+
style?: Record<string, string>;
|
|
189
|
+
}
|
|
190
|
+
interface ParsedMarkdownDocument {
|
|
191
|
+
metadata: FrontmatterMetadata;
|
|
192
|
+
content: string;
|
|
193
|
+
nodes: MarkdownASTNode[];
|
|
194
|
+
tocEntries: {
|
|
195
|
+
id: string;
|
|
196
|
+
text: string;
|
|
197
|
+
level: number;
|
|
198
|
+
}[];
|
|
199
|
+
inlinedStyles: string[];
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Parses inline formatting (bold, italic, code, links, images, HTML spans)
|
|
203
|
+
*/
|
|
204
|
+
declare function parseInlineSpans(text: string): MarkdownInlineSpan[];
|
|
205
|
+
/**
|
|
206
|
+
* Extracts slug from heading text for TOC & anchor links.
|
|
207
|
+
*/
|
|
208
|
+
declare function slugify(text: string): string;
|
|
209
|
+
/**
|
|
210
|
+
* Parses raw markdown string into rich structured AST nodes.
|
|
211
|
+
*/
|
|
212
|
+
declare function parseMarkdownDocument(rawMarkdown: string): ParsedMarkdownDocument;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Converts CSS margin string (e.g. "2.5cm", "1in", "20mm", 1440) to Word Twips.
|
|
216
|
+
*/
|
|
217
|
+
declare function parseMarginToTwip(margin?: string | number, defaultTwip?: number): number;
|
|
218
|
+
/**
|
|
219
|
+
* Builds a complete docx.Document from a parsed Markdown document.
|
|
220
|
+
*/
|
|
221
|
+
declare function buildDocxDocument(doc: ParsedMarkdownDocument, config: MarkforgeConfig, baseDir?: string): Promise<Buffer>;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Escapes HTML characters safely.
|
|
225
|
+
*/
|
|
226
|
+
declare function escapeHtml(str: string): string;
|
|
227
|
+
/**
|
|
228
|
+
* Converts Markdown inline spans to HTML markup.
|
|
229
|
+
*/
|
|
230
|
+
declare function renderInlinesToHtml(spans?: MarkdownInlineSpan[], baseDir?: string): Promise<string>;
|
|
231
|
+
/**
|
|
232
|
+
* Builds standalone self-contained HTML from a parsed Markdown document.
|
|
233
|
+
*/
|
|
234
|
+
declare function buildHtmlDocument(doc: ParsedMarkdownDocument, config: MarkforgeConfig, baseDir?: string): Promise<string>;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Finds available Chrome or Chromium binary for headless PDF rendering.
|
|
238
|
+
*/
|
|
239
|
+
declare function findChromeExecutable(): string | null;
|
|
240
|
+
/**
|
|
241
|
+
* Injects CSS Paged Media styles into HTML for print & PDF formatting.
|
|
242
|
+
*/
|
|
243
|
+
declare function injectPagedMediaStyles(html: string, config: MarkforgeConfig, metadata?: Record<string, unknown>): string;
|
|
244
|
+
/**
|
|
245
|
+
* Builds a true binary PDF document from parsed Markdown.
|
|
246
|
+
*/
|
|
247
|
+
declare function buildPdfDocument(doc: ParsedMarkdownDocument, config: MarkforgeConfig, baseDir?: string): Promise<Buffer>;
|
|
248
|
+
|
|
249
|
+
interface ResolvedImage {
|
|
250
|
+
src: string;
|
|
251
|
+
buffer: Buffer;
|
|
252
|
+
mimeType: string;
|
|
253
|
+
width?: number;
|
|
254
|
+
height?: number;
|
|
255
|
+
dataUri: string;
|
|
256
|
+
isSvg: boolean;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Infers MIME type from file extension or data URI header.
|
|
260
|
+
*/
|
|
261
|
+
declare function getMimeType(filePathOrUrl: string): string;
|
|
262
|
+
/**
|
|
263
|
+
* Resolves an image source (relative path, remote URL, or base64 data URI) into a binary buffer.
|
|
264
|
+
*/
|
|
265
|
+
declare function resolveImage(src: string, baseDir?: string): Promise<ResolvedImage | null>;
|
|
266
|
+
/**
|
|
267
|
+
* Inlines all image sources in an HTML string with Base64 data URIs.
|
|
268
|
+
*/
|
|
269
|
+
declare function inlineHtmlImages(html: string, baseDir?: string): Promise<string>;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* MarkForge Syntax Highlighter Engine
|
|
273
|
+
* Provides tokenizer & styling for Markdown code blocks across DOCX, HTML, and PDF.
|
|
274
|
+
*/
|
|
275
|
+
interface SyntaxToken {
|
|
276
|
+
text: string;
|
|
277
|
+
type: "keyword" | "string" | "comment" | "number" | "boolean" | "function" | "type" | "operator" | "punctuation" | "plain";
|
|
278
|
+
colorHex: string;
|
|
279
|
+
bold?: boolean;
|
|
280
|
+
italic?: boolean;
|
|
281
|
+
}
|
|
282
|
+
declare const SYNTAX_COLORS: {
|
|
283
|
+
keyword: string;
|
|
284
|
+
string: string;
|
|
285
|
+
comment: string;
|
|
286
|
+
number: string;
|
|
287
|
+
boolean: string;
|
|
288
|
+
function: string;
|
|
289
|
+
type: string;
|
|
290
|
+
operator: string;
|
|
291
|
+
punctuation: string;
|
|
292
|
+
plain: string;
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Tokenizes a single line of code into styled tokens based on language.
|
|
296
|
+
*/
|
|
297
|
+
declare function tokenizeCodeLine(line: string, lang?: string, theme?: "dark" | "light"): SyntaxToken[];
|
|
298
|
+
/**
|
|
299
|
+
* Converts a code snippet to syntax-highlighted HTML with colored span tokens.
|
|
300
|
+
*/
|
|
301
|
+
declare function highlightCodeToHtml(code: string, lang?: string): string;
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Renders Mermaid diagram definition into an SVG/PNG buffer for DOCX and HTML embedding.
|
|
305
|
+
*/
|
|
306
|
+
declare function renderMermaidToPng(mermaidCode: string, _baseDir?: string): Promise<Buffer | null>;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Default theme — full design system with Blu-by-BCA-Digital cyan palette.
|
|
310
|
+
*/
|
|
311
|
+
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, Oxygen, Ubuntu, Cantarell, 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; }\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 #33CDCF; padding-bottom: 0.5rem; }\nh2 { font-size: 1.6rem; color: #009DA0; 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";
|
|
312
|
+
/**
|
|
313
|
+
* Academic theme — serif typography for formal papers/reports.
|
|
314
|
+
*/
|
|
315
|
+
declare const THEME_ACADEMIC = "\n:root {\n --mf-bg: #ffffff;\n --mf-text: #1a1a1a;\n --mf-text-muted: #555;\n --mf-primary: #33CDCF;\n --mf-primary-dark: #009DA0;\n --mf-primary-light: #ECFDFD;\n --mf-border: #ccc;\n --mf-card-bg: #f9f9f9;\n --mf-code-bg: #1e1e1e;\n --mf-code-text: #d4d4d4;\n --mf-font-family: \"Merriweather\", \"Georgia\", \"Times New Roman\", serif;\n --mf-font-mono: \"Courier New\", Courier, monospace;\n}\nbody { font-family: var(--mf-font-family); font-size: 16px; line-height: 1.8; padding: 3rem; color: var(--mf-text); }\n.document-container { max-width: 780px; margin: 0 auto; text-align: justify; }\nh1, h2, h3 { font-family: \"Times New Roman\", Times, serif; font-weight: bold; text-align: left; }\nh1 { font-size: 2rem; border-bottom: 1px solid #000; padding-bottom: 0.3rem; }\nh2 { font-size: 1.4rem; border-bottom: 1px solid #ccc; padding-bottom: 0.2rem; }\nh3 { font-size: 1.2rem; }\np { margin: 0.9rem 0; }\n";
|
|
316
|
+
declare const THEMES: Record<string, string>;
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Type-safe configuration helper for markforge.config.ts
|
|
320
|
+
*/
|
|
321
|
+
declare function defineConfig(config: MarkforgeConfig): MarkforgeConfig;
|
|
322
|
+
|
|
323
|
+
declare const DEFAULT_CONFIG: Required<Omit<MarkforgeConfig, "outputDir" | "css" | "margins" | "header" | "footer" | "watermark" | "metadata" | "syntaxTheme">> & {
|
|
324
|
+
outputDir?: string;
|
|
325
|
+
css?: string | string[];
|
|
326
|
+
margins?: MarkforgeConfig["margins"];
|
|
327
|
+
header?: MarkforgeConfig["header"];
|
|
328
|
+
footer?: MarkforgeConfig["footer"];
|
|
329
|
+
watermark?: string;
|
|
330
|
+
metadata?: MarkforgeConfig["metadata"];
|
|
331
|
+
syntaxTheme?: string;
|
|
332
|
+
};
|
|
333
|
+
/**
|
|
334
|
+
* Resolves and loads markforge configuration from disk.
|
|
335
|
+
*/
|
|
336
|
+
declare function loadConfig(customPath?: string, cwd?: string): Promise<{
|
|
337
|
+
config: MarkforgeConfig;
|
|
338
|
+
configPath: string | null;
|
|
339
|
+
}>;
|
|
340
|
+
|
|
341
|
+
declare const MARKFORGE_VERSION = "0.1.0";
|
|
342
|
+
declare function getMarkforgeVersion(fromDir?: string): string;
|
|
343
|
+
|
|
344
|
+
export { type CompilationResult, DEFAULT_CONFIG, type DocumentOrientation, type FrontmatterMetadata, type GeneratedOutputFile, type HeaderFooterItem, MARKFORGE_VERSION, type MarkdownASTNode, type MarkdownInlineSpan, type MarkdownNodeType, type MarkforgeConfig, type MarkforgeFormat, type MarkforgeTheme, type PageMargins, type PaperSize, type ParsedMarkdownDocument, type ResolvedImage, SYNTAX_COLORS, type SyntaxToken, THEMES, THEME_ACADEMIC, THEME_DEFAULT, type WatermarkOptions, buildDocxDocument, buildHtmlDocument, buildPdfDocument, compileMarkdown, defineConfig, escapeHtml, findChromeExecutable, formatServerTimestamp, getMarkforgeVersion, getMimeType, highlightCodeToHtml, injectPagedMediaStyles, inlineHtmlImages, loadConfig, compileMarkdown as markforge, parseInlineSpans, parseMarginToTwip, parseMarkdownDocument, renderInlinesToHtml, renderMermaidToPng, resolveImage, slugify, tokenizeCodeLine };
|