Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/cli/markforge/docs/full-all-properties.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Unified Platform Architecture & Document Suite"
subtitle: "Enterprise Specification & Feature Validation Guide"
author: "Masum RPG"
author: "Ma'sum"
company: "Masum Dev Technologies"
version: "1.0.0"
date: "2026-08-29"
Expand Down
37 changes: 37 additions & 0 deletions apps/cli/markforge/examples/1-minimal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Example 1: Minimal Programmatic Usage
*
* Compiles a Markdown string or file with zero configuration.
* Uses default corporate styling and outputs to .temp/example-minimal/
*/
import { compileMarkdown } from "@masumdev/markforge";

async function run() {
console.log("=== MarkForge: Minimal Programmatic Compilation ===");

const markdown = `
# Minimal Programmatic Document

This document was generated programmatically with **MarkForge** using minimal configuration.

- Zero configuration required
- Auto-detects paper size and margins
- Generates Word DOCX, PDF, and HTML
`;

const result = await compileMarkdown(markdown, {
to: ["docx", "pdf", "html"],
outputDir: "./.temp/example-minimal",
metadata: {
title: "Minimal Example Document",
author: "Ma'sum",
},
});

console.log(`Compilation completed in ${result.durationMs}ms:`);
for (const file of result.files) {
console.log(`- [${file.format.toUpperCase()}] ${file.fileName} (${file.sizeBytes} bytes)`);
}
}

run().catch(console.error);
73 changes: 73 additions & 0 deletions apps/cli/markforge/examples/2-intermediate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Example 2: Intermediate Programmatic Usage
*
* Demonstrates themes, syntax highlighting palettes, TOC, custom margins,
* and live progress logging callback.
*/
import {
compileMarkdown,
OutputFormat,
Theme,
SyntaxTheme,
PaperSizeEnum,
} from "@masumdev/markforge";

async function run() {
console.log("=== MarkForge: Intermediate Programmatic Compilation ===");

const markdownContent = `
# Technical Architecture Overview

Welcome to the intermediate programmatic specification.

## Core Microservices

Here is the TypeScript microservice interface:

\`\`\`typescript
export interface ServiceNode {
id: string;
endpoint: string;
activeConnections: number;
}
\`\`\`

> [!NOTE]
> All network traffic across nodes is encrypted via mTLS.
`;

const result = await compileMarkdown(
markdownContent,
{
to: [OutputFormat.DOCX, OutputFormat.PDF, OutputFormat.HTML],
outputDir: "./.temp/example-intermediate",
theme: Theme.CORPORATE,
syntaxTheme: SyntaxTheme.DRACULA,
paperSize: PaperSizeEnum.A4,
toc: true,
margins: {
top: "2.5cm",
bottom: "2.5cm",
left: "2.5cm",
right: "2.5cm",
},
metadata: {
title: "Technical Architecture Overview",
subtitle: "Microservices & Edge Network",
author: "Ma'sum",
company: "Masum Dev Technologies",
version: "1.2.0",
},
},
(status) => {
console.log(`[PROGRESS] ${status}`);
}
);

console.log(`\nCompiled ${result.files.length} documents in ${result.durationMs}ms:`);
for (const file of result.files) {
console.log(`- [${file.format.toUpperCase()}] ${file.fileName} (${file.sizeBytes} bytes)`);
}
}

run().catch(console.error);
178 changes: 178 additions & 0 deletions apps/cli/markforge/examples/3-full-custom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/**
* Example 3: Full Enterprise Programmatic Usage
*
* Demonstrates 100% of all properties:
* - Dynamic metadata tokens ({title}, {author}, {company}, {version}, {date}, {page}, {pages})
* - Per-zone header and footer customization (left, center, right, dividers)
* - 100% unselectable vector watermark (Canvas-to-PNG raster)
* - Signatures and approval blocks (Lembar Pengesahan)
* - Custom ThemeProps color tokens
* - Live progress callback
*/
import {
compileMarkdown,
OutputFormat,
Orientation,
PaperSizeEnum,
SyntaxTheme,
type MarkforgeConfig,
} from "@masumdev/markforge";

async function run() {
console.log("=== MarkForge: Full Enterprise Programmatic Compilation ===");

const markdown = `---
title: "Enterprise Cloud Infrastructure Agreement"
subtitle: "High-Availability Multi-Region Architecture"
author: "Ma'sum"
company: "Masum Dev Technologies"
version: "2.0.0"
date: "2026-08-29"
lang: "en"
---

# Executive Summary

This formal document verifies all enterprise capabilities of the MarkForge engine.

## Infrastructure Diagram

\`\`\`mermaid
flowchart LR
Client[Web Client] --> Gateway[API Gateway]
Gateway --> ServiceA[Auth Service]
Gateway --> ServiceB[Billing Service]
\`\`\`

## Configuration Code

\`\`\`typescript
export const clusterConfig = {
region: "ap-southeast-1",
nodes: 12,
ha: true,
};
\`\`\`

> [!IMPORTANT]
> Formal authorization signatures are attached at the end of this document.
`;

const config: MarkforgeConfig = {
to: [OutputFormat.DOCX, OutputFormat.PDF, OutputFormat.HTML],
outputDir: "./.temp/example-full",
orientation: Orientation.PORTRAIT,
paperSize: PaperSizeEnum.A4,
toc: true,
syntaxTheme: SyntaxTheme.GITHUB_DARK,
embedImages: true,
bundleHtml: true,

// Custom Theme Props Palette
theme: {
primaryColor: "#0D998D",
primaryDark: "#008073",
primaryLight: "#D9F1F0",
backgroundColor: "#FFFFFF",
textColor: "#0F172A",
textMuted: "#64748B",
borderColor: "#E2E8F0",
cardBackground: "#F8FAFC",
codeBackground: "#0F172A",
codeText: "#F8FAFC",
fontFamily: "'Segoe UI', Roboto, sans-serif",
fontMono: "'Cascadia Code', Consolas, monospace",
},

margins: {
top: "3cm",
bottom: "3cm",
left: "2.5cm",
right: "2.5cm",
},

// 100% Unselectable PDF & Visual Watermark
watermark: {
text: "CONFIDENTIAL DRAFT",
color: "#E11D48",
opacity: 0.08,
fontSize: 52,
rotate: -45,
},

// Custom Header Zones with Dynamic Tokens
header: {
left: {
text: "{company} | {title}",
color: "#0D998D",
fontSize: 9,
bold: true,
},
center: "Confidential Reference",
right: {
text: "v{version}",
color: "#94A3B8",
fontSize: 8.5,
italic: true,
},
divider: true,
dividerColor: "#CBD5E1",
},

// Custom Footer Zones with Dynamic Tokens & Page Numbering
footer: {
left: {
text: "Author: {author}",
color: "#64748B",
fontSize: 8.5,
},
center: "{date}",
right: {
text: "Page {page} of {pages}",
color: "#0D998D",
fontSize: 9,
bold: true,
},
divider: true,
dividerColor: "#CBD5E1",
},

// Formal Signatures & Approval Block (Lembar Pengesahan)
signatures: {
align: "space-between",
style: "line",
borderColor: "#CBD5E1",
items: [
{
title: "Prepared by",
name: "{author}",
role: "Lead Platform Architect",
date: "{date}",
},
{
title: "Reviewed by",
name: "Sarah Jenkins",
role: "Head of Infrastructure",
date: "{date}",
},
{
title: "Approved by",
name: "Dr. Alexander Wright",
role: "Chief Technology Officer",
date: true,
},
],
},
};

const result = await compileMarkdown(markdown, config, (msg) => {
console.log(`[COMPILING] ${msg}`);
});

console.log(`\nCompilation successful in ${result.durationMs}ms:`);
for (const f of result.files) {
console.log(`- [${f.format.toUpperCase()}] ${f.filePath} (${f.sizeBytes} bytes)`);
}
}

run().catch(console.error);
64 changes: 64 additions & 0 deletions apps/cli/markforge/examples/4-low-level-ast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Example 4: Low-Level AST & In-Memory Buffer Builders
*
* Demonstrates direct low-level document compilation without writing files to disk.
* Returns raw binary Buffers (DOCX, PDF) and HTML markup strings.
*/
import * as fs from "node:fs";
import {
parseMarkdownDocument,
buildDocxDocument,
buildPdfDocument,
buildHtmlDocument,
resolveDocumentConfig,
Theme,
} from "@masumdev/markforge";

async function run() {
console.log("=== MarkForge: Low-Level AST & Buffer Pipeline ===");

const rawMarkdown = `
# Low-Level In-Memory Compilation

This markdown is ingested directly into an AST node tree.

- Node parsing
- In-memory binary generation
- Direct buffer retrieval
`;

// 1. Parse Markdown into structured AST
const parsedDoc = parseMarkdownDocument(rawMarkdown);
console.log(`- AST generated with ${parsedDoc.nodes.length} nodes and ${parsedDoc.tocEntries.length} TOC entries`);

// 2. Resolve document configuration
const resolvedConfig = resolveDocumentConfig(parsedDoc.metadata, {
theme: Theme.CORPORATE,
toc: true,
metadata: {
title: "In-Memory Buffer Spec",
author: "Ma'sum",
},
});

// 3. Build documents independently in parallel
const [docxBuffer, pdfBuffer, htmlString] = await Promise.all([
buildDocxDocument(parsedDoc, resolvedConfig),
buildPdfDocument(parsedDoc, resolvedConfig),
buildHtmlDocument(parsedDoc, resolvedConfig),
]);

console.log(`- DOCX Buffer generated : ${docxBuffer.byteLength} bytes (PK header: ${docxBuffer.subarray(0, 4).toString("hex")})`);
console.log(`- PDF Buffer generated : ${pdfBuffer.byteLength} bytes (PDF header: ${pdfBuffer.subarray(0, 5).toString("utf-8")})`);
console.log(`- HTML String generated : ${Buffer.byteLength(htmlString, "utf-8")} bytes`);

// Optional: write to disk
fs.mkdirSync("./.temp/example-ast", { recursive: true });
fs.writeFileSync("./.temp/example-ast/in-memory-doc.docx", docxBuffer);
fs.writeFileSync("./.temp/example-ast/in-memory-doc.pdf", pdfBuffer);
fs.writeFileSync("./.temp/example-ast/in-memory-doc.html", htmlString, "utf-8");

console.log("All in-memory buffers saved to ./.temp/example-ast/");
}

run().catch(console.error);
Loading
Loading