Commits

Toby Inkster committed 824f156

center align

Comments (0)

Files changed (2)

lib/HTML/HTML5/Table/Row.pm

 
 use List::Util qw/max/;
 use Moose;
-use POSIX qw/ceil/;
+use POSIX qw/ceil floor/;
 
 has node => (
 	is        => 'rw',
 		}
 		$n -= 3;
 		
+		my $align = $cell->align;
 		my $format = sub
 		{
 			my ($str) = @_;
 			return (' ' x $n) unless defined $str;
-			sprintf($cell->align =~ /right/i ? "% ${n}s" : "% -${n}s", $str);
+			if ($align =~ /middle|center|centre/i)
+			{
+				my $before = floor(($n - length $str) / 2);
+				my $after  = $n - ($before + length $str);
+				return (' ' x $before).$str.(' ' x $after);
+			}
+			sprintf($align =~ /right/i ? "% ${n}s" : "% -${n}s", $str);
 		};
 
 		my @celltext  = split /\r?\n/, $cell->celltext;

lib/HTML/HTML5/ToText/Trait/RenderTables.pm

 The table rendering engine understands the C<< <caption> >>, C<< <thead> >>,
 C<< <tbody> >>, C<< <tfoot> >>, C<< <tr> >>, C<< <th> >>, C<< <td> >>,
 C<< <colgroup> >> and C<< <col> >> elements; and the C<< span >>,
-C<< colspan >> and C<< rowspan >> attributes. It doesn't currently do
-C<< align >> / C<< valign >>, but one day...
+C<< align >> (values "left", "right" and "center"), C<< colspan >> and
+C<< rowspan >> attributes. It doesn't currently do C<< valign >>, but maybe
+one day...
 
 =head1 BUGS