Parent: gdata-server/todo
Goal: the HTML renderer (notes_web.py) should serve any note in a requested output format chosen purely by content type / format selector — request the type, get the appropriate output — through one integrated path, not a separate CLI tool. The visual formats (HTML, PDF, PostScript, PNG) should share a single render so they always match.
Formats to support
- HTML — browser default. Already supported.
- JSON — straight pass-through of the JSONHTL document. Already supported.
- Raw text (text/plain) — already supported; diagrams may be omitted or represented by their alt text.
- Markdown (text/markdown) — already supported.
- YAML — already supported.
- PDF — NEW. Must render well and embed inline SVG diagrams (not just text).
- PostScript — NEW. Same rendered layout, PS output.
- Candidate extras likely to be wanted: PNG (raster of the rendered page, for previews/thumbnails/sharing) and possibly a single-file SVG of the whole page.
Key requirement: the visual exports must cover SVG diagrams
PDF/PostScript/PNG must include inline SVG blocks (diagrams), which the current exporter does not. This is the main gap — a note that is mostly diagrams must export faithfully, not as text-only.
Current state (2026-10-24)
negotiate_format() in notes_web.py supports only html / json / markdown / plain / yaml; Accept: application/pdf returns None → HTTP 406 (pinned by test_serve_note_406_body). PDF exists solely as a separate CLI, notes_to_pdf.py, whose pipeline is pandoc → groff(ms) → ps2pdf — markdown-based, so it drops SVG diagrams entirely. See gdata-server/http-formats.
Implementation notes
- Wire PDF/PS (and any raster) into negotiate_format() + _serve_note() with correct media types and Vary: Accept, so selection is uniform with the existing formats.
- Choose a render engine that embeds SVG: WeasyPrint (HTML+CSS+SVG → PDF) is the natural fit because it can consume the HTML renderer's own output directly; headless Chromium --print-to-pdf is an alternative. Both handle inline SVG.
- Derive PostScript from the same rendered output (e.g. pdftops / pdf2ps) or the engine's own PS writer; derive PNG by rasterising the same render.
- Keep JSON / Markdown / plain as pure pass-through / text — no diagram rendering needed there.
- Prefer reusing the single HTML render as the source of truth so every visual format stays consistent.
Raised 2026-10-24. Interim workaround: cairosvg exports an SVG block to a vector PDF ad hoc (cairosvg x.svg -o x.pdf, merge with pdfunite) — see the authoring/export tips in notes-browser/svg-diagrams.