PANDOC_VERSION:must_be_at_least'3.0'-- Minimalistic PlantUML to SVG filter for Pandoc---- Fenced code (also ```puml):-- ```plantuml-- @startuml ... @enduml-- ```---- Bracket attributes (Pandoc markdown):-- ```{.plantuml caption="Title" align=left #my-id}-- @startuml ... @enduml-- ```---- Same-line attributes (Pandoc markdown):-- ```plantuml {caption="Title" align=left #my-id}-- @startuml ... @enduml-- ```---- Note: With reader `gfm`, bracket fences become class "{.plantuml" (GFM has no-- fenced_code_attributes). We still treat that as PlantUML so the diagram runs.-- Pandoc 3.x: document metadata is not on PANDOC_STATE (unknown key if indexed).localplantuml_path='plantuml'-- GFM puts the first word of the info string in classes, e.g. "{.plantuml".localfunctionclass_signals_plantuml(c)ifc=='plantuml'orc=='puml'thenreturntrueendifstring.find(c,'{.plantuml',1,true)==1thenreturntrueendifstring.find(c,'{.puml',1,true)==1thenreturntrueendreturnfalseendlocalfunctionblock_is_plantuml(block)for_,cinipairs(block.classes)doifclass_signals_plantuml(c)thenreturntrueendendreturnfalseendfunctionMeta(m)ifm['plantuml-path']thenplantuml_path=pandoc.utils.stringify(m['plantuml-path'])endreturnmendfunctionCodeBlock(block)ifnotblock_is_plantuml(block)thenreturnnilendlocalsuccess,svg=pcall(pandoc.pipe,plantuml_path,{'-tsvg','-pipe','-charset','UTF8'},block.text)ifnotsuccessthenio.stderr:write("[plantuml.lua] PlantUML Error: "..tostring(svg).."\n")returnnilend-- Use hash of SVG content as filenamelocalfname=pandoc.sha1(svg)..'.svg'pandoc.mediabag.insert(fname,'image/svg+xml',svg)-- Create the image element (inherit CodeBlock attr: align, etc.)localalt_raw=block.attributes.captionlocalalt=alt_rawandpandoc.utils.stringify(alt_raw)or''localimg=pandoc.Image(alt_rawor{},fname,'',block.attr)-- Wrap in Figure if a caption is provided in attributesifalt~=''thenreturnpandoc.Figure({pandoc.Plain{img}},{pandoc.Plain{pandoc.Str(alt)}},block.attr)endreturnpandoc.Para{img}endreturn{{Meta=Meta},{CodeBlock=CodeBlock}}