Markdown output breaks with table titles
What did you do?
Created a table with a title or caption set, e.g. via table.title = "Here be Table caption"
What did you expect to happen?
The markdown output should be parsable and rendering as a table in markdown viewers (e.g. Github)
What actually happened?
The markdown output is not rendered at all as a table
What versions are you using?
- PrettyTable: 3.11.0 Please include code that reproduces the issue.
from prettytable import PrettyTable, MARKDOWN
table = PrettyTable(field_names=["Namespace", "Count"])
table.title = "Here be Table caption"
table.add_row(["bla", "24"])
table.add_row(["blu", "1"])
table._set_default_style() # workaround for other markdown output bug
table.set_style(MARKDOWN)
print(table.get_formatted_string(out_format="text"))
the results looks like this
| :-------------------: |
| Here be Table caption |
| Namespace | Count |
| :------------|------: |
| bla | 24 |
| blu | 1 |
which is not parsable my markdown renderers, see e.g. Github preview one here:
| :-------------------: | | Here be Table caption |
| Namespace | Count |
|---|---|
| bla | 24 |
| blu | 1 |
It seems there is no officially supported syntax for markdown table captions yet, just some different approaches in different products, see https://forum.obsidian.md/t/captions-for-tables-in-markdown/17240/5
Hence, a solution would be to have the markdown formatter instead create a text header for that table, e.g.:
## Here be Table caption
| Namespace | Count |
| :------------|------: |
| bla | 24 |
| blu | 1 |
which would look like this rendered:
Here be Table caption
| Namespace | Count |
|---|---|
| bla | 24 |
| blu | 1 |
I'm not sure though what header depth to choose and if that would mess up with the document structure. It might be better to just show that title as bold text above the table?