const normalizeFootnotes = html => html.replace(/footnote-(?:[a-f0-9]+-){4}/g, "footnote-");
const { expect } = require("chai");
const fs = require("node:fs");
const path = require("node:path");
const vm = require("node:vm");
const { JSDOM } = require("jsdom");
require("ts-node/register/transpile-only");
const { renderMarkdown } = require("../src/markdown");
const { renderDiagram } = require("../src/markdown-diagrams");
const root = path.resolve(__dirname, "..");
function checkHtml(html, allowMediaData = false) {
const dom = JSDOM.fragment(html);
expect(dom.querySelector("script,iframe,object,embed,form,base,meta,link")).to.equal(null);
for (const element of dom.querySelectorAll("*")) {
for (const attr of element.attributes) {
expect(attr.name).not.to.match(/^on/i);
if (["href", "xlink:href", "src", "srcset", "poster"].includes(attr.name)) {
// Strip URL control characters before checking executable schemes.
// eslint-disable-next-line no-control-regex
expect(attr.value.replace(/[\u0000-\u0020]/g, "")).not.to.match(allowMediaData && ["src", "srcset", "poster"].includes(attr.name) ? /(?:javascript|vbscript):/i : /(?:javascript|vbscript|data):/i);
}
}
}
}
describe("Markdown security boundaries", function () {
const attacks = [
'
',
'link',
'
',
'