jgm/pandocfilters

pandoc crashes if I try to replace an image

Closed this issue · 6 comments

I'm writing a filter for pandoc, but if I try to remove images I get an error. Here's a minimal filter:

from pandocfilters import toJSONFilter, RawBlock


def filter(key, value, format, meta):
    if key == 'Image':
        return RawBlock('html', 'ok')


if __name__ == "__main__":
    toJSONFilter(filter)

Here's the error:

pandoc: Error in $.blocks[17].c[0]: failed to parse field blocks: failed to parse field c: mempty
CallStack (from HasCallStack):
  error, called at pandoc.hs:144:42 in main:Main

I call pandoc without any extra options, just --filter my_filter.py and -o output.html.

Version:

pandoc 1.19.2.1
Compiled with pandoc-types 1.17.0.4, texmath 0.9, skylighting 0.1.1.4

on Windows 10 x64

jgm commented

Pandoc --version says

pandoc 1.19.2.1
Compiled with pandoc-types 1.17.0.4, texmath 0.9, skylighting 0.1.1.4

I tried both pandocfilters-1.4.1 and -1.4.2.

jgm commented

Oh, the problem is that you use RawBlock instead of RawInline.
An image is an Inline.
Sorry, this library doesn't have very good error reporting. You might try panflute instead!

I'm writing a <figure> which is a block element. I thought I could choose what to use. Is there a way?
Maybe I should replace the Para...

jgm commented

I solved by replacing the containing Para. Thanks for the help and the library!