我试图在Python-markdown的帮助下使用Markdown语法将表格呈现为HTML:https://python-markdown.github.io/
我试过这里提供的例子: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)
但我得到的结果是:
<p>First Header | Second Header
------------- | -------------
Content Cell | Content Cell
Content Cell | Content Cell</p>
怎么了?
1 回答
由于表是扩展名,因此您需要将其名称传递给
markdown.markdown
:html = markdown(s, extensions=['tables'])
https://python-markdown.github.io/extensions/