使用 markdown2 将 Markdown 表格转换为 HTML
Converting Markdown tables to HTML using markdown2
我正在尝试(以编程方式)使用 markdown2 将 Markdown 表格转换为 HTML,但它不起作用。我认为应该是因为 markdown2 应该是
complete implementation of Markdown in Python
一个最小的非工作示例(意味着在 Jupyter 笔记本中 运行 以正确显示输出):
import markdown2
import IPython.display
markdown_text = '''
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | 1600 |
| col 2 is | centered | 12 |
| zebra stripes | are neat | 1 |
'''
display(IPython.display.Markdown(markdown_text))
converter = markdown2.Markdown()
html = converter.convert(markdown_text)
display(IPython.display.HTML(html))
有线索吗?
表格不是 the original Markdown specification. Try enabling the relevant extra 的一部分:
import markdown2
import IPython.display
markdown_text = '''
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | 1600 |
| col 2 is | centered | 12 |
| zebra stripes | are neat | 1 |
'''
display(IPython.display.Markdown(markdown_text))
converter = markdown2.Markdown(extras=["tables"]) # <-- here
html = converter.convert(markdown_text)
display(IPython.display.HTML(html))
我正在尝试(以编程方式)使用 markdown2 将 Markdown 表格转换为 HTML,但它不起作用。我认为应该是因为 markdown2 应该是
complete implementation of Markdown in Python
一个最小的非工作示例(意味着在 Jupyter 笔记本中 运行 以正确显示输出):
import markdown2
import IPython.display
markdown_text = '''
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | 1600 |
| col 2 is | centered | 12 |
| zebra stripes | are neat | 1 |
'''
display(IPython.display.Markdown(markdown_text))
converter = markdown2.Markdown()
html = converter.convert(markdown_text)
display(IPython.display.HTML(html))
有线索吗?
表格不是 the original Markdown specification. Try enabling the relevant extra 的一部分:
import markdown2
import IPython.display
markdown_text = '''
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | 1600 |
| col 2 is | centered | 12 |
| zebra stripes | are neat | 1 |
'''
display(IPython.display.Markdown(markdown_text))
converter = markdown2.Markdown(extras=["tables"]) # <-- here
html = converter.convert(markdown_text)
display(IPython.display.HTML(html))