Skip to content

feat(docs): add offline plots glossary helpers and slides - #2017

Merged
gerchowl merged 34 commits into
devfrom
feature/1994-typst-content
Nov 4, 2026
Merged

gerchowl merged 34 commits into
devfrom
feature/1994-typst-content

Conversation

@gerchowl

@gerchowl gerchowl commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add @local/devkit-docs:0.2.0 with offline native plots, consumer-loaded glossary rendering, and a 16:9 presentation layout. Preserve byte-identical 0.1.0 and 0.1.1 imports and their content hashes.

Glossaries load explicitly with #show: glossary-setup.with(yaml("/glossary.yaml")). This works with large registers, plain compilation, editor previews, hooks, and recipes without transporting YAML through compiler arguments. Acronyms expand at their first body occurrence; outline and figure-outline copies use short forms. For PDF bookmarks, glossary-tools binds canonical term text before layout while retaining contextual expansion. The legacy setup API remains supported; bookmark-safe headings use the documented bound term helper.

Type of Change

  • feat -- New feature
  • fix -- Bug fix
  • docs -- Documentation
  • test -- Tests
  • build -- Offline package registry and sandbox check

Modifiers

  • Breaking change (!)

Changes Made

  • Vendor lilaq 0.5.0 and its complete licensed, content-locked dependency closure.
  • Require both plot axis labels and a figure caption. Keep ordinary labels and ticks at 9 pt, synthesized super/sub text at 7 pt, and attached math scripts at least 7 pt. Reject explicit undersized math text; document limits for arbitrary user math and transforms.
  • Load glossary data in the consumer's filesystem scope, reject duplicate IDs while building the lookup dictionary, diagnose missing registers and unknown IDs, and render a sorted, unique used-term appendix.
  • Resolve YAML exponent and octal scalars before the existing string-only schema validation, so numeric spellings cannot pass as terms, aliases, or forbidden names.
  • Add title, section, and content slides with shared branding, type scale, booktabs, captions, and revision stamps. Footer text comes from short-title or title, extracted read-only with an explicit work stack, without recursive traversal, reconstruction or source-element layout. Hidden content is omitted, term items retain their term and description, paired single/double smart quotes remain readable, and cells, nonzero horizontal spacing and math attachments separate text leaves. Render plain text at 9 pt on one fixed line, truncate measured grapheme prefixes with a logical-end ellipsis, align to the text direction, and reserve a 2 mm counter gap. Bound extraction to 400 graphemes and a one-million-item for-loop traversal budget; handle apostrophes after letters/digits, separate cases and vertical spacing, and document same-type nested double-quote limits. Skip footnotes and placed content; document plain-text and unknown-atom behavior.
  • Exercise both footer sources across styled text, math operators, block containers, labelled content, footnotes, transformations, breaks, tall images, Hebrew, CJK, emoji and long words. Supply a licensed two-character CJK font fixture for deterministic offline PDF extraction.
  • Force synthesized plot super/sub glyphs at 7 pt, give missing/empty registers clear diagnostics linked to current public docs, and document footnote-first expansion, outline show-rule ordering, and explicitly styled math-attachment limits. Reject empty YAML and empty arrays in both compilation and schema validation; lead the README with the bound glossary API.
  • Extend real compiler/PDF acceptance checks, including a register over 150 KB through the actual compile hook, canonical recipe, and plain compiler.

Changelog Entry

Added

  • Typst plots, glossary and slides (#1994)
    • Ship devkit-docs 0.2.0 with licensed, offline lilaq plots, required axis labels and a 7 pt text minimum.
    • Load consumer glossary YAML directly, reject duplicate IDs, and reserve acronym expansion for body occurrences.
    • Keep plot ticks at 9 pt, enforce script and explicit math text minimums, and fit long slide footer titles.
    • Show plain slide footer text with measured grapheme truncation, a fixed line and a 2 mm counter gap, including RTL titles.
    • Extract deeply nested footer content iteratively, skip hidden text, separate cells and math leaves, and preserve term-item text and paired smart quotes.
    • Bound footer extraction and measurement to 400 graphemes, retain apostrophes, and separate cases and vertical spacing.
    • Synthesize readable script glyphs and provide bookmark-safe bound glossary terms with actionable setup errors and non-empty register validation.
    • Add a branded 16:9 slide layout with title, section and content slides, booktabs, captions and revision footers; retain older package imports.

Testing

  • RED regressions: 12 failed, 3 passed, exit 1. Reproduce the 10,000-iteration while-loop guard, uncapped output, apostrophe errors and missing cases/vertical separators; committed before implementation.
  • Targeted compiler, docs, guard and registry tests: 296 passed, exit 0.
  • Offline Nix house-style check: 165 compiler tests, retained imports, hook/recipe/layout checks and 21 style mutants passed, exit 0.
  • All 18 hosted checks passed on 409b608a94a10509ce28396ffdd71e1a9b24f1f5, including Test Summary, Project Tests, Project Flake Gates and both Home Matrix platforms.
  • Large-title fixtures cover 5,000 children, 1,000 nested sequences, 3,000 emphasised words and 10,000 words, with correct PDF prefixes, a 400-grapheme extraction bound and a 30-second compile deadline.

Commands:

uv run --with pytest-xdist pytest tests/typst_content.py tests/test_typst_docs.py packages/vig-utils/tests/test_typst_guard.py packages/vig-utils/tests/test_typst_packages.py -n 4 --basetemp="$HOME/.cache/devkit-pytest/1994e-r8-regressions" --durations=15
nix build .#checks.x86_64-linux.typst-house-style --no-link --max-jobs 1 --cores 2 -L

Manual Testing Details

pdftotext -bbox verifies plain prefixes, ellipses, page margins, a single line and at least 2 mm counter clearance. pdftohtml -xml verifies 9 pt footer text without inherited title styling. The traversal test places 15,000 hidden children before visible text, exercising more than 10,000 work items independently of the output cap. Combining-grapheme boundary tests cover 399, 400 and 401 clusters. Three apostrophe examples compare exact extraction with native Typst slide-body rendering; digit-following apostrophes separately assert the footer's explicit right-quote rule. Existing exact extraction and PDF tests retain deep nesting, source precedence, empty math, hidden content, term items, grouped cells, matrix/attachment separators, RTL and styling checks. Registry tests retain immutable 0.1.0/0.1.1 bytes and refresh only the unreleased 0.2.0 digest.

Checklist

  • Code follows project style guidelines
  • Self-review performed
  • Non-obvious implementation details commented
  • Documentation updated
  • Root and scaffold changelogs updated
  • No new compiler warnings
  • Acceptance tests added
  • Targeted existing tests pass
  • Phase 2a dependency merged

Additional Notes

Content guards remain the separate phase-3 PR. This fix round stays on the same branch and PR, rebased onto current dev; 0.2.0 does not collide with the published 0.1.1 package. No merge or workflow dispatch requested.

Refs: #1994

@gerchowl gerchowl mentioned this pull request Nov 3, 2026
15 of 23 tasks
@gerchowl
gerchowl force-pushed the feature/1994-typst-content branch from 036564f to d197d29 Compare November 4, 2026 01:34
@gerchowl
gerchowl merged commit fa7ab55 into dev Nov 4, 2026
18 checks passed
@gerchowl
gerchowl deleted the feature/1994-typst-content branch November 4, 2026 03:06
gerchowl added a commit that referenced this pull request Nov 4, 2026
## Description

Add docs-only content checks for missing figure captions, missing table
headers, direct page/font overrides, and SVG lettering below 7 pt at its
placed size. The shared hook supports skip globs and end-of-line
suppression with source diagnostics.

## Type of Change

- [x] `feat` -- New feature
- [x] `fix` -- Bug fix
- [x] `docs` -- Documentation only
- [ ] `chore` -- Maintenance task
- [ ] `refactor` -- Code restructuring
- [x] `test` -- Adding or updating tests
- [ ] `ci` -- CI/CD pipeline changes
- [ ] `build` -- Build system or dependency changes
- [ ] `revert` -- Reverts a previous commit
- [ ] `style` -- Code style changes

### Modifiers

- [ ] Breaking change (`!`)

## Changes Made

- Add `typst-content` through the shared docs hook definition and
portable asset; keep non-docs hook configuration unchanged.
- Query compiled content once per entry in one shared ephemeral mirror,
with source diagnostics and at most two compiler workers. Preserve
native image values and validate a clean original compile before falling
back from instrumentation failures or warnings.
- Resolve literal and variable image paths relative to their containing
source and retain generated assets. Honor table suppression without
derived-table duplicates, detect multiline function/closure template
overrides, and scope duplicate-label/fallback suppression to individual
calls in dependency/document order.
- Preserve markup and caption prose around inline expressions so
grid/column measurements stay instrumented, while retaining multiline
and imported closure checks.
- Attribute logos only to direct document-template parameters and
measure each logo/body placement independently; dictionary keys cannot
supply logo attribution. Instrument only compiler-reported dependency
sources with indexed scanning, linear edit assembly, and cached
dependency-edge tokenization.
- Measure SVG fit, nested SVG/symbol viewports, inherited font units,
height-only sizing, visible text and used definitions. Resolve CSS font
shorthand from Matplotlib 3.6–3.9 and the 3.10 font-size form with the
normal cascade and `!important`; warn on unresolved sizes and bounded
use expansion. Accept Matplotlib DOCTYPEs while blocking
entities/external references; warn per placement for Typst scale
transforms.
- Ship package 0.2.1 with guard-only layout measurements for
percentages, automatic sizing, grids, columns and figure bodies. Archive
the exact shipped 0.2.0 source and retain historical imports and hashes.
- Document fallback sizing, unresolved-size warnings, SVG limitations
and suppression. Add a dedicated sandboxed compiler contract and a
reproducible medium-document benchmark.

- Track code and markup with one structural tokenizer, including
multiline else chains, smart quotes, URLs, escaped hashes and qualified
builtin calls. Reuse its modes, delimiters and comments for
instrumentation.
- Record effective paper, margins and font in guard-only package
contexts at page starts and headings. Report runtime bypasses by page;
document the entry-level runtime suppression marker.
- Warn on incomplete CSS blocks and cap selector/node work at 1,000,000,
including repeated reference visits.

## Changelog Entry

### Added

- **Opt-in Typst content guards**
([#1994](#1994))
- Check figure captions, table headers, house-style overrides and SVG
text below 7 pt at its placed size, with skip globs and source-line
suppression.
- Retain prior house-style imports and add 0.2.1 guard-only layout
measurements without changing normal PDF output.

## Testing

- [ ] Full local suite (`just test`); delegated to CI as required by the
task brief.
- [x] Targeted tests pass locally.
- [x] Manual testing performed.

### Manual Testing Details

- RED tests were committed before implementation. Scanner regressions,
seven runtime alias cases, repeated-reference CSS work and
replaced-header cases each failed before their fixes (pytest exit 1).
- Targeted scanner, compiler contracts, guards, package integrity and
docs scaffolding: 278 passed, exit 0. Final runtime and normal-output
equality regressions after moving page probes into the background: 11
passed, exit 0.
- Final `nix build .#checks.x86_64-linux.typst-content
.#checks.x86_64-linux.typst-house-style --no-link --max-jobs 1 --cores 2
-L`: exit 0. Includes 115 content compiler contracts, 165 house-style
tests, the remaining native/layout contracts and 21 killed style
mutants.
- Six content mutants killed: markup content inheriting code mode, logo
closing-line suppression, reference-depth cap, inline-call adjacency,
context introducer and direct template-logo attribution. Every mutant
exits 1 on an explicit assertion or missing expected exception; the
mutation harness exits 0.
- Normal 0.2.1 PDFs are byte-identical to released 0.2.0; its archived
package digest matches the unchanged release lock. Historical imports
remain resolvable.
- Prior review benchmark: `uv run python
packages/vig-utils/tests/benchmark_typst_content.py --entries 1
--figures-per-entry 4000 --unrelated-files 0` measured 60.567s before
and 21.052s after, both exit 0. This round adds a source-tokenization
count regression and caps CSS cascade work at 1,000,000 selector/node
evaluations, including repeated references.
- All 18 checks passed on pushed head
`1490cf833f09e1d94c4902354f980f609b5eb759`. [CI including Test
Summary](https://github.com/vig-os/devkit/actions/runs/41766273353),
[Home
Matrix](https://github.com/vig-os/devkit/actions/runs/41766273344), and
[CodeQL](https://github.com/vig-os/devkit/actions/runs/41766273252)
completed successfully.

Current local pytest commands (each exit 0):

```sh
uv run --with pytest-xdist pytest packages/vig-utils/tests/test_typst_content_unit.py packages/vig-utils/tests/typst_content_contract.py packages/vig-utils/tests/test_typst_guard.py packages/vig-utils/tests/test_typst_packages.py tests/test_typst_docs.py -n 4 --basetemp=$HOME/.cache/devkit-pytest/1994f-r6-rebased -q
uv run --with pytest-xdist pytest packages/vig-utils/tests/typst_content_contract.py -k 'runtime or normal_output_unchanged' -n 4 --basetemp=$HOME/.cache/devkit-pytest/1994f-r6-header-green -q
```

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented hard-to-understand areas
- [x] I have updated the documentation accordingly
- [x] I have updated both CHANGELOGs and the generated changelog copy
- [x] My changes generate no new warnings or errors in normal builds
- [x] I have added tests that prove the feature works
- [x] New and relevant existing unit tests pass locally
- [x] Any dependent changes have been merged and published

## Additional Notes

Relative and automatic sizing without package metadata uses the
documented page-width fallback. Unresolved sizing/font shorthand,
unsupported SVG styling, scale transforms and SVG use expansion limits
emit named warnings. SVG traversal is capped at 32 reference levels and
32,768 visited nodes, including repeated reference contents. Unsupported
uppercase font properties, declaration comments and spaced importance
markers warn explicitly. Images from bytes have no inspectable source
path and are documented as skipped. Raster images and lettering
converted to outlines cannot be measured. Rebased onto #2017; retain the
released 0.2.0 source and hash while shipping guard instrumentation in
0.2.1.

The retained 0.2.0 package is an unchanged archive of previously
reviewed source from #2017. Shared defusedxml is retained so dynamically
activated docs hooks and recipes always use the same hardened parser
without a second Python environment; the dependency tradeoff is
documented in both CHANGELOGs.

Refs: #1994
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant