frostming / marko

A markdown parser with high extensibility.

Home Page:https://marko-py.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get the raw text after converting?

sulunemre opened this issue · comments

Hey, I am trying to parse a Markdown string as a raw text. For example: ## A title should be A title.
I've tried:

from marko.ext.gfm import gfm
element = gfm.parse("## A title").children[0]
gfm.render(element)

But, it returns '<h2>A title</h2>\n' and I am not interested in HTML tags but only the text.

My first thought was using Beautiful Soup for parsing the output HTML but it is probably an overkill. Is there a better way?

Thanks!

gfm.parse("## A title").children[0] is a Heading element.

Get the raw text by gfm.parse("## A title").children[0].children[0].children