Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 996
Fomalhaut Avatar asked Dec 09 '18 16:12

Fomalhaut


People also ask

How do you use tables in Markdown?

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.

How do you show a table in Markdown?

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.

Does Python support Markdown?

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.


1 Answers

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/

like image 146
Transfusion Avatar answered Nov 08 '22 18:11

Transfusion