pandoc / lua-filters

A collection of lua filters for pandoc
MIT License
600 stars 165 forks source link

diagram-generator empty caption (`caption=""`) causes unexpected behavior #262

Closed fuhrmanator closed 1 year ago

fuhrmanator commented 1 year ago

I was working on a big document and didn't see the figure caption (or number) anymore for one of my PlantUML diagrams. I had forgotten to complete the caption:

```{.plantuml #fig-my_diagram caption=""}
...

The figure appears properly, but there are no errors. I wish I had known about this before the PDF went for proofing.

So, I hacked a modification to the filter (I'm not much of a lua programmer), but it looks like this, replacing lines https://github.com/pandoc/lua-filters/blob/master/diagram-generator/diagram-generator.lua#L354-L358

  -- If the user defines a caption, read it as Markdown.
  local caption = {}
  if block.attributes.caption then
    if (block.attributes.caption == "") then
      error("Diagram caption defined but has empty value, replacing with value 'EMPTY CAPTION'.")
      block.attributes.caption = "EMPTY CAPTION"
    end
    caption = pandoc.read(block.attributes.caption).blocks or pandoc.Blocks{}
  end

  local alt = pandoc.utils.blocks_to_inlines(caption)

It results in RED console output (I use Pandoc in Quarto):

ERROR: Diagram caption defined but has empty value, replacing with value 'EMPTY CAPTION'.

and I can search in my PDF file for the bad caption (I wasn't sure how to provide more context/location info inside the LUA error).

It's not a huge issue, but would save time if someone else makes this (admittedly stupid) mistake.

tarleb commented 1 year ago

Thanks for the report. The diagram generator now has a new home at https://github.com/pandoc-ext/diagram. I don't think I want to change the filter's behavior with regard to empty captions, as other users might use them intentionally. Relevant xkcd: https://xkcd.com/1172/