|
| 1 | +# K9 Pandoc Reader, Writer, and Filter |
| 2 | + |
| 3 | +## Summary |
| 4 | + |
| 5 | +Custom Pandoc reader, writer, and Lua filter for K9 Self-Validating Components — a security-tiered service configuration format built on Nickel, with three trust levels (Kennel, Yard, Hunt) and structured pedigree metadata. |
| 6 | + |
| 7 | +K9 files come in two syntaxes: YAML (`.k9`) for Kennel-level configs and Nickel (`.k9.ncl`) for Yard/Hunt-level components with contracts, recipes, and cryptographic signing. This tooling enables converting K9 documents to HTML, PDF, DOCX, Markdown, and all other Pandoc-supported formats. |
| 8 | + |
| 9 | +## Components |
| 10 | + |
| 11 | +- **k9.lua** — Comprehensive Pandoc custom reader (597 lines). Auto-detects YAML vs Nickel syntax, extracts pedigree metadata, identifies security trust level, and parses records, contracts, recipes, and bindings into the Pandoc AST. |
| 12 | +- **k9-reader.lua** — Lightweight reader variant (92 lines) for quick extraction. |
| 13 | +- **k9-writer.lua** — Custom Pandoc writer (230 lines). Converts any Pandoc AST to valid K9 Nickel output with pedigree blocks, security settings, recipe definitions, and proper multiline string syntax (`m%"..."%`). |
| 14 | +- **k9-filter.lua** — Post-processing Lua filter with four passes: security badge colouring (green/amber/red for trust levels), contract annotation highlighting, recipe command validation (80+ known tools), and pedigree completeness checking. |
| 15 | +- **k9.html** — HTML5 Pandoc template with security-level-adaptive header bar, pedigree summary card, contract styling, recipe blocks with labels, copy-to-clipboard on code blocks, and responsive/print-friendly layout. |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
| 19 | +```sh |
| 20 | +# K9 Nickel to HTML (full pipeline) |
| 21 | +pandoc -f k9.lua input.k9.ncl \ |
| 22 | + --lua-filter=k9-filter.lua \ |
| 23 | + --template=k9.html \ |
| 24 | + -o output.html |
| 25 | + |
| 26 | +# K9 YAML to PDF |
| 27 | +pandoc -f k9.lua config.k9 -o output.pdf |
| 28 | + |
| 29 | +# Round-trip: K9 to AST to K9 |
| 30 | +pandoc -f k9.lua input.k9.ncl -t k9-writer.lua -o roundtrip.k9.ncl |
| 31 | +``` |
| 32 | + |
| 33 | +## Requirements |
| 34 | + |
| 35 | +- Pandoc 3.0+ with Lua support |
| 36 | + |
| 37 | +## Spec |
| 38 | + |
| 39 | +- K9 SVC specification: <https://github.com/hyperpolymath/standards/tree/main/k9-svc> |
| 40 | +- Media type: `application/vnd.k9+nickel` (IANA registration pending) |
| 41 | + |
| 42 | +## Related |
| 43 | + |
| 44 | +- [pandoc/lua-filters](https://github.com/pandoc/lua-filters) — Community Lua filters repository |
| 45 | +- [K9 LSP server](../lsp/) — Language Server Protocol implementation |
| 46 | +- [VS Code extension](../editors/vscode/) — Syntax highlighting for VS Code |
| 47 | +- [K9 specification](../SPEC.adoc) — Full K9 SVC specification |
| 48 | +- [Pedigree contract](../pedigree.ncl) — Nickel contract defining component structure |
| 49 | + |
| 50 | +## License |
| 51 | + |
| 52 | +PMPL-1.0-or-later (Palimpsest License) |
| 53 | + |
| 54 | +## Author |
| 55 | + |
| 56 | +Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk> |
0 commit comments