import assert from "node:assert/strict"; import test from "node:test"; import { estimatedImageHeight, imageSize, rememberImageSize } from "../../../src/lib/workspace/imageSizes.ts"; import { renderMarkdownHtml } from "../../../src/lib/workspace/noteHtml.ts"; test("a rendered image has size attributes only when its size is known", () => { const unknown = "data:image/png;base64,AAAA"; const known = "data:image/png;base64,BBBB"; rememberImageSize(known, 1400, 700); const urls = new Map([["a.png", unknown], ["b.png", known]]); assert.doesNotMatch(renderMarkdownHtml("![a](a.png)", urls), /width=/); assert.match(renderMarkdownHtml("![b](b.png)", urls), /width="1400" height="700"/); }); test("a large data URL keeps its size without the image data as the key", () => { const url = `data:image/png;base64,${"A".repeat(5000)}${"B".repeat(100)}${"C".repeat(5000)}`; const other = `data:image/png;base64,${"A".repeat(5000)}${"D".repeat(100)}${"C".repeat(5000)}`; rememberImageSize(url, 10, 20); assert.deepEqual(imageSize(url), { width: 10, height: 20 }); assert.equal(imageSize(other), undefined); }); test("an image without a real size stays unknown", () => { rememberImageSize("data:image/svg+xml;base64,AAAA", 0, 0); assert.equal(imageSize("data:image/svg+xml;base64,AAAA"), undefined); }); test("the estimate scales a wide image to the text column and keeps a small image", () => { assert.equal(estimatedImageHeight(''), -1); assert.equal(estimatedImageHeight(''), 370 + 45); assert.equal(estimatedImageHeight(''), 50 + 45); });