Skip to the content

Capsid menu

src/render/document.ts

12 lines and 1 functions in DrDustinEdwards/enarratio, at commit 4c5695a on 2026-10-24. This file on GitHub.

Functions

The functions of document.ts
FunctionLinesComplexityCoveredCRAPMutation
createDocument9 to 131100%OkCRAP 1Ok100%

Imports

It imports no other module of this repo. Imported by src/render/plot.ts.

Source

import { parseHTML } from "linkedom";

/**
 * A document for Observable Plot to draw into, outside a browser. linkedom, because it runs in
 * Node.js, Workers, Deno and Bun. Bundlers that build for browsers use `document.browser.ts`
 * instead (the `browser` condition of the `#document` import in package.json), so linkedom is
 * not shipped to readers.
 */
export function createDocument(): Document {
  const { document } = parseHTML("<!doctype html><html><body></body></html>");
  // linkedom implements the subset of the DOM that Plot and Enarratio use; its types differ.
  return document as unknown as Document;
}