I want to use Pandoc to merge multiple Markdown files. While doing so, I want each file's frontmatter or metadata to generate custom Markdown at the top of the document before merging. I found this SO post answer which appears to do what I want, but I don't sufficiently understand Pandoc filters or the Haskell for the proposed filter. My attempt to translate the Haskell into Python is this:
from pandocfilters import Header
from pandocfilters import toJSONFilter
def insertMeta(key, value, format, meta):
if ???:
return Header(meta['title'], [], [])
if __name__ == "__main__":
toJSONFilter(insertMeta)
I understand that toJSONFilter
will walk the AST of the document, but I have no idea how to write a condition to only insert header information at the top of the document. What am I conditioning on? I tried to dir(pandocfilters)
but do not see an object that looks like metadata or file headers. Thanks for any help.