Scan your whole stack
Are you using @pretextbook/pretext-html?
Find out what’s in your code.
Scan your apps free in minutes (opens in a new tab)Latest version: v0.21.3
@pretextbook/pretext-html was last scanned on 26 Nov 2026 at version 0.21.3. Risk score 0 of 100. No malicious behavior was detected.
| Version | Published | Status |
|---|---|---|
| 0.21.3 LATEST | 26 Nov 2026 | No rules fired |
| 0.21.2 | 25 Nov 2026 | No rules fired |
| 0.21.1 | 14 Nov 2026 | No rules fired |
| 0.21.0 | 11 Nov 2026 | Not shown |
| 0.20.0 | 11 Nov 2026 | Not shown |
Findings for v0.21.3. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.
The score describes 0.21.3; other versions have their own rules, not their own score.
The publisher’s own README, as collected from the registry.
Convert PreTeXt documents to HTML in pure
JavaScript — no Python, no PreTeXt installation. This runs the official,
unmodified PreTeXt XSLT stylesheets with
@pretextbook/libxslt-wasm, a
WebAssembly build of libxml2/libxslt/libexslt (the same C libraries the Python
CLI uses via lxml), so the HTML matches a real pretext build. It is a fork of
jeremy-code/libxslt-wasm built
with a larger WASM stack so whole-book documents render without overflowing
(see Forking libxslt-wasm).
The output is a single, standalone HTML page. The theme css/js and MathJax load from public CDNs, the whole document is rendered as one page, and images are linked rather than embedded, so the host serves them from wherever it keeps them (see Images and other assets). This is what powers the "Live Preview" in the PreTeXt-tools VS Code extension, and it is published so other tools (e.g. pretext.plus) can render previews the same way.
npx @pretextbook/pretext-html source/main.ptx \
--project-dir . \
--publication publication/publication.ptx \
-o preview.html
HTML goes to stdout (or --output); diagnostics (PTX:WARNING, PTX:ERROR,
deprecation notices) go to stderr. Run pretext-html --help for all options.
The CLI relaunches itself with --experimental-wasm-jspi automatically (see
Requirements).
import { renderHtml } from "@pretextbook/pretext-html";
const { html } = await renderHtml({
sourcePath: "source/main.ptx", // root document
projectDir: ".", // directory the transform may read from
publicationPath: "publication/publication.ptx", // optional
stringParams: {}, // optional extra XSLT stringparams
});
sourceContent lets you render unsaved editor text (with sourcePath still
anchoring relative xi:includes).fragment: true renders a non-root file (a lone <section>, <chapter>, …)
by wrapping it in a minimal <pretext> document. To keep the project's LaTeX
macros and custom settings, give it the docinfo: either docinfoSourcePath
(the project main file, whose <docinfo> is lifted out — resolving
xi:includes, including a docinfo that is itself included), or docinfo (a
<docinfo> element as a string, if you already have it). Both are ignored
for complete documents, which carry their own docinfo.sourceMap: true additionally returns a source map for editor/preview
sync: one entry per element, in document order, mapping the element's HTML
id to the source file/line it was authored in — through xi:includes.
This works because HTML ids are the @unique-id values that
pretext-assembly.xsl stamps with a deterministic walk
(@label ?? @xml:id ?? parent-id + "-" + sibling-position), which is
replicated over the merged tree in JS; the rendered page itself is
unchanged. Entries carry a parent id so clients can fall outward when an
element has no HTML id of its own, and findSourceMapEntry(entries, line)
picks the element nearest a cursor line. (This powers the two-way sync in
the VS Code Instant Preview; the same map works for any embedder.)src/publication.ts):<html><resources host="cdn"/>: css/js, theme and icon font from the CDN.<common><chunking level="0"/>: the whole document on one page.<html><cross-references knowled="never"/>: cross-references are links,
because the knowl files they would open are never written.<html><platform portable="no"/>: PreTeXt's portable HTML mode is off,
even for a project that builds portable. Portable mode would do the first
three as well, and earlier releases relied on it, but it also inlines
every latex-image and PreFigure SVG into the page. Without it those are
linked like every other image.<html><search variant="none"/>: no search box and no search index. The
index is a separate file a preview never writes, and building it costs a
walk over the whole document on every render.cssTheme: "denver" supplies the PreTeXt HTML theme for projects that do not
choose one, by adding <html><css theme="…"/></html> to the publication file
used for the build (including the minimal one synthesized when you pass no
publicationPath). It is a default, never an override: a publication file
that already names a theme — @theme, or the deprecated @style/@shell —
keeps it, so the preview goes on matching what pretext build produces. The
themes the bundled stylesheets know are default-modern (PreTeXt's own
default), denver, tacoma, salem, greeley and boulder; the preview
loads theme-<name>.min.css from the CDN, so an unrecognised name gives an
unstyled page. Not to be confused with theme below, which is the
light/dark mode within whichever css theme is in force.xslDir (~1s to compile, then
~100ms–1s per render depending on document size).theme: "dark" | "light" | "system" makes the preview follow the embedding
app's light/dark theme (see Theme control).<details> (footnotes, image descriptions) are left
alone. Pass openKnowls: false (--no-open-knowls on the CLI) for the
collapsed reading experience of a real pretext build.Every image the page shows is an ordinary link under one of two fixed
prefixes, exactly as in a real build. Author-supplied files are under
external/, and everything pretext generate makes (latex-image, PreFigure,
sageplot, asymptote, …) is under generated/:
<img src="external/kitten.png" />
<img src="generated/latex-image/diagram.svg" />
A real build copies both directories next to its pages. A preview has no such directory, so the host maps each URL to wherever it keeps the file:
import { renderHtml } from "@pretextbook/pretext-html";
import {
rewriteAssetUrls,
missingAssetPlaceholder,
} from "@pretextbook/pretext-html/assets"; // dependency-free subpath
const { html, assetDirs } = await renderHtml({ sourcePath: "source/main.ptx" });
const page = rewriteAssetUrls(html, (kind, relPath) => {
// kind is "external" or "generated"; relPath is e.g. "latex-image/diagram.svg"
const url = lookUp(kind, relPath); // a webview URI, a blob URL, a hosted URL…
return url ?? missingAssetPlaceholder(kind, relPath);
});
assetDirs gives the absolute directories behind the two prefixes, resolved
the way PreTeXt resolves them. external comes from the document's
<docinfo><directories external="…"/>, falling back to the publication
file's deprecated source/directories/@external; it is absent when neither
declares one, which PreTeXt reads as "no external assets". generated comes
from the publication file's source/directories/@generated and defaults to
generated/ beside the main source file.assetDirs and
answers from its own store of uploaded or generated files. Nothing reads
image files during the render itself.<img> again while its
src is unchanged, and a live patch leaves an unchanged element alone, so a
regenerated image behind the same URL keeps showing the old picture. With a
new URL, a live patch updates just that src in place and only that image
reloads. Re-deliver the page when the files change (the VS Code preview
watches the asset directories), not only when the source does.missingAssetPlaceholder returns a data-URI SVG that names the missing file
and says what to do (pretext generate latex-image, or "check @source"),
which reads better than the browser's broken-image glyph. Return undefined
from the resolver instead to leave a URL as it is.src attributes are rewritten. An annotated PreFigure diagram (one with
<annotations>) is drawn by a script from data-src/data-cml attributes,
which are left alone.--output), linking each
asset relative to the output file. HTML written to stdout keeps PreTeXt's
own URLs.An <interactive> that PreTeXt points straight at a service — @desmos,
@calcplot3d, @circuitjs, @iframe — is an ordinary <iframe> on the page
and needs nothing from the host.
One authored with @platform (GeoGebra, JSXGraph, D3, Sage, DoenetML, plain
JavaScript), and <interactive geogebra="…">, which PreTeXt rewrites into that
form, is different: the page holds <iframe src="<id>-if.html">, and a real
build writes that second, minimal page — the slates, the platform's libraries,
the author's scripts — to a file beside it. This renderer writes no files, so
it returns those pages instead:
const { html, iframePages } = await renderHtml({ sourcePath });
// iframePages: { "graph-if.html": "<!DOCTYPE html>\n<html>…", … }
html is left with the iframes exactly as PreTeXt emits them, pointing at
files that do not exist until the host does one of two things:
embedIframePages, which gives every iframe that names
a page that page as its srcdoc (moving the filename to
data-ptx-iframe-page). This is what the CLI does.import { embedIframePages } from "@pretextbook/pretext-html/iframe-pages";
const page = embedIframePages(html, iframePages, { sandbox: "allow-scripts" });
srcdoc frame
shares its embedder's origin. A host that shows documents its user did not
write, on an origin that matters (a web app with a session), should pass
sandbox without allow-same-origin. Omitted, the frame is unsandboxed,
as in a PreTeXt build.<interactive source="board.js"> becomes
<script src="external/board.js">), and a srcdoc frame resolves those
against the embedding page's URL. To send them elsewhere, run each page
through rewriteAssetUrls before embedding it../iframe-pages subpath, free of the WASM
renderer, for a host that inlines pages a worker rendered.A render costs what PreTeXt's assembly costs, and that tracks the number of
elements in the document: a few hundred milliseconds for a chapter, tens of
seconds for a whole book. A live preview of a large document therefore should
not render the whole document, and need not: the subtree option renders one
division of it, numbered and cross-referenced exactly as the whole document
would number it, by pruning the rest to a skeleton (see src/skeleton.ts).
const { html, size, subtree } = await renderHtml({
sourcePath: "source/main.ptx",
subtree: {
line: cursorLine, // the division around the author's cursor...
file: cursorFile, // ...in this file (defaults to sourcePath)
level: 2, // chunk level: sections of a book are pages of their own
wholeDocumentUpTo: 3000, // but a small document previews whole
},
});
line/file select the innermost division containing a source line; id
selects by xml:id instead (an element inside a division selects that
division). The division need not carry an xml:id of its own — the one
PreTeXt would stamp on it is injected, so the page's HTML ids are unchanged.data-ptx-division (and data-ptx-id for a link to an
element), so a host can make them re-render with subtree: { id }.level has PreTeXt's chunk-level meaning, for a host that wants whole
pages at some depth: the preview is the page that would hold the selection
in a build chunked at that level. A selection deeper than level previews
its ancestor at level, whole; one at level is shown whole; one shallower
is the summary page above. Omit it to treat every division as a page of its
own.wholeDocumentUpTo renders the whole document instead when it has no more
than that many elements — a small document previews whole as fast as any
division of it would.size (elements, bytes, and the files the
document spans, to watch for changes), and subtree (id, level,
collapsed) when one division was emitted rather than the whole document.
measureDocument(options) reports the same size without rendering, for a
host deciding how much to preview before each render.fragment: true and a context document, subtree narrows the preview
within the placed fragment — a cursor line in a chapter file previews the
section it is in.What a division preview still has to do on every render is read and parse the whole document, to prune it. Two options keep that cheap:
readSource(path) (or files, a map from absolute path to content) supplies
the document's files from memory — the xi:include targets, the context
document, the publication file — for a host that already holds its project
in memory (a browser editor) or has unsaved buffers (an editor). A reader
that returns undefined for a path falls through to the platform's own read.SourceCache of your own as cache to scope it (and invalidate() it), or
cache: false to parse afresh each time.On a synthetic 12-chapter book of 28,000 elements split into 157 files, a section or subsection preview takes well under a second warm (0.3–0.8s measured, most of it the division itself), and a chapter's summary page about the same, against 20–40 seconds for the whole book.
The same renderer runs in a browser — no server, no Python. Bundlers pick it up
through the browser export condition automatically; there is nothing to
configure.
import { renderHtml, isJspiAvailable } from "@pretextbook/pretext-html";
if (!isJspiAvailable()) {
// No WebAssembly JSPI in this engine — fall back to a server-side build.
}
const { html } = await renderHtml({
sourcePath: "/source/main.ptx", // a *virtual* path: no filesystem is read
sourceContent: editorText, // required in the browser
projectDir: "/source",
fragment: true, // rendering one division on its own
});
Differences from the Node API, all of them consequences of there being no filesystem:
Find threats in your stack.
OX Radar can check high-priority threats, like critical package CVEs, against your context.
Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.
The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).
The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.