Skip to content
bayanasarPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Vertext

Unicode-aware top-to-bottom text with columns advancing right-to-left.

Vertical text is its own layout system, not a rotated horizontal one. Glyph orientation, column progression, and Latin handling are decisions the layout model makes explicitly; nothing here is a 90° transform on a horizontal engine.

Design documentation lives in docs/: docs/OVERVIEW.md for the engine and the documents that consume it, and docs/ARCHITECTURE.md for how the layout works end to end. PROGRESS.md records which claims have actually been run.

Run the demo

./examples/render.sh

That builds the binary, copies the extension into examples/_extensions/, and renders examples/quarto-demo.qmd. Both the copied extension directory and the rendered output are generated and git-ignored; examples/render.sh produces them from nothing.

extensions/vertext is the source of the filter. It is not the only copy: extensions/vertext-theme vendors its own, because Quarto requires an extension that uses another to carry it inside its own _extensions/. Two copies of a filter in one repository will drift, and these two have. Refresh the vendored one with cp -R extensions/vertext extensions/vertext-theme/_extensions/ rather than editing it — examples/test-extension.sh asserts the two are byte-identical, and CI's examples/test-column-budget.js reads both copies so a fix applied to one of them fails there.

Install

The filter and the binary are two halves of one release and must come from the same one: the filter refuses a binary whose wire version differs and leaves the document horizontal with a warning. A release's wire version is its MAJOR.MINOR and a pre-release's is its whole version, so a build from main, which carries the next minor's pre-release, pairs with no release; see docs/ARCHITECTURE.md.

cargo install vertext-cli --version 0.5.0
quarto add https://github.com/bayanasar/vertext/releases/download/v0.5.0/vertext-quarto-0.5.0.zip

The zip holds _extensions/vertext/ and nothing else. It is built from extensions/vertext by python3 tools/quarto-archive.py, so there is no copy of the filter at the repository root for quarto add <org>/<repo> to find.

A browser host takes vertext-wasm-<version>.zip from the same release: vertext.wasm and its glue vertext.mjs, built by python3 tools/wasm-archive.py. They are two halves in the same way, and the glue's load() throws VersionMismatch, naming both versions, rather than render with a module whose wire version is not its own. vertext-wasm is publish = false: this zip is the only official source of the module.

Then use it in a Quarto document:

---
filters: [vertext]
format:
  vertext-html: default
---

::: {.vertext}
山川异域,风月同天。
:::

The extension invokes the vertext binary at render time, producing static HTML. No browser JavaScript is required.

Orientation

Not everything in a document wants to be vertical. Each block decides:

Content Rendering Decided by
CJK / Mongolian paragraph Vertical columns East Asian Width majority
Latin-majority paragraph Horizontal block, 66ch The same measure, inverted
Heading, page title Vertical unless it and the body it heads are both Latin-majority The same measure, on both
Fenced or indented code Horizontal block, 80ch, monospace Markdown declared it code
Table Rows become columns Markdown declared it a table
::: {.vertext .vertext-code} Vertical code The author declared it

The majority is measured in ink, not characters: ideographs and Mongolian count double, because 山川异域 is four characters and a whole clause while "It is a truth universally acknowledged" is thirty-eight for a comparable amount of meaning. Punctuation does not vote.

There is exactly one heuristic in the system and it only ever chooses an orientation. Prose is never distinguished from code by guessing — markdown already says which is which, and where it does not, the author can.

Consecutive horizontal blocks stack: a heading sits on top of its paragraph rather than each claiming a slot beside the columns.

Progression

Columns advance right-to-left for CJK (vertical-rl) and left-to-right for traditional Mongolian (vertical-lr). Both are facts of their scripts, and getting it backwards does not look wrong — it reads the document in reverse.

vertext-progression: lr    # traditional Mongolian

It is declared rather than detected because it cannot be inferred: a Chinese document teaching Mongolian and a Mongolian document teaching Chinese contain the same scripts and want opposite answers. Default is right-to-left.

Column length

In vertical text the length of a column is the length of a line: it decides at which character a sentence turns into the next column, and so how often the reader's eye moves across. It is declared as a number of characters.

vertext-column-chars: 34   # the default

A column is that many upright cells long, unless the space on the page is shorter, in which case it is the space. The cell is --vertext-cell (18px), declared once in vertext.css: it is both the size an upright CJK glyph is set at and the unit the column counts in, so changing it scales those glyphs and the measure together. Latin and Mongolian are sized in proportion to it (14 and 15 against the default 18), so the three scripts scale together. The space is whatever a theme reports through --vertext-column-theme-height; without a theme it is the window height less the mode's own margins. So a document keeps one measure on every screen with room for it, and a short window wraps sooner instead of cutting text under the chrome.

It is declared rather than taken from the window because a window-following length is not a measure. Measured on one lesson page, a column that tracks the window runs from 30 to 96 characters across ordinary screen sizes, which makes the same document a different page on each of them. Anything other than a whole number from 1 to 400 is ignored with a warning.

Whole-document mode

vertext: true          # lay the document out vertically, keep the page chrome
vertext-page: true     # additionally make the page itself a vertical surface

vertext: true suits a document inside a site — navbar, sidebar, and table of contents keep working. vertext-page: true takes over the body and suits a standalone document. Either way no ::: {.vertext} fence is needed; explicit fences still work for laying out one region of an otherwise horizontal page.

Fonts and region

vertext ships no CJK face, and where the pause marks 、,。.;: sit is the face's to decide. A Mainland face such as Noto Sans SC puts them in the upper right of their cell; a Taiwan or Hong Kong page wants them centred, which takes a Taiwan face such as Noto Sans TC and the language declared (lang: zh-TW, zh-HK or zh-Hant in the YAML). Without it pandoc writes lang="", and a face that serves every region falls back to its own: Noto Sans SC keeps the corner under zh-TW too.

The curly quotes ‘ ’ “ ” take the face's vertical form in the same way. A Mainland face draws them as the corner brackets 「 」『 』; a Taiwan face draws a small upright mark in a corner of the cell, whatever the language, since Taiwan sets vertical quotes with 「」 in the first place. A Latin face has curly quotes and no vertical forms, so a page whose font stack puts a Latin face first, as Quarto's default does, draws the quotes upright in their horizontal form: put the CJK face first.

Every bracket, quote and pause or stop mark between characters takes one cell. The faces also carry narrower, proportional forms of these marks, and Firefox uses them on a page that sets font-kerning: normal, as pandoc's standalone template does, so the stylesheet turns kerning off for the cells. Chrome narrows on its own: by default one of two adjacent marks, as the 」 in 」,, takes half a cell (text-spacing-trim: normal), so the stylesheet sets text-spacing-trim: space-all on the cells too. That is a choice: Mainland and Hong Kong publications mostly narrow such a pair (CLReq 6.3.2), and vertext offers no way to ask for it yet.

The Mongolian face does ship: Noto Sans Mongolian sits beside vertext.css under the SIL Open Font License (NotoSansMongolian-OFL.txt), and the stylesheet loads it under a family name of its own. Every Mongolian measurement behind this project was taken in that face, including where a run sits across its line: its stem is 0.19 em off the centre of its box, and the stylesheet moves each run by --vertext-mongolian-stem-shift to put the stem on the line's centre. A theme that sets bichig in another face declares its own value on .vertext, not on :root, where it would depend on which stylesheet loads last.

A site that copies vertext.css somewhere itself, rather than through Quarto, copies NotoSansMongolian-Regular.ttf and NotoSansMongolian-OFL.txt into the same directory. Without the font the face is a 404, and the shift still moves a fallback face that was never measured.

What markdown survives

The filter flattens each block to characters before handing it to the binary, so structure only crosses the boundary where the wire protocol carries it:

Markdown Result
Headings (#–######) Own block, level-scaled, with a section rule. Horizontal only when its own text and the first paragraph or list item after it both are; with none after it in the strip, the strip's prose together stands for the page
Fenced / indented code At the top level of a vertext: true or vertext-page: true page, passed to pandoc whole and set horizontally between the columns, highlighted and with Quarto's copy button as on any other page. So is a notebook cell, embedded or executed, and a tabset whose every panel is code, which keeps its tabs. So is code in a box (below). Inside a list, a quote, a Div with no class or a ::: {.vertext} fence, a code strip: own block, horizontal, indentation preserved, not highlighted
Tables Real <table>; rows become columns, cells never hyphenate
Bullet / ordered lists Each item is its own block, oriented on its own. An ordered item carries its number as text
Paragraphs Own block, oriented by the rule above
Inline formulas ($…$) One horizontal box in the column, set by the document's own math engine (MathJax, KaTeX, MathML). A formula is never divided, so a long one makes its line as wide as the formula
Display formulas ($$…$$) Own horizontal block, like code; one wider than the measure scrolls. In a list item, a quote or a table cell, one box in the column, like an inline formula
Footnotes ([^1], ^[…]) The mark stays in its column as a small box and links to its note. The notes go at the end of the page, where pandoc puts them; on a vertical page the browser sets them in its own vertical text, not this layout
Citations and cross-references ([@key], @key, @eq-x) One horizontal box in the column, like an inline formula, filled after layout by citeproc or Quarto's crossref. A long one makes its line as wide as itself. The bibliography goes at the end of the page, set like the footnotes
A labelled formula ($$…$$ {#eq-x}) Under Quarto, numbered and the target of its references, in a paragraph, a list item, a quote or a table cell
A box: a Div with a class (::: {.card}, or <div class="card"> with blank lines around its content) Kept, with its id, classes and attributes, and its blocks laid out inside it, so the vertical page has the boxes the horizontal one has and one stylesheet serves both. Write that stylesheet in logical properties (max-inline-size, margin-block-end): max-width on a vertical page limits the columns' advance, not their length. A Div with no class is poured into the running text
<p class="x">…</p>, <h1>–<h6> written as tags Read as the paragraph or heading they are: a <p> becomes a box with its classes, an <hN> a heading
A paragraph of nothing but spans (<span class="name">…</span> <span class="role">…</span>, a row of tags) One small box per span, with its classes, set one after another down the column. A span inside running text is flattened like emphasis
A block holding any other raw HTML (a rendered listing, a plot) Passed through whole and set horizontally, markdown inside it included
Images (![alt](a.png)) One in a sentence is a box in its column, like an inline formula, no longer than the column. One on its own, or a numbered figure ({#fig-a}), is passed to pandoc whole and set between the columns with its caption
Callouts (::: {.callout-note}), tabsets (::: {.panel-tabset}) Kept as Quarto's own: the frame, the title and the tabs are Quarto's, and the text inside is laid out in columns. The title and a tab's name are set by the browser in the page's writing mode
Emphasis, links Flattened to their text. The markup is lost
A list nested inside a list item Flattened into that item's text
Mongolian inside a code strip Rendered in the monospace face, so its letters stay isolated instead of joining

The last three rows are real limitations, not rounding errors: *emphasis* arrives as the bare word, and bichig inside a code strip keeps the monospace face deliberately — a family change mid-line would break the column alignment that is the reason code is set in monospace at all. The cost is that those letters do not join, which is the failure this library exists to prevent, appearing in the one place it is chosen rather than suffered. Declared degradation beats pretended fidelity, but only where the reader will see the declaration. Each construct needs its own marker in the protocol before it can be rendered as itself, and until it has one it belongs in this table rather than being silently implied.

Items are classified one at a time on purpose. Flattening a list into a single string welds the items together and classifies them as a lump: six mostly-Chinese items that each carry a Latin term add up to a Latin-majority blob, and the whole list turns horizontal.

Whole-page vertical flow

Add vertext-page: true to the document's YAML and the page itself becomes a vertical surface: writing-mode: vertical-rl on the body, so the title, the headings, and the prose between strips all flow top-to-bottom with columns advancing right-to-left, and the document scrolls horizontally from the right edge. This is the browser's native vertical flow — the strip is not a box embedded in a horizontal page.

The document title is re-rendered through the binary as a level-1 heading and Quarto's own title block is hidden, so the title obeys the same layout rules as the body it heads: it opens the first section's strip, and a title with more Latin than Han, 2.3 構建系統——Cargo vs CMake / Bazel / Meson / Make, stands in a column over a Chinese page. Rotating it with text-orientation: sideways would have been a transform wearing the costume of vertical text.

Collapsing the top strip

On a vertical page, depth is the scarce axis: a navigation strip that costs 11rem out of a 100vh column takes a tenth of every line of text, on every page. Horizontally the same strip costs nothing anyone notices.

So the extension ships a control that hands that depth back, and a theme opts in by publishing its top-edge depth as a custom property:

:root {
  --vertext-nav-depth: 11rem;        /* the strip AND the content inset read this */
  --vertext-nav-depth-collapsed: 2.1rem;   /* optional; this is the default */
}

Every rule that would otherwise write the number — the strip's own size, the content region's top inset, any calc() deriving a height from it — must read var(--vertext-nav-depth) instead. That is the whole contract: one value moves, and the geometry follows.

The extension then builds the button itself and appends it to the strip, which it finds by [data-vertext-edge="nav"], falling back to Quarto's #quarto-header. Collapsing sets vertext-nav-collapsed on the body; the choice is remembered in localStorage. The strip shrinks to a bar that still carries the button — never to nothing, because a control you cannot get back to is a one-way door, not a collapse.

A page that does not declare --vertext-nav-depth gets no button at all. That is deliberate. A theme still baking its depth into a build-time constant would otherwise get a control that renders, clicks, flips a class and moves nothing — which is worse than no control, because it looks like it worked. Reading the computed property back is the one check that proves the geometry really is a runtime value.

Two optional attributes on <html> localize the tooltip, which defaults to English: data-vertext-nav-label and data-vertext-nav-label-collapsed.

Layout

Columns run top-to-bottom; a source newline starts the column to the left. Layout::progression carries the advance direction as data — RightToLeft (vertical-rl, CJK) or LeftToRight (vertical-lr, traditional Mongolian) — because progression is a property of the script, not a property of the engine. The renderer stamps it on the root as data-column-advance and the stylesheet follows.

Source offsets and carets

A slot carries what it shows, not where that text came from, so vertext_core::source_map(input, &layout) (or layout_with_source_map) returns the other half: every slot's column, position and source byte range, and a caret that moves both ways between a source offset and a (column, slot, grapheme) position. A Mongolian run is one slot but many caret positions, because a writer edits letters. The hyphen the layout adds to split a long word is flagged and has no source bytes. The geometry is relative: visual lines inside a column and positions on the page belong to the host, which breaks the lines.

What the engine does not decide

Line breaking, and with it the kinsoku rules, belong to the host. The core places glyphs into slots and hands you columns; it does not decide where a column ends. A vertical column's length is the CSS budget --vertext-column-height, and wrapping inside a horizontal block is the browser's, which is the only party here holding font metrics.

That is a consequence of the core being metric-free, not a postponement. To forbid a column from beginning with 。 or ending with ( you must first own the break, and to own the break you must measure — which means fonts at layout time, which is the one thing vertext-core cannot have while it stays pure enough to cross wasm32 with no I/O. So today: no kinsoku, no widow and orphan control, no line-adjustment (追い出し / 追い込み). A host that needs them must supply them, and the print path would need the core to grow metrics first.

What the engine does guarantee at a break is narrower and worth stating: a Mongolian run is never split, a suffix separator never becomes a break opportunity, and a Latin word breaks only at a hyphen it already contained or at the declared cap, with the hyphen visible.

Prose Latin slots are capped at 12 characters; long words are hard-wrapped with a visible hyphen. Code blocks use 24 so conventional compound identifiers stay intact. The caps are declared once, in vertext-html, and published to CSS as custom properties — a cap written in two places drifts, and a drifted cap truncates silently instead of wrapping visibly. Dictionary-aware hyphenation is a later opt-in because it needs a language tag and a hyphenation dictionary, and a hyphenation without a language is a guess.

A Mongolian run is kept whole, and U+202F NARROW NO-BREAK SPACE is kept inside it. In bichig that mark is not a space between words but the joint inside one: ᠮᠣᠩᠭᠣᠯ + U+202F + ᠤᠨ is the genitive "Mongolia's". The separator holds the stem's last letter in its final form, opens the suffix in its initial form, and forbids a break between the two — UAX #14 gives it class GL. Unicode nevertheless gives it White_Space=Yes, so an engine that asks only is_whitespace sets every case ending as a separate word: a half-em gap in the column with the suffix stranded a row below it. It joins only where Mongolian holds it on both sides; anywhere else — French before a colon, digit grouping — it is the narrow space its name describes and keeps its own slot.

Workspace

Crate Role
vertext-core Pure layout engine. Text in, positioned slots out. No I/O, no DOM — it must cross wasm32 unchanged.
vertext-html Shared Layout → HTML renderer and the mode protocol. Every HTML host goes through it, so the slot-to-class mapping exists once.
vertext-cli Thin stdin-to-stdout shell over vertext-html.
vertext-wasm The same renderer for the browser, through a plain C ABI with no imports: byte-identical HTML to the CLI, and the source map for carets. Glue and a caret demo in examples/wasm/.
vertext-ffi For a native host that draws slots itself: each slot's kind, text and source range as JSON over a C ABI. bindings/dart binds it for Dart and Flutter.

One host ships. The Markdown/Quarto extension in extensions/vertext is in production. Every other adapter is a design document and no code, except chaji's backend (vertext-ffi, bindings/dart), which exists without its host. They are indexed in docs/ROADMAP.md, with what each is waiting on:

Product Status
Markdown / Quarto extension (extensions/vertext) Done — shipping in production
Quarto theme Partly real — extensions/vertext-theme/ ships the SCSS and the nav collapse; the design describes more
chaji 侘寂 (Flutter) Backend exists — vertext-ffi and the Dart binding; the optional layout theme in the wabisabi widget kit is not started
Browser extension Design only — vertext-wasm now exists
Notes Design only — vertext-wasm and slot geometry now exist
Neovim plugin Design only — an honest lossy projection onto the terminal grid
Web IDE Design only
Browser Design only, last in the queue

The markdown path is complete: the filter renders real documents end to end and is in production. It is a Pandoc filter with four Quarto-specific calls, so other Pandoc-based generators are a small port; non-Pandoc generators (Hugo's goldmark, remark, python-markdown) each need their own adapter over the same wire protocol.

The two pieces of engine work the browser-side products waited on are in: vertext-wasm renders byte-identically to the CLI, and slot geometry — slot positions and the two-way map to source offsets — is in vertext-core. examples/wasm/caret.html is the first host to use both: a textarea and its vertical rendering, with the caret moving between them.

Tests

cargo test --workspace         # layout engine and renderer
./examples/test-extension.sh   # the Quarto filter, through real `quarto render`
node examples/test-nav-toggle.js   # the collapse control's branches, in a stub DOM

The last one exists because the other two cannot run a script: cargo test stops at the renderer and test-extension.sh greps markup. It covers the opt-in rule, persistence, and the way back — and it explicitly does not cover hit-testing or layout. A control that renders in the right place and is unclickable has shipped from here before, with every check green the whole way; only a real browser driving a real mouse event catches that, and a consuming site's tools/check-nav-toggle.py is that test.

Getting a browser and a pandoc without installing Quarto

Neither of the last two needs Quarto itself, and neither needs root. This is worth writing down because "no browser here" was believed on this project for longer than it was true, and a control shipped unclicked on the strength of it.

uv pip install --target . pypandoc_binary      # pandoc + lua, ./pypandoc/files/pandoc
npx @puppeteer/browsers install chrome@stable  # a real Chrome, into ./chrome
npx sass extensions/vertext-theme/vertext-theme.scss theme.css

With those three, the whole crossing can be driven by hand: pandoc parses the markdown, the real vertext.lua runs over the AST with Quarto's four quarto.* calls shimmed, and the real vertext binary lays it out. For the collapse control, build a page carrying the compiled theme and the NAV_TOGGLE block read straight out of vertext.lua — extracted, never retyped, or the thing under test is a copy of it — serve it, and point check-nav-toggle.py at it with Chrome started as:

chrome --headless=new --remote-debugging-port=9222 --window-size=1400,900

Run the check against the previous commit as well. A rig that cannot reproduce the failure is not evidence that the failure is gone.

Layout invariants and the mode protocol are unit-tested; the README's 山川异域,风月同天 sample is pinned as a golden. Correctness claims for a script require a reference rendering behind them — "it parses" is not "it renders".

The unit of layout is the UAX #29 extended grapheme cluster, so a variation selector stays with the ideograph whose glyph it selects, a combining mark with its base, and a ZWJ emoji sequence with itself. This is the reason vertext-core has its one dependency, unicode-segmentation: cluster boundaries are table-driven, and a hand-rolled approximation renders text that is wrong in exactly the ways a reader notices and a test does not.

The extension test document is deliberately multi-byte. Marker stripping in the filter is byte-oriented, and an ASCII-only fixture cannot catch a pattern that corrupts neighbouring CJK.

License

MIT, except the Noto Sans Mongolian font: NotoSansMongolian-Regular.ttf, in goldens/fonts/ and shipped with the extension, is under the SIL Open Font License 1.1 (OFL.txt beside it, NotoSansMongolian-OFL.txt in the extension).

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages