Are Markdown Tables supported?
johnthagen opened this issue ยท 6 comments
Are Extended syntax tables supported? https://www.markdownguide.org/extended-syntax/#tables
Code
if __name__ == "__main__":
table = """
| Syntax | Description |
| ----------- | ----------- |
| Header | Title |
| Paragraph | Text |
"""
output_path = Path("out.pdf")
md2pdf(
output_path,
md_content=f"This is a **test**\n\n{table}",
css_file_path=None,
base_url=None
)
Output
Expecting to see a table here:
Version
Python 3.9.1
$ pip list
Package Version
------------ -------
cairocffi 1.2.0
CairoSVG 2.5.1
cffi 1.14.4
cssselect2 0.4.1
defusedxml 0.6.0
docopt 0.6.2
html5lib 1.1
markdown2 2.3.10
md2pdf 0.4
Pillow 8.1.0
pip 20.3.3
prettytable 2.0.0
pycparser 2.20
Pyphen 0.10.0
setuptools 49.6.0
six 1.15.0
tinycss2 1.1.0
wcwidth 0.2.5
WeasyPrint 52.2
webencodings 0.5.1
wheel 0.35.1
Looking closer, it looks like the best thing to do would be to expose the extras
attribute out to the user. markdown2
supports this extra
:
* tables: Tables using the same format as GFM
<https://help.github.com/articles/github-flavored-markdown#tables> and
PHP-Markdown Extra <https://michelf.ca/projects/php-markdown/extra/#table>.
Exposing this to the user would allow them to enable whichever extras they need.
Like so:
def md2pdf(pdf_file_path, md_content=None, md_file_path=None,
css_file_path=None, base_url=None, extras=None):
"""
Converts input markdown to styled HTML and renders it to a PDF file.
Args:
pdf_file_path: output PDF file path.
md_content: input markdown raw string content.
md_file_path: input markdown file path.
css_file_path: input styles path (CSS).
base_url: absolute base path for markdown linked content (as images).
Returns:
None
Raises:
ValidationError: if md_content and md_file_path are empty.
"""
if extras is None:
extras = ["cuddled-lists"]
...
I can confirm that setting extras=["cuddled-lists", "tables"]
fixes this issue.
Related to #10
Great! Can you propose a PR?
@jmaupetit Looking at the master
branch more closely, this actually is supported
Line 31 in b73deee
But there has not been a released on PyPI in 4 years:
https://pypi.org/project/md2pdf/
Could a new release from master
be pushed to PyPI? That would close this issue.
This is now fixed! https://pypi.org/project/md2pdf/0.5/