v0.3.19
The Programmable Typesetter for the Web
Postext takes semantic markdown and applies centuries-old editorial layout rules — Knuth-Plass justification, orphan prevention, figure placement — producing publication-grade pages rendered to HTML, canvas, or print-ready PDF.
What Is Postext
Editorial Layout,
Computed for the Web
CSS gives you responsive layout — flexbox, grid, columns. But it cannot balance columns, prevent orphans, flow text around figures, or place footnotes at the bottom of a column. These are editorial decisions that have been refined over centuries of print typesetting.
Postext bridges that gap. Feed it semantic markdown and a configuration object. It measures text 300–600× faster than the DOM using @chenglou/pretext, then computes the complete page geometry — every line, float, and caption — and renders it through HTML, canvas, or print-ready PDF backends.
Input
# Chapter One
The quick brown fox jumps over
the lazy dog. A paragraph with
a {{figure:hero-img}} reference
and a footnote.[^1]
[^1]: Additional context placed
at column bottom automatically.Output
Capabilities
What Print Typesetters Knew All Along
Knuth-Plass Justification
The same optimal line-breaking algorithm TeX uses, with TeX-pattern hyphenation and orphan control — evenly set text blocks with no rivers of whitespace, beyond anything CSS can express.
Resources & Cross-References
Figures, SVG diagrams, and tables float to the top or bottom of columns and pages — the way print floats work — with typed numbering and :ref cross-references that always stay in sync.
Table & Caption Styling
Tables typeset with independent body and header typography, and captions that follow your configuration — numbered, styled, and placed alongside the resource they describe.
Single-Ink Diagrams
Recolor SVG diagrams to tints of one ink by luminance, so every illustration matches your design — ready for spot-colour printing.
LaTeX Math
Inline and display equations written in LaTeX, measured and typeset by the engine so they sit on the baseline grid alongside the text.
Web & Print-Ready PDF
One layout engine, three renderers. The same computed pages render to HTML, canvas, or print-ready PDF — with bookmarks and CMYK colour.
API
One Function, Full Control
Call buildDocument with your content and a configuration object. Get back the complete page geometry, ready to render with renderToHtml — or the canvas and PDF backends.
import { buildDocument, renderToHtml } from "postext";
const doc = buildDocument(
{ markdown },
{
layout: { layoutType: "double" },
bodyText: {
textAlign: "justify",
hyphenation: { enabled: true, locale: "en-us" },
},
}
);
const html = renderToHtml(doc);Workflow
Three Steps to Publication-Grade Layout
Write Semantic Markdown
Author your content in enriched markdown with resource references and footnote markers. No layout concerns — just content.
Configure Layout Rules
Define columns, typography rules, resource placement strategies, and section overrides in a PostextConfig object.
Render to HTML, Canvas, or PDF
Call buildDocument and receive the complete layout geometry — then render it with the HTML, canvas, or print-ready PDF backend.
Installation
Start in Under a Minute
# Install with your package manager
pnpm add postext// Quick start
import { buildDocument, renderToHtml } from "postext";
const doc = buildDocument({
markdown: "# Hello World\n\nYour content here.",
});
const html = renderToHtml(doc);