frostming / marko

A markdown parser with high extensibility.
https://marko-py.readthedocs.io/en/latest/
MIT License
345 stars 38 forks source link

v2 - parse_inline now unusable independently, errors in docs #162

Closed peku33 closed 1 year ago

peku33 commented 1 year ago

Hi, I tried updating my project from marko v1 to marko v2. I use it to parse short messages and extract just a few accepted elements (bold, italic, underline) from ast.

Previously I was able to use Parser.parse_inline("markdown text") to obtain children. Now this method changed it footprint to def parse_inline(self, element: block.BlockElement, source: Source) and its usage is not documented.

The method parse(self, text: str) has just the text parameter, but in docs its still :param source_or_text: the text or source object.

Is there any way to achieve previous behaviour of extracing simple elements from short string?

frostming commented 1 year ago

Just use the parse(text) method to get the parsed tree:

text = "I am a **bolded text**"
doc = parse(text)
print(doc.children[0].children)