From a125798c270ecf67d14495f3ce7972fee8c71d57 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Thu, 21 Nov 2019 20:45:47 -0700 Subject: [PATCH] Markdown.pl: process lists, code blocks and blockquotes together When processing something like this: * first > quoted * second It's imperative that the list tags and blockquote tags do not become intermingled resulting in invalid output like so:

Instead, process the lists together with code blocks and blockquotes so that cannot happen and instead we get the correct output like so: Signed-off-by: Kyle J. McKay --- Markdown.pl | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/Markdown.pl b/Markdown.pl index 7026b3b..9b76221 100755 --- a/Markdown.pl +++ b/Markdown.pl @@ -850,11 +850,7 @@ sub _RunBlockGamut { $text =~ s{^ {0,3}\_(?: {0,2}\_){2,}[ ]*$}{\n $-[0]) { + $text .= _DoListBlocks(substr($parse, $-[0], $-[1] - $-[0])); + } + $text .= &$list_item_sub(@captures); + } + $text .= _DoListBlocks(substr($parse, pos($parse))) if pos($parse) < length($parse); } else { - $text =~ s{ + my $parse = $text; + $text = ""; + pos($parse) = 0; + while ($parse =~ m{\G(?s:.)*? (?: (?<=\n\n) | \A\n? | (?<=:\n) | @@ -1733,9 +1742,14 @@ sub _DoLists { [ ]{$indent,$less_than_double_indent}$marker_any[ ])) ) $whole_list - }{ - &$list_item_sub($1, $2, $3, $4); - }egmx; + }gmcx) { + my @captures = ($1, $2, $3, $4); + if ($-[1] > $-[0]) { + $text .= _DoListBlocks(substr($parse, $-[0], $-[1] - $-[0])); + } + $text .= &$list_item_sub(@captures); + } + $text .= _DoListBlocks(substr($parse, pos($parse))) if pos($parse) < length($parse); } return $text; @@ -1895,7 +1909,7 @@ sub _ProcessListItems { } else { # Recursion for sub-lists: - $item = _DoLists(_Outdent($item)); + $item = _DoListsAndBlocks(_Outdent($item)); chomp $item; $item = _RunSpanGamut($item); } @@ -1916,7 +1930,7 @@ sub _ProcessListItems { } # Anything left over (similar to $') goes into result, but this should always be empty - $result .= _RunBlockGamut(substr($list_str, pos($list_str))); + $result .= _RunBlockGamut(substr($list_str, pos($list_str))) if pos($list_str) < length($list_str); $g_list_level--; @@ -2101,7 +2115,7 @@ sub _DoBlockQuotes { $bq =~ s/^[ ]+$//mg; # trim whitespace-only lines $bq = _RunBlockGamut($bq); # recurse - $bq =~ s/^/ /mg; + $bq =~ s/^/\027/mg; "
\n$bq\n
\n\n"; }egmx;