diff --git a/build.sh b/build.sh index 32b4377..0325223 100755 --- a/build.sh +++ b/build.sh @@ -772,7 +772,6 @@ do_latex() { --highlight-style=${SYNTAX_HIGHLIGHT_STYLE} --template=${TEMPLATE_PDF} --lua-filter=convert-diagrams.lua - --lua-filter=convert-aasvg.lua --lua-filter=convert-images.lua --lua-filter=center-images.lua --lua-filter=informative-sections.lua @@ -883,7 +882,6 @@ do_docx() { --embed-resources --standalone --lua-filter=convert-diagrams.lua - --lua-filter=convert-aasvg.lua --lua-filter=convert-images.lua --lua-filter=parse-html.lua --lua-filter=apply-classes-to-tables.lua @@ -927,7 +925,6 @@ do_html() { --template=${TEMPLATE_HTML} ${HTML_STYLESHEET_ARGS} --lua-filter=convert-diagrams.lua - --lua-filter=convert-aasvg.lua --lua-filter=parse-html.lua --lua-filter=apply-classes-to-tables.lua --lua-filter=landscape-pages.lua diff --git a/filter/convert-aasvg.lua b/filter/convert-aasvg.lua deleted file mode 100644 index d6673c7..0000000 --- a/filter/convert-aasvg.lua +++ /dev/null @@ -1,63 +0,0 @@ --- Turn aasvg-classed code blocks into figures, retaining other classes on the --- code block as classes on the figure. - --- Patch the path to include the current script's directory. -package.path = package.path .. ";" .. debug.getinfo(1).source:match("@?(.*/)") .. "?.lua" -utils = require "utils" - -function aasvgFigure(code, caption, attrs) - local filename_base = '.cache/' .. attrs.identifier .. '.' .. utils.getContentsHash('code=' .. code .. 'caption=' .. pandoc.utils.stringify(caption) .. 'attrs=' .. pandoc.utils.stringify(attrs)) .. '.aasvg' - local filename_svg = filename_base .. '.svg' - local filename_pdf = filename_base .. '.pdf' - - if utils.fileExists(filename_pdf) then - print(string.format(" not converting %s (already up-to-date as %s)", attrs.identifier, filename_pdf)) - else - print(string.format('rendering %s using aasvg ...', filename_svg)) - if not utils.runCommandWithInput(string.format( - "aasvg --fill > %s 2>&1", filename_svg), code) then - print(string.format('failed to convert ASCII art SVG (aasvg) diagram to %s using aasvg, falling back to letting LaTeX try to pick it up', filename_svg)) - return false - else - print(string.format(" rendered %s to %s", attrs.identifier, filename_svg)) - end - - print(string.format('converting %s to %s using rsvg-convert ...', filename_svg, filename_pdf)) - if not utils.runCommandSuppressOutput(string.format("rsvg-convert --format=pdf --keep-aspect-ratio --output %s %s 2>&1", filename_pdf, filename_svg)) then - print(string.format('failed to convert %s to %s using rsvg-convert, falling back to letting LaTeX try to pick it up', filename_svg, filename_pdf)) - return false - else - print(string.format(' converted %s to %s', filename_svg, filename_pdf)) - end - - -- Delete stale copies of the files. This makes it easier to cache only the latest converted pdfs. - -- Don't do this if the "keepstaleimages" variable is set. - if not PANDOC_WRITER_OPTIONS.variables["keepstaleimages"] then - utils.deleteFilesExcept('.cache/' .. attrs.identifier .. '*.aasvg.svg*', filename_svg) - utils.deleteFilesExcept('.cache/' .. attrs.identifier .. '*.aasvg.pdf*', filename_pdf) - end - end - - local img = pandoc.Image(caption, filename_pdf) - return pandoc.Figure(img, caption, attrs) -end - -function CodeBlock(el) - local isAasvg = false - local figure_classes = pandoc.List({}) - for i, class in ipairs(el.classes) do - if class == 'aasvg' then - isAasvg = true - else - figure_classes:insert(class) - end - end - if isAasvg then - local caption = {long = pandoc.Plain(pandoc.Str(el.attributes.caption))} - local attrs = pandoc.Attr(el.identifier, figure_classes) - el.identifier = nil - el.classes = {'aasvg'} - return aasvgFigure(el.text, caption, attrs) - end - return el -end diff --git a/filter/convert-diagrams.lua b/filter/convert-diagrams.lua index d63bcb0..8958d05 100644 --- a/filter/convert-diagrams.lua +++ b/filter/convert-diagrams.lua @@ -1,5 +1,5 @@ --- Turn mermaid and plantuml code blocks into figures, retaining other classes --- on the code block as classes on the figure. +-- Turn aasvg, mermaid, or plantuml code blocks into figures, retaining +-- other classes on the code block as classes on the figure. -- Patch the path to include the current script's directory. package.path = package.path .. ";" .. debug.getinfo(1).source:match("@?(.*/)") .. "?.lua" @@ -71,6 +71,10 @@ function convertFigure(code, caption, attrs, extension, convert_command) return pandoc.Figure(img, caption, attrs) end +function aasvgFigure(code, caption, attrs) + return convertFigure(code, caption, attrs, ".aasvg.svg", "aasvg --fill > %s 2>&1") +end + function mermaidFigure(code, caption, attrs) return convertFigure(code, caption, attrs, mermaid_extension[FORMAT] or mermaid_extension["pdf"], "mmdc --configFile /resources/filters/mermaid-config.json --puppeteerConfigFile ./.puppeteer.json --width 2000 --height 2000 --backgroundColor transparent --pdfFit --input - --output %s 2>&1") @@ -86,7 +90,7 @@ function CodeBlock(el) local figure_classes = pandoc.List({}) for i, class in ipairs(el.classes) do - if class == 'mermaid' or class == 'plantuml' then + if class == 'aasvg' or class == 'mermaid' or class == 'plantuml' then diagramType = class else figure_classes:insert(class) @@ -97,6 +101,9 @@ function CodeBlock(el) local caption = {long = pandoc.Plain(pandoc.Str(el.attributes.caption))} local attrs = pandoc.Attr(el.identifier, figure_classes) + if diagramType == 'aasvg' then + return aasvgFigure(el.text, caption, attrs) + end if diagramType == 'mermaid' then return mermaidFigure(el.text, caption, attrs) end diff --git a/guide.tcg b/guide.tcg index 937d875..22fd0fc 100644 --- a/guide.tcg +++ b/guide.tcg @@ -605,7 +605,7 @@ Users are encouraged to use AES instead. # Figures {#sec:figures} -There are various ways to include a figure in a document: as an image file checked into the repository, as a [Mermaid](http://mermaid.js.org) diagram, and as an [aasvg](https://github.com/martinthomson/aasvg) diagram. +There are various ways to include a figure in a document: as an image file checked into the repository, or as a [Mermaid](http://mermaid.js.org) or [PlantUML](https://plantuml.com) or [aasvg](https://github.com/martinthomson/aasvg) diagram. ## Images