// Test the extracted page script without a server or a browser dependency. const assert = require('node:assert/strict'); const fs = require('node:fs'); const vm = require('node:vm'); class Element { constructor(tag) { this.tag = tag; this.childNodes = []; this.innerHTML = ''; this.textContent = ''; this.dataset = {}; this.attributes = {}; } setAttribute(name, value) { this.attributes[name] = value; } append(...nodes) { this.childNodes.push(...nodes); } replaceChildren(...nodes) { this.childNodes = nodes; } requestSubmit() { this.submits = (this.submits || 0) + 1; } } const elements = new Map(); const document = { getElementById(id) { if (!elements.has(id)) elements.set(id, new Element(id)); return elements.get(id); }, createElement(tag) { return new Element(tag); }, }; const context = vm.createContext({ document, fetch: () => new Promise(() => {}), setTimeout() {} }); vm.runInContext(fs.readFileSync(process.argv[2], 'utf8'), context); const run = source => vm.runInContext(source, context); const render = value => { context.markdownInput = value; return run('markdown(markdownInput)'); }; const html = render('# Heading\n\n- **Bold** and *italic* [link](https://example.com) `inline`\n\n```js\nconst x = 1 < 2;\n```\n\n| Name | Value |\n| --- | --- |\n| one | two |\n\n'); for (const expected of ['
inline', '', 'two ', '<script>']) assert.ok(html.includes(expected), expected);
assert.ok(!html.includes('