lepture / mistune

A fast yet powerful Python Markdown parser with renderers and plugins.
http://mistune.lepture.com/
BSD 3-Clause "New" or "Revised" License
2.59k stars 251 forks source link

Changes migrating from v2 to v3 #354

Closed lucafaggianelli closed 1 year ago

lucafaggianelli commented 1 year ago

I updated from 2.x to 3.x and I noticed there are other changes with respect to the upgrade guide, no big deal but worth to tell you :)

- abbr(self, key, definition)
+ abbr(self, text: str, title: str)

- task_list_item(self, text: str, level: int, checked: bool)
+ task_list_item(self, text: str, checked: bool)

I'm building a custom renderer, and the output is not textual, but rather a tree of components... FWIW is a Plotly Dash renderer, so I needed to migrate other parts of my code as my renderer doesn't play well with "".join functions and similar.

So I needed to override the render_tokens method, in the other version I changed the finalize method though:

def render_tokens(self, tokens, state):
-       return ''.join(self.iter_tokens(tokens, state))
+       return list(self.iter_tokens(tokens, state))

And in the image(self, alt: str, url: str, title: Optional[str] = None) method I noticed that alt it's actually a List[str] .. easy to fix but I wanted to know what to expect for the alt argument.

Moreover if you have other advices for implementing a non-textual renderer I'd be happy :)

Thanks for the great work with Mistune!!

lepture commented 1 year ago

The way you subclass render and change render_tokens is correct.

lepture commented 1 year ago

I've upgraded the documentation, close this issue.