my ($stream, $type) = @_;
my @events;
until ($stream->$_is_type(close => $type)) {
- push @events, $stream->next;
+ my $next = $stream->next;
+ if ($next->{type} eq 'OPEN' and $next->{name} eq 'br') {
+ push @events, { type => 'TEXT', raw => "\n" };
+ }
+ else {
+ push @events, $next;
+ }
}
return HTML::Zoom->from_events(\@events)->to_html;
};
return sprintf '== %s ==', $report->{title};
}
+my $_prepare_column_content = sub {
+ my ($content) = @_;
+ return ''
+ unless defined $content;
+ my @lines = split m{\n}, $content;
+ if (@lines == 1) {
+ return $content;
+ }
+ else {
+ my ($first, @rest) = @lines;
+ return HTML::Zoom->from_events([
+ { type => 'TEXT', raw => $first },
+ map {
+ my $string = $_;
+ ( @{ HTML::Zoom->from_html('<br/>')->to_events },
+ { type => 'TEXT', raw => $string });
+ } @rest,
+ ]);
+ }
+};
+
sub _apply_table_body {
my ($self, $markup, $report) = @_;
my $index = 0;
$_->apply_if($col !~ m{^__}, sub {
$_->add_to_attribute('td', class => "si-column-$col");
})
- ->replace_content('td', defined($value) ? $value : '')
+ ->replace_content('td', $value->$_prepare_column_content)
->apply_if($col_idx != $#cols, sub {
$_->add_after('td', "\n ");
});
<td class="si-column-baz">784</td>
<td></td>
<td></td>
+ </tr><tr class="data-row">
+ <td class="si-column-bar">989</td>
+ <td class="si-column-baz">foo<br/>bar</td>
+ <td></td>
+ <td></td>
</tr>
</table>
<!-- SI:TABLE end foo:c -->
rows => [
{ bar => 232, baz => 884 },
{ bar => 332, baz => 784 },
+ { bar => 989, baz => "foo\nbar" },
],
},
]), 'publish ok';
<td>172</td>
<td>173</td>
</tr>
+ <tr>
+ <td class="si-column-bar">foo<br/>bar</td>
+ <td class="si-column-baz">bar<br/>baz</td>
+ <td>199</td>
+ </tr>
</table>
<!-- SI:TABLE end foo -->
is_deeply $report->{rows}[1], {
bar => 232, baz => 422, __usercol_0 => 172, __usercol_orph_0 => 173,
}, 'second row';
+ is_deeply $report->{rows}[2], {
+ bar => "foo\nbar", baz => "bar\nbaz", __usercol_0 => 199,
+ }, 'third row';
};
is shift(@$stream), '', 'empty line';