Add browser upload and viewer HTML resolution for HTML/Markdown
ingestHtmlFromFile and ingestMarkdownFromFile store session bytes with correct content types. resolveDomViewerHtml renders sanitized HTML or markdown paragraphs for HtmlViewerAdapter (EANCH-WP-0004).
This commit is contained in:
parent
4999ea31f2
commit
d605bf64be
5 changed files with 112 additions and 4 deletions
23
src/browser/view-html.test.ts
Normal file
23
src/browser/view-html.test.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { createPdfByteStore } from "./byte-store";
|
||||
import { markdownSourceToViewerHtml, resolveDomViewerHtml } from "./view-html";
|
||||
import { ingestHtmlFromFile } from "./upload";
|
||||
|
||||
const HTML = `<!DOCTYPE html><html><body><p>Hello HTML viewer</p></body></html>`;
|
||||
|
||||
describe("resolveDomViewerHtml", () => {
|
||||
it("returns sanitized HTML for html-dom representations", async () => {
|
||||
const store = createPdfByteStore();
|
||||
const file = new File([HTML], "sample.html", { type: "text/html" });
|
||||
const { document, representation } = await ingestHtmlFromFile(file, store);
|
||||
const html = resolveDomViewerHtml(document, representation, store);
|
||||
expect(html).toContain("Hello HTML viewer");
|
||||
expect(html).not.toMatch(/<script/i);
|
||||
});
|
||||
|
||||
it("renders markdown as paragraph HTML", () => {
|
||||
const html = markdownSourceToViewerHtml("# Title\n\nBody paragraph.");
|
||||
expect(html).toContain("<p>");
|
||||
expect(html).toContain("Body paragraph.");
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue