Closed pbodnar closed 2 years ago
Important: The parsing phase is currently tightly connected with initiation and closing of a renderer. Therefore, you should never call Document(...) outside of a with ... as renderer block, unless you know what you are doing.
I think it would help to give an example of this "tight connection". Because just by reading that warning I have no idea.
I would like to parse a Markdown document into an AST, then do some processing on the AST and then render the resulting AST into HTML. Is that something that mistletoe can be used for or not?
@not-my-profile, thanks for your feedback -> see the new commit above - I hope it covers the topic of "tight connection" good enough now?
Regarding your second question, I think this should be possible. Something like:
with open('foo.md', 'r') as fin:
with HTMLRenderer() as renderer:
doc = Document(fin)
# ... do some stuff with the doc ...
rendered = renderer.render(doc)
Can you try out and let me know if it works for you?
OK, so I've pushed the doc commit to master. Feel free to open new issue / PR for improvements. :)
Thanks for replying / clarifying!
I guess one of the reasons I find the API confusing is that Document(..)
doesn't look like it's parsing. I wouldn't expect Document.__init__
to perform parsing.
OK, so here we go (8447a42). @not-my-profile, thanks for your feedback! :)
Note: I have focused just on the documentation here in the end.