Skip to content
Browse files

Fix for adjacent list of different kind.

  • Loading branch information...
1 parent bf63664 commit 4bd7facc2bbf68cf20b7ca7b56e8dc75a3b85495 @michelf committed Jan 1, 2009
Showing with 21 additions and 6 deletions.
  1. +6 −0 PHP Markdown Readme.text
  2. +15 −6 markdown.php
View
6 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.
View
21 markdown.php
@@ -929,19 +929,22 @@ function doLists($text) {
$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 @@ function doLists($text) {
[ ]*
'.$marker_re.'[ ]+
)
+ |
+ (?= # Lookahead for another kind of list
+ \n
+ \3 # Must have the same indentation
+ '.$other_marker_re.'[ ]+
+ )
)
)
'; // mx
@@ -982,7 +991,7 @@ function _doLists_callback($matches) {
$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 );

0 comments on commit 4bd7fac

Please sign in to comment.
Something went wrong with that request. Please try again.