I am trying to render a table into HTML using Markdown syntax with the help of Python-markdown: https://python-markdown.github.io/
I tried the example provided here: https://python-markdown.github.io/extensions/tables/
from markdown import markdown
s = """
First Header | Second Header
------------- | -------------
Content Cell | Content Cell
Content Cell | Content Cell
"""
html = markdown(s)
print(html)
But what I get as the result is:
<p>First Header | Second Header
------------- | -------------
Content Cell | Content Cell
Content Cell | Content Cell</p>
What is wrong?
To add a table, use three or more hyphens ( --- ) to create each column's header, and use pipes ( | ) to separate each column. For compatibility, you should also add a pipe on either end of the row. Cell widths can vary, as shown below. The rendered output will look the same.
A table is an arrangement of data in rows and columns. To add a table in Markdown, use the vertical line | to separate each column, and use three or more dahses --- to create each column's header. A vertical line should also be added at either end of the row.
Python-Markdown is a Python library that allows you to convert Markdown text to HTML in various ways. You can extend its functionality using its different extensions that provide additional features. Note however, that the Python-Markdown has a few minor differences with the standard Markdown syntax.
Since tables is an extension, you need to pass its name to markdown.markdown
:
html = markdown(s, extensions=['tables'])
https://python-markdown.github.io/extensions/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With