Inline filters (original) (raw)

Currently passing filters works by passing a list, this feels a bit clunky / sub optimal integrated...
Considering there is a package as pandocfilters, it should be possible to so something like this:

import pypandoc
from pathlib import Path
from pandocfilters import toJSONFilter, Str

def caps(key, value, format, meta):
  if key == 'Str':
    return Str(value.upper())

input = Path('somefile.md')
output = input.with_suffix('.docx')
pypandoc.convert_file(input, 'docx', outputfile=output, filters=[toJSONFilter(caps)])

(Pseudo code to illustrate how it might work. Copy and pasted from provided examples)

Or in short: It should be possible to pass a function or maybe a object as filter, while passing a string would work as it currently is