DEV Community

Joan Ramio
Joan Ramio

Posted on

piotrmurach/tty-table to markdown

Hello,

I will suggest to @piotrmurach to add a method to tty-table to generate markdown. It can ba called .to_md

It is similar to the actual

table.render(:ascii, alignments: [:center, :right])
# =>
#  +-------+-------+
#  |header1|header2|
#  +-------+-------+
#  |  a1   |     a2|
#  |  b1   |     b2|
#  +-------+-------+
Enter fullscreen mode Exit fullscreen mode

.to_md should remove first and last lines and adapt the line under the headers.

table.to_md(alignments: [:center, :right])
# =>
#  |header1|header2|
#  |:-----:|------:| 
#  |  a1   |     a2|
#  |  b1   |     b2|
Enter fullscreen mode Exit fullscreen mode

It is important to align text also in markdown, because it is more readable than:

#  |header1|header2|
#  |:-----:|------:| 
#  |a1|a2|
#  |b1|b2|
Enter fullscreen mode Exit fullscreen mode

Thank you,
Joan Ramió.

Top comments (0)