kellyjonbrazil/jtbl

Add option to use Markdown table syntax

Closed this issue · 7 comments

This would make the table even more readable in Markdown documents or Github issues because it would be rendered as a proper HTML table.

Hi - thank you for opening this feature request. I think this could be an interesting use case for jtbl. Let me do some investigation to see if this is an easy add.

Looks like this should be pretty quick and easy to add. Is this the format that you are looking for?

| item   | qty   |
|--------|-------|
| spam   | 42    |
| eggs   | 451   |
| bacon  | 0     |

Yeah, that's it!

I have this working in the master branch:

$ echo '[
            {
                "column1": "data",
                "column2": 123,
                "column3": true,
                "column4": null
            },
            {
                "column1": "This is a long string that should not be truncated by the markdown table format. Lines should not be wrapped for markdown.",
                "column2": 123,
                "column3": true,
                "column4": null
            }
        ]' | jtbl -m
| column1                                                                                                                    |   column2 | column3   | column4   |
|----------------------------------------------------------------------------------------------------------------------------|-----------|-----------|-----------|
| data                                                                                                                       |       123 | True      |           |
| This is a long string that should not be truncated by the markdown table format. Lines should not be wrapped for markdown. |       123 | True      |           |
$ 

I think that works, but just wanted to make sure I'm not missing anything you need like heading or trailing newlines before pushing to PyPi.

Thanks!

Looks good to me!

Heading or trailing newlines I think aren't necessary in the output.

If I would copy the output to later paste it into a Markdown document, then I would just add the appropriate blank lines by myself.

The big time saver that this feature provides is writing the correct table syntax with the column separators aligned so it still looks good in the terminal or in the source editor.

Perfect - I have pushed v1.3.0 to PyPi.

Cheers!

It works! Another great addition to the toolkit. Thanks for the quick resolution!