You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importmistletoefrommistletoeimportDocumentmarkdown_text="""## Heading ASome text under heading 1.## Heading B *italic*Some text under heading 2.## Heading C **bold**Some text under heading 3."""# Parse the Markdown textdoc=Document(markdown_text)
fortokenindoc.children:
ifisinstance(token, mistletoe.block_token.Heading):
# heading_content = " ".join(str(child.content) for child in token.children if hasattr(child, 'content'))heading_content=token.contentprint(f'Level: {token.level}, Content: {heading_content}')
will output
Level: 2, Content: Heading C **bold**
Level: 2, Content: Heading C **bold**
Level: 2, Content: Heading C **bold**
The text was updated successfully, but these errors were encountered:
Hi @clehene, thanks for the report. For elements like BlockCode or HtmlBlock, the content property/attribute makes sense (see #163). For others, like Heading, not so much.
As you are not the first to ask this question (see #99), I think the simplest thing to do now is to rename the reported Heading's contentclass attribute to _content, so that it is clear that it is not a part of the public API. That would be in-line e.g. with _open_info in the CodeFence token class.
I can also imagine we could introduce a getter property called text or similar that would recursively concat text from the child tokens, but that would be for another feature request...
The
content
forblock_token.Heading
gets harwill output
The text was updated successfully, but these errors were encountered: