-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
114 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ Text formats | |
ltsv | ||
html | ||
json | ||
markdown | ||
markdown/markdown | ||
mediawiki | ||
rst/index | ||
sourcecode/index | ||
|
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
docs/pages/examples/table_format/text/markdown/markdown.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.. _example-markdown-table-writer: | ||
|
||
Markdown | ||
---------------------------- | ||
|MarkdownTableWriter| class can write a table to the |stream| with Markdown table format from a data matrix. | ||
|
||
.. include:: md_example.txt | ||
|
||
Markdown with margins | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
.. include:: md_example_with_margin.txt | ||
|
||
GitHub flavored Markdown (GFM) | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
.. include:: md_example_with_flavor.txt | ||
|
||
Apply styles to GFM table with programmatically | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
.. include:: md_example_with_style_style.txt |
File renamed without changes.
27 changes: 27 additions & 0 deletions
27
docs/pages/examples/table_format/text/markdown/md_example_with_flavor.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
If you set ``flavor`` keyword argument of ``MarkdownTableWriter`` class to ``"github"`` or ``"gfm"``, the writer will output markdown tables with GitHub flavor. | ||
GFM can apply some additional styles to tables such as ``fg_color`` (text color). | ||
|
||
:Sample Code: | ||
.. code-block:: python | ||
:caption: Write a Markdown table with GitHub flavor | ||
|
||
from pytablewriter import MarkdownTableWriter | ||
from pytablewriter.style import Style | ||
|
||
writer = MarkdownTableWriter( | ||
column_styles=[ | ||
Style(fg_color="red"), | ||
Style(fg_color="green", decoration_line="underline"), | ||
], | ||
headers=["A", "B"], | ||
value_matrix=[ | ||
["abc", 1], | ||
["efg", 2], | ||
], | ||
margin=1, | ||
flavor="github", | ||
enable_ansi_escape=False, | ||
) | ||
writer.write_table() | ||
|
||
Rendered results can be found at `here <https://github.com/thombashi/pytablewriter/blob/master/docs/pages/examples/output/markdown/gfm.md>`__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
docs/pages/examples/table_format/text/markdown/md_example_with_style_filter.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
You can apply styles to specific cells by using style filters. | ||
Style filters will be written as functions. | ||
Example of a style filter function are as follows: | ||
|
||
:Sample Code: | ||
.. code-block:: python | ||
:caption: Write a Markdown table with GitHub flavor | ||
|
||
from typing import Any, Optional | ||
|
||
from pytablewriter import MarkdownTableWriter | ||
from pytablewriter.style import Cell, Style | ||
|
||
|
||
def style_filter(cell: Cell, **kwargs: Any) -> Optional[Style]: | ||
if cell.is_header_row(): | ||
return None | ||
|
||
if cell.col == 0: | ||
return Style(font_weight="bold") | ||
|
||
value = int(cell.value) | ||
|
||
if value > 80: | ||
return Style(fg_color="red", font_weight="bold", decoration_line="underline") | ||
elif value > 50: | ||
return Style(fg_color="yellow", font_weight="bold") | ||
elif value > 20: | ||
return Style(fg_color="green") | ||
|
||
return Style(fg_color="lightblue") | ||
|
||
|
||
writer = MarkdownTableWriter( | ||
table_name="style filter example", | ||
headers=["Key", "Value 1", "Value 2"], | ||
value_matrix=[ | ||
["A", 95, 40], | ||
["B", 55, 5], | ||
["C", 30, 85], | ||
["D", 0, 69], | ||
], | ||
flavor="github", | ||
enable_ansi_escape=False, | ||
) | ||
writer.add_style_filter(style_filter) | ||
writer.write_table() | ||
|
||
Rendered results can be found at `here <https://github.com/thombashi/pytablewriter/blob/master/docs/pages/examples/output/markdown/style_filter.md>`__ |