Skip to main content

Library to generate Markdown table

Project description

py-markdown-table-generator

Python library to generate Markdown table.

Usage

pip3 install markdown_table_generator

CLI

csv-to-md -s ";" -a c tests/table.csv

# |   OS    |      Creator      |  Company  |
# |:-------:|:-----------------:|:---------:|
# | Ubuntu  | Mark Shuttleworth | Canonical |
# | FreeBSD |                   |           |
# | Fedora  |                   |  Red Hat  |

csv-to-md -s ";" -a r tests/table.csv

# |      OS |           Creator |   Company |
# |--------:|------------------:|----------:|
# |  Ubuntu | Mark Shuttleworth | Canonical |
# | FreeBSD |                   |           |
# |  Fedora |                   |   Red Hat |

csv-to-md -s ";" -a r tests/table.csv | xclip -selection clipboard # Copy markdown table in clipboard

psql -h 127.0.0.1 -U postgres postgres -c "select * from test" --csv | csv-to-md # Generate markdown table from PostgreSQL query

Library

from markdown_table_generator import generate_markdown, table_from_string_list

# ====================================================
# Generate markdown table from list of list of strings
# ==================================================== 
rows = [
    ["OS", "Creator", "Company"],
    ["Ubuntu", "Mark Shuttleworth", "Canonical"],
    ["FreeBSD", None, None],
    ["Fedora", None, "Red Hat"],
]
table = table_from_string_list(rows, Alignment.CENTER)
markdown = generate_markdown(table)
print(markdown)

# |   OS    |      Creator      |  Company  |
# |:-------:|:-----------------:|:---------:|
# | Ubuntu  | Mark Shuttleworth | Canonical |
# | FreeBSD |                   |           |
# | Fedora  |                   |  Red Hat  |


# ====================================================
# Generate markdown table from CSV
# ==================================================== 
csv = """
OS;Creator;Company
Ubuntu;Mark Shuttleworth;Canonical
FreeBSD;;
Fedora;;Red Hat
"""
table = table_from_csv(csv.splitlines(), ";", Alignment.RIGHT)
markdown = generate_markdown(table)
print(markdown)

# |      OS |           Creator |   Company |
# |--------:|------------------:|----------:|
# |  Ubuntu | Mark Shuttleworth | Canonical |
# | FreeBSD |                   |           |
# |  Fedora |                   |   Red Hat |

Build

python3 -m venv venv
. ./venv/bin/activate
pip install -r requirements.txt
python3 -m build

Test

python3 -m venv venv
. ./venv/bin/activate
pip install -r requirements.txt
pytest

Contribute

ln -s "$(pwd)/sh/pre-commit.sh" .git/hooks/pre-commit

... and let's code!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

markdown_table_generator-1.1.0.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distribution

markdown_table_generator-1.1.0-py3-none-any.whl (5.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page