I'm trying to (programmatically) convert Markdown tables to HTML using markdown2, but it's not working. I take it should because markdown2 is supposed to be a
complete implementation of Markdown in Python
A minimal non-working example (meant to be run in a Jupyter notebook to properly display the output):
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))
Any clue?
Tables aren't part of 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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With