diff --git a/Markdown.pl b/Markdown.pl index 9042c6d..dfbc5b9 100755 --- a/Markdown.pl +++ b/Markdown.pl @@ -2005,8 +2005,8 @@ sub _DoTables { unless $nohdr; my $cnt = 0; my @classes = ("class=\"$opt{style_prefix}row-even\"", "class=\"$opt{style_prefix}row-odd\""); - $tab .= " " . _MakeTableRow("td", \@align, _SplitTableRow($_)) . "\n" - foreach split(/\n/, $rows); + $tab .= " " . _MakeTableRow("td", \@align, @$_) . "\n" + foreach (_SplitMergeRows($rows)); $tab .= "\n\n"; } else { $w; @@ -2017,6 +2017,49 @@ sub _DoTables { } +sub _SplitMergeRows { + my @rows = (); + my ($mergeprev, $mergenext) = (0,0); + foreach (split(/\n/, $_[0])) { + $mergeprev = $mergenext; + $mergenext = 0; + my @cols = _SplitTableRow($_); + if (_endswithbareslash($cols[$#cols])) { + my $last = $cols[$#cols]; + substr($last, -1, 1) = ""; + $last =~ s/[ ]+$//; + $cols[$#cols] = $last; + $mergenext = 1; + } + if ($mergeprev) { + for (my $i = 0; $i <= $#cols; ++$i) { + my $cell = $rows[$#rows]->[$i]; + defined($cell) or $cell = ""; + $rows[$#rows]->[$i] = _MergeCells($cell, $cols[$i]); + } + } else { + push(@rows, [@cols]); + } + } + return @rows; +} + + +sub _endswithbareslash { + return 0 unless substr($_[0], -1, 1) eq "\\"; + my @parts = split(/\\\\/, $_[0], -1); + return substr($parts[$#parts], -1, 1) eq "\\"; +} + + +sub _MergeCells { + my ($c1, $c2) = @_; + return $c1 if $c2 eq ""; + return $c2 if $c1 eq ""; + return $c1 . " " . $c2; +} + + sub _SplitTableRow { my $row = shift; $row =~ s/^$LEAD//; diff --git a/syntax.md b/syntax.md index 8c892ca..8756e70 100644 --- a/syntax.md +++ b/syntax.md @@ -619,6 +619,61 @@ Inline markup is recognized just fine within each column: |:- |~~Strikeout~~ `code` _etc._ +Row text can be split over multiple rows by ending a row with a +backslash (`\`) as the last character on the line. + +For example, this: + + Item|Price|Description + -|-:|- + Nut|$1.29|Delicious + Bean|$0.37|Fiber + Squash|$1.83|Healthy + +Generates output something like this: + + + + + + +
ItemPriceDescription
Nut$1.29Delicious
Bean$0.37Fiber
Squash$1.83Healthy
+ +But adding a trailing `\` to the end of first table body row like +so: + + Item|Price|Description + -|-:|- + Nut|$1.29|Delicious \ + Bean|$0.37|Fiber + Squash|$1.83|Healthy + +Generates this output instead: + + + + + +
ItemPriceDescription
Nut Bean$1.29 $0.37Delicious Fiber
Squash$1.83Healthy
+ +The corresponding columns of the first two rows are merged. It's +possible to merge multiple rows. Adding a trailing `\` to the +second row too would result in a single row output table. + +The `\` must be the very last character on the line to be recognized +as a "row-joiner". If the optional trailing `|` has been included +the "row-joiner" must appear after that like so: + + Item|Price|Description| + -|-:|-| + Nut|$1.29|Delicious| \ + Bean|$0.37|Fiber| + Squash|$1.83|Healthy| + +The advantage of including the optional trailing `|` when using a +"row-joiner" is that renderers that do not support the "row-joiner" +will see that as a superfluous extra column instead and discard it. + ~~~~~~~~~~~ Style Sheet