handle newline and html break conversions in mediawiki publishing
[scpubgit/System-Introspector-Report.git] / lib / System / Introspector / Report / Publish / MediaWiki / Producer.pm
index f6c252c..db40895 100644 (file)
@@ -44,6 +44,27 @@ sub _render_title {
   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;
@@ -63,7 +84,7 @@ sub _apply_table_body {
               $_->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    ");
                 });