Browse Source

Markdown.pl: finesse backslash handling in tables

Prevent loss of backslash-escaping in tables by avoiding an effective
de-backslash operation that was incorrect.  Now `\\\\` always ends up
producing two backslashes whether it's in a table or not.

Adjust the regexps so that the `|` in `\|` does not get mistaken for
the final `|` of a table row when that table row has omitted the
final trailing `|`.

Also silently handle a lone `\` at the end of a table row by pretending
it was doubled rather than breaking the table.

While in that area of the code, remove a line that computed a value
which was never used.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
master
Kyle J. McKay 5 years ago
parent
commit
a833262dd7
  1. 7
      Markdown.pl

7
Markdown.pl

@ -1904,10 +1904,10 @@ sub _DoBlockQuotes {
my ($LEAD, $TRAIL, $LEADBAR, $LEADSP, $COLPL, $SEP);
BEGIN {
$LEAD = qr/(?>[ ]*(?:\|[ ]*)?)/o;
$TRAIL = qr/\|[ ]*/o;
$TRAIL = qr/[ ]*(?<!\\)\|[ ]*/o;
$LEADBAR = qr/(?>[ ]*\|[ ]*)/o;
$LEADSP = qr/(?>[ ]*)/o;
$COLPL = qr/(?:[^\n|\\]|\\[^\n])+/o;
$COLPL = qr/(?:[^\n|\\]|\\(?:(?>[^\n])|(?=\n|$)))+/o;
$SEP = qr/[ ]*:?-+:?[ ]*/o;
}
@ -1944,7 +1944,6 @@ sub _DoTables {
elsif (/:$/) {" align=\"right\""}
else {""}
} @seps;
my $headers = _MakeTableRow("th", \@align, @heads);
my $tab ="\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\" class=\"$opt{style_prefix}table\">\n" .
" <tr class=\"$opt{style_prefix}row-hdr\">" . _MakeTableRow("th", \@align, @heads) . "</tr>\n";
my $cnt = 0;
@ -1969,7 +1968,7 @@ sub _SplitTableRow {
$row =~ s!\\\|!$g_escape_table{'|'}!go; # Then do \|
my @elems = map {
s!$g_escape_table{'|'}!|!go;
s!$g_escape_table{'\\'}!\\!go;
s!$g_escape_table{'\\'}!\\\\!go;
s/^[ ]+//;
s/[ ]+$//;
$_;

Loading…
Cancel
Save