Article
Body text.
import assert from "node:assert/strict"; import { createRequire } from "node:module"; import * as path from "node:path"; import { fileURLToPath } from "node:url"; import { describe, test } from "vitest"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const require = createRequire(import.meta.url); const addonDir = path.resolve( __dirname, "..", "..", "..", "..", "rust-engine", "addon", ); const platformTag = `${process.platform}-${process.arch}`; const candidates = [ path.join(addonDir, `forge_engine.${platformTag}.node`), path.join(addonDir, "forge_engine.dev.node"), ]; let native; for (const candidate of candidates) { try { native = require(candidate); break; } catch { // try next } } if (!native) { console.error( "Native addon not found. Run `npm run build:native -w @singularity-forge/native` first.", ); process.exit(1); } describe("native html: htmlToMarkdown()", () => { test("converts basic HTML to markdown", () => { const html = "
World
"; const result = native.htmlToMarkdown(html); assert.ok(result.includes("Hello"), "Should contain heading text"); assert.ok(result.includes("World"), "Should contain paragraph text"); }); test("converts links to markdown links", () => { const html = 'Visit Example
'; const result = native.htmlToMarkdown(html); assert.ok( result.includes("[Example]"), "Should contain markdown link text", ); assert.ok( result.includes("(https://example.com)"), "Should contain markdown link URL", ); }); test("converts lists to markdown", () => { const html = "bold and italic
"; const result = native.htmlToMarkdown(html); assert.ok( result.includes("**bold**") || result.includes("__bold__"), "Should contain bold", ); assert.ok( result.includes("*italic*") || result.includes("_italic_"), "Should contain italic", ); }); test("handles empty HTML", () => { const result = native.htmlToMarkdown(""); assert.equal(typeof result, "string"); }); test("handles plain text", () => { const result = native.htmlToMarkdown("Just plain text"); assert.ok(result.includes("Just plain text"), "Should preserve plain text"); }); test("accepts skipImages option", () => { const html = 'Content with
image
Body text.
const x = 1;";
const result = native.htmlToMarkdown(html);
assert.ok(result.includes("const x = 1;"), "Should contain code content");
});
test("converts complex nested HTML", () => {
const html =
'';
const result = native.htmlToMarkdown(html);
assert.ok(result.includes("Section"), "Should contain heading");
assert.ok(result.includes("example.com"), "Should contain link");
assert.ok(result.includes("one"), "Should contain list items");
});
});