Skip to content

Latest commit

 

History

History
126 lines (101 loc) · 6.38 KB

export_docs_formats.md

File metadata and controls

126 lines (101 loc) · 6.38 KB

testing / export_docs_formats.sh

Revision: 4 Last modified: 2026-12-04T14:04:05Z

Overview

scripts/testing/export_docs_formats.sh is the ONE exporter of the §11.4.60 documentation classes. It turns every class instance's Markdown into a .html sibling and a .pdf sibling beside it.

It exists because the repository had no format artefacts and two gaps: ls docs/*.html docs/*.pdf returned 0 files (the formats switch was OFF and nothing demanded exports), and even with the switch ON the engine's own exporter (workable-items export --formats) covers only the four tracker documents — docs/CONTINUATION.md, README.md, every Status.md and every Status_Summary.md had no exporter at all. This script closes both.

The export step is composed of four pieces:

Piece Role
scripts/lib/doc_class_set.sh the ONE enumeration of the eight classes (fixed six + discovered Status fleet)
scripts/testing/escape_unknown_html_tags.py converter fix: escapes source placeholders (<pid>, <N>, <hash of ignored non-pycache files>) that pandoc would emit as raw markup, and preserves real HTML
scripts/testing/export_docs_formats.sh this exporter: switch resolution, pandoc → sanitize → weasyprint, verification, atomic install
scripts/testing/validate_export_html.py the independent well-formedness oracle (also run by tests/test_export_docs_formats.sh)

Prerequisites

  • pandoc (3.x) and weasyprint (60+) on PATH. Measured on this host 2026-12-04: pandoc 3.11, WeasyPrint 69.0.
  • The formats-export switch ENABLED for the repository being exported. This repo opts in through docs/context/doc_export.policy containing enabled=1; a one-run override is DOCS_EXPORT=1. The constitution-wide default (config/formats_export.conf) stays formats_export=false — the operator order of 2026-10-26 is not changed by this repository's opt-in.

Usage examples

# export every class instance (writes .html + .pdf beside each .md)
scripts/testing/export_docs_formats.sh

# read-only: report missing/stale siblings, write nothing; exit 1 when any
scripts/testing/export_docs_formats.sh --check

# export only what is missing or older than its .md
scripts/testing/export_docs_formats.sh --only-stale

# explicit root (used by tests and by the sync wrapper)
scripts/testing/export_docs_formats.sh --root /path/to/repo

# one-run switch override (no policy file needed)
DOCS_EXPORT=1 scripts/testing/export_docs_formats.sh

# the two internal helpers, directly
python3 scripts/testing/escape_unknown_html_tags.py --self-test
python3 scripts/testing/validate_export_html.py --self-test
python3 scripts/testing/validate_export_html.py docs/Issues.html README.html

Exit codes: 0 all fresh/exported · 1 --check found missing or stale · 2 usage/environment · 3 switch OFF (UNVERIFIED — deliberately not 0) · 4 toolchain absent · 5 export or verification failure · 6 sanitizer missing.

Edge cases

  • Switch OFF. Prints an announced SKIPPED (UNVERIFIED, exit 3). A disabled switch is not compliance, so it never exits 0 (§11.4.201(1)).
  • Toolchain absent. Exits 4 with the missing tool names. Nothing is faked: a placeholder HTML/PDF is never installed (§11.4.6, §11.4.222).
  • Degenerate output. Every produced file is verified before it is installed: HTML must exceed 1 KiB and end in </html>, PDF must exceed 1 KiB and start with %PDF-. A file that fails is not installed and the run FAILs.
  • Converter drift. The sanitizer must be idempotent; the exporter re-runs it and compares bytes, and refuses to ship a drifting export. It also greps for a surviving UPPERCASE element name (never valid HTML) and FAILs.
  • A fixed class that does not exist (e.g. no docs/Fixed.md yet) is REPORTED as CLASS ABSENT and does not fail the run — an absent instance and a clean instance must not look identical, so it is named, not counted away.
  • The Status fleet is discovered with find docs -name Status.md -o -name Status_Summary.md, never a static list, because integrations land per phase.
  • Concurrency. Outputs are written to a temp file and renamed, so a reader never observes a half-written sibling.

Internal behaviour

  1. Resolve the root (--root, else the git toplevel, else the constitution root).
  2. Source scripts/lib/doc_class_set.sh (class list) and scripts/formats_export_lib.sh (the ONE switch reader — the conf and the policy file are never parsed here).
  3. Enumerate the class instances; report absent fixed classes.
  4. For each instance: pandoc --standalone -f markdown-yaml_metadata_block -t html5 --metadata title=<name> → escape_unknown_html_tags.py (twice, to prove idempotence) → residual uppercase-tag check → verify_html → weasyprint → verify_pdf → atomic install.
  5. --check compares mtimes only ([ sibling -ot md ]) and writes nothing.

Why the sanitizer exists (measured 2026-12-04, before the fix): pandoc passes any <name ...> from Markdown through as raw HTML, and these tracker documents legitimately contain 60+ placeholder spellings as literal text. The first generation of these exports produced 714 findings in the project's own well-formedness walk (548 in docs/Issues.html alone); after the converter fix every one of the eight exports validates clean. The figures and the validator command are recorded in docs/notes/export-toolchain.md.

Related scripts

  • scripts/testing/sync_issues_docs.sh — the wrapper; its stage 3 calls this exporter and reports EXPORTED/SKIPPED from this script's real exit code.
  • scripts/gates/cm_docs_composite_sync.sh — the parity gate (+ paired scripts/gates/cm_docs_composite_sync_mutation_test.sh).
  • scripts/formats_export_lib.sh — the ONE switch reader.
  • scripts/lib/doc_class_set.sh — the ONE class enumeration.
  • tests/test_export_docs_formats.sh — the §11.4.224 test (real toolchain, two independent HTML oracles: validate_export_html.py and xmllint).
  • docs/notes/export-toolchain.md — measured toolchain availability, the before/after validator counts, and what remains owed.

Last verified

2026-12-04 — all eight class instances exported and validated clean (validate_export_html.py: 8 files, 0 findings; xmllint --html: accepted); tests/test_export_docs_formats.sh = 14/14 PASS, 0 skipped; cm_docs_composite_sync_mutation_test.sh = 9/9 PASS.