Browse Source

Markdown.pl: do not start sublist in list marker line

Given a list like so:

  * 1. item
  * 2. items
  * 3. items

Each line contains two list item "markers".  The first is
an unordered list marker "*" and the second is an ordered
list marker ("1.", "2." or "3.").

However, a sublist (the "1.", "2." or "3.") may not start
inside the actual marker line of the parent list.

Make sure that any text on the same line following the initial
list marker does *not* get recognized as the start of a sublist.

In other words, make sure the above does _NOT_ produce:

    <ul>
      <li><ol><li>item</li></ol></li>
      <li><ol start="2"><li value="2">items</li></ol></li>
      <li><ol start="3"><li value="3">items</li></ol></li>
    </ul>

But instead more correctly produces this output:

    <ul>
      <li>1. item</li>
      <li>2. items</li>
      <li>3. items</li>
    </ul>

Recognizing a sublist start within any of the parent list's marker
lines does not make sense.  With this change this longstanding
problem is corrected once again.

The problem was first fixed in version 1.1.0 and remained fixed in
version 1.1.1 but that fix caused too many problems and was reverted
causing versions 1.1.2 through 1.1.13 to be broken again.

The technique used to fix the problem this time differs from the
previous attempt and will hopefully survive scrutiny keeping the
problem resolved from now on.

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

7
Markdown.pl

@ -2972,6 +2972,13 @@ sub _ProcessListItems {
}
$last_marker = $list_marker;
if ($item =~ /^(.+)/) {
my $ml_text = $1;
my $ml_len = length($1);
my $ml_sub = sub {my $ml_mk = shift; $ml_mk =~ s!([-+*.\)])!$g_escape_table{$1}!go; $ml_mk};
$ml_text =~ s/(?:(?<= )|\A)(${marker_any})(?= )/&$ml_sub($1)/ge;
$item = $ml_text . substr($item, $ml_len);
}
if ($leading_line or ($item =~ m/\n{2,}/)) {
$item = _RunBlockGamut(_Outdent($item));
$item =~ s{(</[OUou][Ll]>)\s*\z}{$1} and $item .= "\n$idt<span style=\"display:none\">&#160;</span>";

Loading…
Cancel
Save