简体   繁体   中英

Why are tables not working in Python-markdown?

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?

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM