You can also use read and write files instead of Python strings. For example, if you have a `notebookify` function that takes a doc (pandoc AST) and returns a Jupyter notebook (as a Python JSON-like dictionnary), your wrapper script could be something like: # file: notebookify.py # here: imports, notebookify definition, etc. # ... def main(): filename = sys.argv[1] doc = pandoc.read(file=filename) notebook = notebookify(doc) ipynb = Path(filename).with_suffix(".ipynb") with open(ipynb, "w", encoding="utf-8") as output: json.dump(notebook, output, ensure_ascii=False, indent=2) if __name__ == "__main__": main() you would invoke it with $ python notebookify.py my_document.md and it would produce a my_document.ipynb Jupyter notebook. This example is developped with more details here: https://boisgera.github.io/pandoc/examples/#jupyter-notebooks Cheers, SB Le samedi 4 décembre 2021 à 15:58:31 UTC+1, denis...-NSENcxR/0n0@public.gmane.org a écrit : > Thanks Sébastian. > > So, if I understand correctly, you'll use that in in a script that reads > your markdowns file and outputs another. Correct? (I just mean, usually > your doc will be in your filesystem, not in a python variable.) > > Best > Denis > > ________________________________________ > Von: pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org im Auftrag > von Sébastien Boisgérault > Gesendet: Samstag, 4. Dezember 2021 15:43:42 > An: pandoc-discuss > Betreff: Re: Pandoc Document Model in Python > > (Ooops probably answered Denis only and not the group. Here we go again!) > > AFAICT filters are document AST to AST transformations. In this Python > library, docs (Pandoc instances) represent this AST, so a typical AST > (in-place) transform would be: > > import pandoc > from pandoc.types import * > > def uppercase(doc): > for elt in pandoc.iter(doc): > if isinstance(elt, Str): > elt[0] = elt[0].upper() # elt: Str(Text) > > If you need to make a markdown to markdown transformation instead, you > read the input markdown, transform it then write it back: > > >>> markdown = "Hello world!" > >>> doc = pandoc.read(markdown) > >>> uppercase(doc) > >>> markdown = pandoc.write(doc) > >>> print(markdown) > HELLO WORLD! > > There are more examples here: > > https://boisgera.github.io/pandoc/examples/ > > and a documentation of common patterns here: > > https://boisgera.github.io/pandoc/cookbook/ > > Cheers, > > Sébastien > > Le samedi 4 décembre 2021 à 15:06:10 UTC+1, denis...-NSENcxR/0n0@public.gmane.org a écrit : > Hi Sebastian > Looks interesting. But I don't undertake how you'd use that as an > alternative to a filter. Can you give an example? > Denis > > > > ________________________________________ > Von: pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org im Auftrag > von Sébastien Boisgérault > Gesendet: Samstag, 4. Dezember 2021 14:20:03 > An: pandoc-discuss > Betreff: Pandoc Document Model in Python > > Hi everyone, > > I have just released the 2.0 version of a pandoc python library which > exposes the Pandoc document model to Python : > > https://github.com/boisgera/pandoc#-overview > > The main goal is to enable all kinds of analysis, generation and > transformation of documents with Python (roughly speaking, an alternative > to pandoc filters); it is not to convert from one format to another (it can > do it, but so can the standard pandoc command-line tool). > > Feedback welcome ! > > Cheers, > > Sébastien > > > > -- > You received this message because you are subscribed to the Google Groups > "pandoc-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/pandoc-discuss/f224cd2c-7d68-40b4-a855-7d4d0d7aa442n%40googlegroups.com > < > https://groups.google.com/d/msgid/pandoc-discuss/f224cd2c-7d68-40b4-a855-7d4d0d7aa442n%40googlegroups.com?utm_medium=email&utm_source=footer > >. > > -- > You received this message because you are subscribed to the Google Groups > "pandoc-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/pandoc-discuss/de1fd005-0d0d-49a2-86cc-5a72c764835dn%40googlegroups.com > < > https://groups.google.com/d/msgid/pandoc-discuss/de1fd005-0d0d-49a2-86cc-5a72c764835dn%40googlegroups.com?utm_medium=email&utm_source=footer > >. > -- You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/0afdf96b-bc19-4117-a78b-bdbee13e076an%40googlegroups.com.