From b1baada95300e82b810e1138b0cf0a20b19e7ab3 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" <mackyle@gmail.com> Date: Thu, 19 Jan 2017 08:18:24 -0800 Subject: [PATCH] Markdown.pl: treat '*' in <ol> like last marker When processing list items, while changes to the list marker style are allowed for "ol" lists (ignored for "ul" lists), switching from "ol" to "ul" or vice-versa is not allowed mid-list. When a numbered/lettered marker is seen while processing a "ul" list it was simply treated as '*'. This always produced the correct result since the actual marker does not matter for "ul" lists. However, when a '*', '+', or '-' was seen while processing a "ol" list it was always treated as a '1.' marker. This is, however, incorrect if the list is not using decimal numbering. Instead treat a "ul" marker encountered during "ol" list processing as a repeat of the last marker seen. The lazy list numbering will kick in and bump it up by one while retaining the correct list marker style. The same treatment is also now given to "ol" markers encountered during "ul" list processing since it's simpler to code that way even though it doesn't make a difference in output in that case. Signed-off-by: Kyle J. McKay <mackyle@gmail.com> --- Markdown.pl | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Markdown.pl b/Markdown.pl index 7f79370..88c1d74 100755 --- a/Markdown.pl +++ b/Markdown.pl @@ -1490,6 +1490,7 @@ sub _ProcessListItems { my $first_marker; my $first_marker_type; my $first_marker_num; + my $last_marker; my $fancy; my $skipped; my $typechanged; @@ -1515,10 +1516,21 @@ sub _ProcessListItems { $result .= substr($list_str, $oldpos, $-[0] - $oldpos); # Sort-of $` $oldpos = $-[0]; # point at start of this entire match } - if ($list_marker !~ /$marker_kind/) { + if (!defined($first_marker)) { + $first_marker = $last_marker = $list_marker; + $first_marker_type = _GetListMarkerType($list_type, $first_marker); + if ($first_marker_type) { + (my $marker_val = $first_marker) =~ s/[.\)]$//; + $first_marker_num = _GetMarkerIntegerNum($first_marker_type, $marker_val); + $next_num = $first_marker_num; + $skipped = 1 if $next_num != 1; + } + } elsif ($list_marker !~ /$marker_kind/) { # Wrong marker kind, "fix up" the marker to a correct "lazy" marker # But keep the old length in $list_marker_len - $list_marker = $list_type eq "ul" ? "*" : "1."; + $list_marker = $last_marker; + } else { + $last_marker = $list_marker; } # Now grab the rest of this item's data upto but excluding the next @@ -1553,16 +1565,6 @@ sub _ProcessListItems { my $checkbox = ''; my $incr = ''; - if (!defined($first_marker)) { - $first_marker = $list_marker; - $first_marker_type = _GetListMarkerType($list_type, $first_marker); - if ($first_marker_type) { - (my $marker_val = $first_marker) =~ s/[.\)]$//; - $first_marker_num = _GetMarkerIntegerNum($first_marker_type, $marker_val); - $next_num = $first_marker_num; - $skipped = 1 if $next_num != 1; - } - } if ($list_type eq "ul" && !$leading_item_space && $item =~ /^\[([ xX])\] +(.*)$/s) { my $checkmark = lc $1; $item = $2;