Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Converts Markdown to styled HTML with WeChat-compatible themes, code highlighting, math, PlantUML, and footnotes.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/main.test.ts
1import assert from "node:assert/strict";2import { execFile } from "node:child_process";3import fs from "node:fs/promises";4import os from "node:os";5import path from "node:path";6import process from "node:process";7import test from "node:test";8import { fileURLToPath } from "node:url";9import { promisify } from "node:util";1011const execFileAsync = promisify(execFile);12const SCRIPT_DIR = path.dirname(fileURLToPath(import.meta.url));13const SCRIPT_PATH = path.join(SCRIPT_DIR, "main.ts");1415async function makeTempDir(prefix: string): Promise<string> {16return fs.mkdtemp(path.join(os.tmpdir(), prefix));17}1819test("CLI forwards wrapper title and package render options", async () => {20const root = await makeTempDir("baoyu-markdown-to-html-cli-");21const markdownPath = path.join(root, "article.md");22await fs.writeFile(markdownPath, "## Section\n\nParagraph with **bold** text.\n", "utf-8");2324const { stdout } = await execFileAsync(25process.execPath,26[27"--import",28"tsx",29SCRIPT_PATH,30markdownPath,31"--theme", "grace",32"--color", "red",33"--font-family", "mono",34"--font-size", "18",35"--keep-title",36"--title", "Overridden",37],38{ cwd: SCRIPT_DIR },39);4041const result = JSON.parse(stdout.trim()) as {42htmlPath: string;43title: string;44};4546assert.equal(result.title, "Overridden");4748const html = await fs.readFile(result.htmlPath, "utf-8");49assert.match(html, /<title>Overridden<\/title>/);50assert.match(html, /<h2[^>]*style="[^"]*background: #A93226/);51assert.match(html, /<strong[^>]*style="[^"]*color: #A93226/);52assert.match(53html,54/<body[^>]*style="[^"]*font-family: Menlo, Monaco, 'Courier New', monospace;[^"]*font-size: 18px/,55);56});5758test("CLI renders Obsidian wikilink images with alt text and Attachments fallback", async () => {59const root = await makeTempDir("baoyu-markdown-to-html-wikilink-cli-");60const attachmentsDir = path.join(root, "Attachments");61await fs.mkdir(attachmentsDir, { recursive: true });62await fs.writeFile(path.join(root, "a.png"), "a", "utf-8");63await fs.writeFile(path.join(attachmentsDir, "b.webp"), "b", "utf-8");6465const markdownPath = path.join(root, "article.md");66await fs.writeFile(67markdownPath,68[69"## Section",70"",71"![[a.png]]",72"",73"![[b.webp|B alt]]",74].join("\n"),75"utf-8",76);7778const { stdout } = await execFileAsync(79process.execPath,80[81"--import",82"tsx",83SCRIPT_PATH,84markdownPath,85"--keep-title",86],87{ cwd: SCRIPT_DIR },88);8990const result = JSON.parse(stdout.trim()) as {91contentImages: Array<{92alt?: string;93localPath: string;94originalPath: string;95placeholder: string;96}>;97htmlPath: string;98};99100assert.deepEqual(101result.contentImages.map(({ alt, localPath, originalPath, placeholder }) => ({102alt,103localPath,104originalPath,105placeholder,106})),107[108{109alt: "",110localPath: path.join(root, "a.png"),111originalPath: "a.png",112placeholder: "MDTOHTMLIMGPH_1",113},114{115alt: "B alt",116localPath: path.join(attachmentsDir, "b.webp"),117originalPath: "b.webp",118placeholder: "MDTOHTMLIMGPH_2",119},120],121);122123const html = await fs.readFile(result.htmlPath, "utf-8");124assert.match(html, /<img src="a\.png" data-local-path="[^"]+a\.png" alt=""/);125assert.match(126html,127/<img src="b\.webp" data-local-path="[^"]+Attachments[^"]+b\.webp" alt="B alt"/,128);129});130