shlomif / Text-Table

CPAN Distribution to render text / ASCII-art / Unicode tables
https://metacpan.org/release/Text-Table
ISC License
4 stars 6 forks source link

Trim feature request #9

Open Skeeve opened 5 years ago

Skeeve commented 5 years ago

I'm creating tables for markdown.

This is example code:

use Text::Table;

my $tb= Text::Table->new(
  \' ',
  'Col 1',
  \' | ',
  'Col 2',
  \' '
);

$tb->load(
  [qw[ A1 B1 ]],
  [qw[ A2 B2 ]],
  [qw[ A3 B3 ]],
  [qw[ A4 B4 ]],
);

print $tb->title, $tb->rule('-', '|'), $tb->body;

For illustration I replaced every space with a dot:

.Col.1.|.Col.2.
-------|-------
.A1....|.B1....
.A2....|.B2....
.A3....|.B3....
.A4....|.B4....

So there are lots of trailing spaces. They even appear if I do not put the spaces as separators into the table creation.

While markdown itself won't complain , markdownlint will. Currently I'm simply map-ping like this:

print map { s/ +$//; $_ } $tb->title, $tb->rule('-', '|'), $tb->body;

but to my understanding this takes away a lot of the beauty of the module. I think it would be great would it be possible to tell the table that trailing spaces in each line should be trimmed.