【问题标题】:Converting Markdown tables to HTML using markdown2使用 markdown2 将 Markdown 表转换为 HTML
【发布时间】:2021-05-23 10:08:06
【问题描述】:

我正在尝试(以编程方式)使用markdown2 将 Markdown 表转换为 HTML,但它不起作用。我认为应该是因为 markdown2 应该是一个

Markdown 在 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))

有什么线索吗?

【问题讨论】:

    标签: python html markdown


    【解决方案1】:

    表格不是the original Markdown specification 的一部分。试试enablingrelevant 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))
    

    【讨论】:

      猜你喜欢
      • 2018-04-13
      • 2010-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-07
      • 2017-05-11
      • 2011-10-28
      • 1970-01-01
      相关资源
      最近更新 更多