From afb45ff2950f2b5beb0a355b2a7035ddb596c5dc Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 28 Oct 2019 02:44:14 -0700 Subject: [PATCH] Markdown.pl: omit empty table header rows There's no point to including an empty header row in the output table. It looks ugly. While the header row is syntactically required in order to recognize the table markup, omit it from the output if all its column cells are empty ignoring any whitespace. This gives a more pleasing result. Additionally add an extra class tag "...-table-nohdr" in addition to the usual "...-table" tag to allow easy custom formatting of these headerless tables if desired. Empty body rows are always preserved because they can always be omitted without breaking the table syntax. Update the docs to describe the new behavior. Signed-off-by: Kyle J. McKay --- Markdown.pl | 8 ++++++-- syntax.md | 14 ++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Markdown.pl b/Markdown.pl index 282414b..28d89bb 100755 --- a/Markdown.pl +++ b/Markdown.pl @@ -1944,8 +1944,12 @@ sub _DoTables { elsif (/:$/) {" align=\"right\""} else {""} } @seps; - my $tab ="\n\n" . - " " . _MakeTableRow("th", \@align, @heads) . "\n"; + my $nohdr = ""; + $nohdr = " $opt{style_prefix}table-nohdr" if join("", @heads) eq ""; + my $tab ="\n
\n"; + $tab .= + " " . _MakeTableRow("th", \@align, @heads) . "\n" + 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" diff --git a/syntax.md b/syntax.md index ecc91c2..8c892ca 100644 --- a/syntax.md +++ b/syntax.md @@ -574,14 +574,16 @@ Output:
Bean$0.37Fiber
-The leading and trailing `|` on each line are optional unless there is only -a single column in which case at least one `|` is always required -- two if -the single column contains only whitespace. +The leading `|` on each line is optional unless the first column contains only +zero or more spaces and/or tabs. The trailing `|` on each line is optional +unless the last column contains only zero or more spaces and/or tabs. + +At least one `|` must be present in every row of the table. Leading and trailing whitespace are always trimmed from each column's value before using it. -To include a literal `|` (veritical bar) character in a column's value, precede +To include a literal `|` (vertical bar) character in a column's value, precede it with a `\` (backslash). To include a literal `\` use `\\` (double them). The number of columns in the separator row must match exactly the number of @@ -595,6 +597,10 @@ be `right`. And finally, with a colon on both ends the alignment will be `center`. The alignment will be applied to the column in both header and body rows. +If all columns in the header row are empty (i.e. contain only zero or more +spaces and/or tabs), the header row will be omitted from the output. Empty +rows in the body of the table are always preserved in the output. + Body rows that contain fewer columns than the header row have empty columns added. Body rows that contain more columns than the header row have the extra columns dropped.