Skip to main content

A package used to generate basic markdown tables from a list of dicts

Project description

markdownTable

A class used to generate padded tables in a markdown code block

Args:
data (list): List of dicts with uniform key : value pairs. The keys will be used for generating the header and values -- the rows.
row_sep (str): A flag used to indicate how and where to insert row separators. Possible values are 'always'/'topbottom'/None where:
               'always 'inserts separators between each individual data row
               'topbottom' inserts separators above the header and below the last row
               'None' omits the insertion of a row separator
padding_width (int): Value used to indicate how much extra padding to insert to table cells.
padding_weight (str): A flag used to indicate the strategy of applying the padding indicated through padding_width.
               Possible values are 'left'/'right'/'centerleft'/'centerright' where:
               'left' aligns items in cells to the end of the cell
               'right' aligns items in cells to the beginning of the cell
               'centerleft' centers items with the extra padding allocated to the beginning of the cell
               'centerright' centers items with the extra padding allocated to the end of the cell
padding_char (str): Custom character to fill extra and normal padding with. Default is a blank space.
newline_char (str): Custom character to be used for indicating a newline

Methods
-------
getHeader()
    gets unescaped table header
getBody()
    gets unescaped table content
getMarkdown()
    gets complete escaped markdown table

Installation

You can install it via pip with the following command pip3 install py-markdown-table and consequently import it via from markdownTable import markdownTable

Examples

markdownTable(data, row_sep = 'always').getMarkdown()

+----------------------------------------+
|    title   |    time   |   date  |seats|
+------------+-----------+---------+-----+
|Vrij Zwemmen|21:30-23:00|Wed 09.12|24/24|
+------------+-----------+---------+-----+
|Vrij Zwemmen|12:00-13:00|Thu 10.12|18/18|
+------------+-----------+---------+-----+
|Vrij zwemmen| 7:30-8:30 |Fri 11.12|18/18|
+------------+-----------+---------+-----+
|Vrij Zwemmen|13:15-14:15|Sat 12.12|18/18|
+------------+-----------+---------+-----+

markdownTable(data, row_sep = 'topbottom').getMarkdown()

+----------------------------------------+
|    title   |    time   |   date  |seats|
|Vrij Zwemmen|21:30-23:00|Wed 09.12|24/24|
|Vrij Zwemmen|12:00-13:00|Thu 10.12|18/18|
|Vrij zwemmen| 7:30-8:30 |Fri 11.12|18/18|
|Vrij Zwemmen|13:15-14:15|Sat 12.12|18/18|
+------------+-----------+---------+-----+

markdownTable(data, row_sep = 'topbottom', padding_width = 5, padding_weight='left').getMarkdown()

+------------------------------------------------------------+
|            title|            time|          date|     seats|
|     Vrij Zwemmen|     21:30-23:00|     Wed 09.12|     24/24|
|     Vrij Zwemmen|     12:00-13:00|     Thu 10.12|     18/18|
|     Vrij zwemmen|       7:30-8:30|     Fri 11.12|     18/18|
|     Vrij Zwemmen|     13:15-14:15|     Sat 12.12|     18/18|
+-----------------+----------------+--------------+----------+

markdownTable(data, row_sep = 'topbottom', padding_width = 5, padding_weight='centerright').getMarkdown()

+------------------------------------------------------------+
|      title      |      time      |     date     |  seats   |
|  Vrij Zwemmen   |  21:30-23:00   |  Wed 09.12   |  24/24   |
|  Vrij Zwemmen   |  12:00-13:00   |  Thu 10.12   |  18/18   |
|  Vrij zwemmen   |   7:30-8:30    |  Fri 11.12   |  18/18   |
|  Vrij Zwemmen   |  13:15-14:15   |  Sat 12.12   |  18/18   |
+-----------------+----------------+--------------+----------+

markdownTable(data, row_sep = 'always', padding_width = 5, padding_weight='centerright', padding_char = '.').getMarkdown()

+------------------------------------------------------------+
|......title......|......time......|.....date.....|..seats...|
+-----------------+----------------+--------------+----------+
|..Vrij Zwemmen...|..21:30-23:00...|..Wed 09.12...|..24/24...|
+-----------------+----------------+--------------+----------+
|..Vrij Zwemmen...|..12:00-13:00...|..Thu 10.12...|..18/18...|
+-----------------+----------------+--------------+----------+
|..Vrij zwemmen...|...7:30-8:30....|..Fri 11.12...|..18/18...|
+-----------------+----------------+--------------+----------+
|..Vrij Zwemmen...|..13:15-14:15...|..Sat 12.12...|..18/18...|
+-----------------+----------------+--------------+----------+

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

py-markdown-table-0.1.0.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

py_markdown_table-0.1.0-py3-none-any.whl (4.8 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