Skip to content

Commit

Permalink
Fix for adjacent list of different kind.
Browse files Browse the repository at this point in the history
  • Loading branch information
michelf committed Jan 1, 2009
1 parent bf63664 commit 4bd7fac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
6 changes: 6 additions & 0 deletions PHP Markdown Readme.text
Expand Up @@ -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.
Expand Down
21 changes: 15 additions & 6 deletions markdown.php
Expand Up @@ -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,}
Expand All @@ -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
Expand Down Expand Up @@ -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 );

Expand Down

0 comments on commit 4bd7fac

Please sign in to comment.