repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

Iteration 13: Corrected diagram-filter.lua accuracy: removed misleading PlantUML support, made it explicitly Graphviz dot/graphviz only, fixed MIME types for PDF outputs (application/pdf), removed unused generate_image function, and improved graceful fallback diagnostic if dot is missing. Updated SKILL.md wording. Verified PlantUML blocks are ignored, dot blocks either generate or fall back unchanged, no PlantUML claims remain, 9/9 filters pass.

d7037c20b42d8058b14d1ee49dbe35f8dfa6c03a

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Result: {"status":"keep","skill_quality":32}

Changed files (4)

.pi/autoresearch/session.jsonl

Modified
1 1 {"run":10,"commit":"4d2e499","metric":29,"metrics":{},"status":"keep","description":"Iteration 10: Added Programmatic Lua API subsection under Lua Filters covering pandoc.read/write, building Pandoc docs from scratch, file→transform→write pipelines, format conversion in Lua, and metadata access. Verified all programmatic examples with pandoc lua. Fixed expected HTML output for manual Header (no auto id). 9/9 filters pass.","timestamp":1780157777826,"segment":0,"confidence":null,"asi":{"hypothesis":"Add programmatic Lua API coverage for agents that need document processing in code, not shell; fix example accuracy against actual pandoc output","new_coverage":"pandoc.read, pandoc.write, build AST from scratch, doc:walk transform, file read/write, metadata access","examples_verified":"4 programmatic examples passed via pandoc lua","accuracy_fix":"manual Header output has no id unless attr set; corrected expected output","filters":"9/9 pass"}}
2 2 {"run":11,"commit":"df7626a","metric":30,"metrics":{},"status":"keep","description":"Iteration 11: Added pandoc-doctor.lua cross-platform diagnostics script and Decision Guide entry. Doctor reports pandoc/API version, OS/arch, reader/writer counts, key format support, common PDF engine availability, executable version, and markdown→html smoke test. Verified output, SKILL.md references, section refs, and 9/9 filters. Scripts: 6.","timestamp":1780157854132,"segment":0,"confidence":null,"asi":{"hypothesis":"Add environment diagnostics for agents debugging PDF engine/format/support failures; reduces troubleshooting friction without bloating main docs","doctor_checks":"version, API, OS/arch, readers/writers, important formats, PDF engines, executable, smoke test","validation":"doctor runs, key diagnostics present, no missing Decision Guide refs, 9/9 filters pass","scripts":6}}
3 +{"run":12,"commit":"941acac","metric":31,"metrics":{},"status":"keep","description":"Iteration 12: Hardened wrapper scripts by replacing os.execute/string command construction with pandoc.pipe argv-list calls in batch-convert, md-to-pdf, web-to-md, and docx-to-md. Fixed batch pattern bug and changed web-to-md to preserve H1 instead of silently shifting it into metadata. Verified filenames with spaces, docx→md with spaces, web H1 preservation, 0 os.execute in scripts, 9/9 filters pass.","timestamp":1780157980678,"segment":0,"confidence":null,"asi":{"hypothesis":"Security/portability hardening: scripts were cross-platform but used shell command strings; argv-list pandoc.pipe avoids shell quoting bugs and handles spaces safely","fixed_bugs":"batch pattern invalid escape; web-to-md dropped H1 due shift-heading-level-by=-1","validation":"space-containing filenames convert; docx with spaces extracts; web H1 preserved; 0 os.execute; 9/9 filters","scripts_hardened":4}}

skills/pandoc/SKILL.md

Modified
1136 1136 - `remove-empty-paras.lua` — Strip empty paragraphs
1137 1137 - `admonitions.lua` — Style `:::note`/`:::warning`/`:::tip` div blocks
1138 1138 - `autolink.lua` — Convert bare URLs into clickable links
1139 -- `diagram-filter.lua` — Generate images from code blocks via pandoc.pipe + mediabag
1139 +- `diagram-filter.lua` — Generate Graphviz images from `dot` code blocks via pandoc.pipe + mediabag
1141 1141 ### Reusable Defaults Files

skills/pandoc/ideas.md

Modified
7 7 - Sandbox mode for untrusted input
8 8 - Admonitions filter (:::note/:::warning/:::tip/:::danger)
9 9 - Autolink filter (bare URLs → clickable links)
10 -- Diagram filter (pandoc.pipe + mediabag pattern)
10 +- Diagram filter (Graphviz `dot` code blocks via pandoc.pipe + mediabag pattern; graceful fallback if dot missing)
11 11 - pdf-report.yaml and html-report.yaml defaults
12 12 - Cross-platform Lua scripts (batch-convert, md-to-pdf, docx-to-md, web-to-md, wordcount, doctor)
13 13 - pandoc.system.list_directory for portable dir listing

skills/pandoc/references/filters/diagram-filter.lua

Modified
1 --- diagram-filter.lua — Example: generate diagrams from code blocks via external tools
1 +-- diagram-filter.lua — Generate Graphviz diagrams from code blocks
2 2 -- Usage: pandoc --lua-filter=diagram-filter.lua doc.md -o out.html
4 --- Demonstrates pandoc.pipe + mediabag for agents that need to
5 --- transform code blocks into images (e.g., PlantUML, graphviz, etc.)
4 +-- Demonstrates pandoc.pipe + pandoc.mediabag for agents that need to
5 +-- transform code blocks into generated images.
6 +--
7 +-- Requires: graphviz `dot` in PATH.
7 9 -- In your Markdown:
8 --- ``` plantuml
9 --- @startuml
10 --- Alice -> Bob: Hello
11 --- Bob --> Alice: Hi!
12 --- @enduml
10 +-- ``` dot
11 +-- digraph { Alice -> Bob; Bob -> Alice }
13 12 -- ```
15 -local function generate_image(src, fmt)
16 - -- This example uses graphviz (dot) as the external tool.
17 - -- Replace with any CLI tool: plantuml, ditaa, mermaid-cli, etc.
18 - local ok, result = pcall(pandoc.pipe, "dot", {"-T" .. fmt}, src)
19 - if not ok then
20 - io.stderr:write("diagram-filter: " .. tostring(result) .. "\n")
21 - return nil
22 - end
23 - return result
24 -end
13 +--
14 +-- Supported classes: dot, graphviz
15 +-- On error or missing `dot`, leaves the original code block unchanged.
26 17 local format_map = {
27 - html = "svg",
28 - html4 = "svg",
29 - html5 = "svg",
30 - latex = "pdf",
31 - beamer = "pdf",
32 - typst = "svg",
18 + html = {ext = "svg", mime = "image/svg+xml"},
19 + html4 = {ext = "svg", mime = "image/svg+xml"},
20 + html5 = {ext = "svg", mime = "image/svg+xml"},
21 + latex = {ext = "pdf", mime = "application/pdf"},
22 + beamer = {ext = "pdf", mime = "application/pdf"},
23 + typst = {ext = "svg", mime = "image/svg+xml"},
35 -function CodeBlock(el)
36 - -- Only process code blocks with class "plantuml" or "dot"
37 - local is_diagram = false
26 +local function has_class(el, wanted)
38 27 for _, cls in ipairs(el.classes) do
39 - if cls == "plantuml" or cls == "dot" or cls == "graphviz" then
40 - is_diagram = true
41 - break
42 - end
28 + if wanted[cls] then return true end
29 + end
30 + return false
31 +end
33 +function CodeBlock(el)
34 + if not has_class(el, {dot = true, graphviz = true}) then
35 + return el
45 - if not is_diagram then return el end
38 + local target = format_map[FORMAT] or {ext = "png", mime = "image/png"}
39 + local ok, img_data = pcall(pandoc.pipe, "dot", {"-T" .. target.ext}, el.text)
47 - local img_fmt = format_map[FORMAT] or "png"
48 - local mime = img_fmt == "svg" and "image/svg+xml" or "image/png"
50 - -- For dot/graphviz, pass directly. For plantuml, you'd adjust the command.
51 - local cmd = "dot"
52 - local args = {"-T" .. img_fmt}
54 - local ok, img_data = pcall(pandoc.pipe, cmd, args, el.text)
55 41 if not ok then
56 - io.stderr:write("diagram-filter error: " .. tostring(img_data) .. "\n")
57 - return el -- leave code block unchanged on error
42 + io.stderr:write("diagram-filter: graphviz dot failed; leaving code block unchanged\n")
43 + io.stderr:write(tostring(img_data):match("([^\r\n]+)") .. "\n")
44 + return el
60 - -- Store in mediabag and create image reference
61 - local fname = pandoc.utils.sha1(img_data) .. "." .. img_fmt
62 - pandoc.mediabag.insert(fname, mime, img_data)
47 + local fname = pandoc.utils.sha1(img_data) .. "." .. target.ext
48 + pandoc.mediabag.insert(fname, target.mime, img_data)
64 50 return pandoc.Para({pandoc.Image({}, fname)})