frostming / marko

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

parse tables, render to markdown #174

Closed nschloe closed 11 months ago

nschloe commented 12 months ago

I'd like to parse a table and render it back to markdown. The MarkdownRenderer() can't do it, and gfm.render() renders to HTML.

from marko.md_renderer import MarkdownRenderer
from marko.ext.gfm import gfm

text = """
| a  | 
| :--: |
| b |
"""

doc = gfm.parse(text)

print(MarkdownRenderer().render(doc))
print()
print(gfm.render(doc))
ab

<table>
<thead>
<tr>
<th align="center">a</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">b</td>
</tr>
</tbody></table>
frostming commented 11 months ago

Use the regular Markdown parser:

md = marko.Markdown(renderer=MarkdownRenderer)
print(md.convert(text), end="")