From 4bd7facc2bbf68cf20b7ca7b56e8dc75a3b85495 Mon Sep 17 00:00:00 2001 From: Michel Fortin Date: Thu, 1 Jan 2009 09:29:26 -0500 Subject: [PATCH] Fix for adjacent list of different kind. --- PHP Markdown Readme.text | 6 ++++++ markdown.php | 21 +++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/PHP Markdown Readme.text b/PHP Markdown Readme.text index 2778f5e..958728f 100644 --- a/PHP Markdown Readme.text +++ b/PHP Markdown Readme.text @@ -200,6 +200,12 @@ expected; (3) the output PHP Markdown actually produced. Version History --------------- +Current: + +* Fix for adjacent list of different kind where the second list could + end as a sublist of the first when not separated by an empty line. + + 1.0.1m (21 Jun 2008): * Lists can now have empty items. diff --git a/markdown.php b/markdown.php index b61a942..c976e82 100644 --- a/markdown.php +++ b/markdown.php @@ -929,19 +929,22 @@ class Markdown_Parser { $marker_ol_re = '\d+[.]'; $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; - $markers_relist = array($marker_ul_re, $marker_ol_re); + $markers_relist = array( + $marker_ul_re => $marker_ol_re, + $marker_ol_re => $marker_ul_re, + ); - foreach ($markers_relist as $marker_re) { + foreach ($markers_relist as $marker_re => $other_marker_re) { # Re-usable pattern to match any entirel ul or ol list: $whole_list_re = ' ( # $1 = whole list ( # $2 - [ ]{0,'.$less_than_tab.'} - ('.$marker_re.') # $3 = first list item marker + ([ ]{0,'.$less_than_tab.'}) # $3 = number of spaces + ('.$marker_re.') # $4 = first list item marker [ ]+ ) (?s:.+?) - ( # $4 + ( # $5 \z | \n{2,} @@ -950,6 +953,12 @@ class Markdown_Parser { [ ]* '.$marker_re.'[ ]+ ) + | + (?= # Lookahead for another kind of list + \n + \3 # Must have the same indentation + '.$other_marker_re.'[ ]+ + ) ) ) '; // mx @@ -982,7 +991,7 @@ class Markdown_Parser { $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; $list = $matches[1]; - $list_type = preg_match("/$marker_ul_re/", $matches[3]) ? "ul" : "ol"; + $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol"; $marker_any_re = ( $list_type == "ul" ? $marker_ul_re : $marker_ol_re );