wolfrevo
wolfrevo

Reputation: 7303

How to write a pandoc reader with Python

I've been searching for a way to write a pandoc reader (not a filter) with Python. But could not find any.

I mean a Reader as documented in Text.Pandoc.Readers

There are examples for Lua and of course for Haskell.

Is it possible to write a reader in python? Are there any working examples?

Upvotes: 2

Views: 398

Answers (1)

tarleb
tarleb

Reputation: 22659

A "reader" usually refers to any program that parses a file into pandoc's internal document representation. Both compiled-in readers written in Haskell as well as custom Lua readers create the document elements directly; this is not possible with any other method.

However, it would be possible to do all parsing and conversions in a separate program, and to pass the document representation as JSON:

my-reader file.txt | pandoc --from=json ...

Here, my-reader must emit the pandoc JSON format. Probably the most pythonic llibrary for that purpose would be panflute. The library is intended for use in a filter, but could as well be used to create a document and its components.

Upvotes: 6

Related Questions