Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are Markdown Tables supported? #36

Closed
johnthagen opened this issue Jan 20, 2021 · 6 comments
Closed

Are Markdown Tables supported? #36

johnthagen opened this issue Jan 20, 2021 · 6 comments

Comments

@johnthagen
Copy link

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:

Screen Shot 2021-01-20 at 12 56 29 PM

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
@johnthagen
Copy link
Author

johnthagen commented Jan 20, 2021

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"]
    ...

@johnthagen
Copy link
Author

I can confirm that setting extras=["cuddled-lists", "tables"] fixes this issue.

@johnthagen
Copy link
Author

Related to #10

@jmaupetit
Copy link
Owner

Great! Can you propose a PR?

@johnthagen
Copy link
Author

@jmaupetit Looking at the master branch more closely, this actually is supported

extras = ['cuddled-lists', 'tables']

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.

@jmaupetit
Copy link
Owner

This is now fixed! https://pypi.org/project/md2pdf/0.5/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants