Tuesday, 21 December 2021

Getting h1 from markdown via python's pandoc library

I'm writing a python batch script to process many markdown files to get h1-like text to generate 'title' metadata variable (I forgot to add 'title' into frontmatter). I'm not using this as pandoc filter.

Thus I was thinking to process those files via pandoc-python, but I'm not familiar with that and I cannot figure out how to get only h1.

content = pandoc.read(post.content)

'content' is pandoc native format. And I see something like this

(Pdb) content                                                                                                                                                                                                                                 
Pandoc(Meta({}), [Header(1, ('foobar', [], []), [Str('foobar:')]), Para(...

I would like to get h1 as simple text.



from Getting h1 from markdown via python's pandoc library

No comments:

Post a Comment