From b4995d75b85154a5c861d4ff68c29ae865125418 Mon Sep 17 00:00:00 2001 From: Matt Gorle Date: Tue, 16 Jul 2013 09:17:20 +0100 Subject: [PATCH 1/4] Implemented some of Enhanced Ordered Lists: numerically ordered lists now start with the first number given. For example, if you start your list in Markdown as follows: 2. second list item 3. third list item then Markdown will produce this:
  1. second list item
  2. third list item
--- Michelf/Markdown.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Michelf/Markdown.php b/Michelf/Markdown.php index 094b0ee..1f5b223 100644 --- a/Michelf/Markdown.php +++ b/Michelf/Markdown.php @@ -851,16 +851,27 @@ class Markdown { $marker_ul_re = '[*+-]'; $marker_ol_re = '\d+[\.]'; $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; + $marker_ol_start_re = '[0-9]+'; $list = $matches[1]; $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol"; $marker_any_re = ( $list_type == "ul" ? $marker_ul_re : $marker_ol_re ); + # Get the start number for ordered list. + $ol_start = 1; + if ($list_type == 'ol') { + $ol_start_array = array(); + $ol_start_check = preg_match("/$marker_ol_start_re/", $matches[4], $ol_start_array); + if ($ol_start_check){ + $ol_start = $ol_start_array[0]; + } + } + $list .= "\n"; $result = $this->processListItems($list, $marker_any_re); - $result = $this->hashBlock("<$list_type>\n" . $result . ""); + $result = $this->hashBlock("<$list_type start=\"$ol_start\">\n" . $result . ""); return "\n". $result ."\n\n"; } From 16c510e924d66d6bdade8420fca71b2d589268f4 Mon Sep 17 00:00:00 2001 From: "Matt Gorle matt@gorle.co.uk" Date: Tue, 16 Jul 2013 20:10:39 +0100 Subject: [PATCH 2/4] Moved enhanced ordered list implementation to MarkdownExtra class. Added configuration variable to enable enhanced ordered list. Enhanced ordered list is disabled by default. Removed extra 'start="1"' when the list's starting value is 1 Removed 'start="1"' on unordered lists --- Michelf/Markdown.php | 76 +++++++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 18 deletions(-) diff --git a/Michelf/Markdown.php b/Michelf/Markdown.php index 1f5b223..21239d1 100644 --- a/Michelf/Markdown.php +++ b/Michelf/Markdown.php @@ -847,31 +847,20 @@ class Markdown { return $text; } protected function _doLists_callback($matches) { - # Re-usable patterns to match list item bullets and number markers: - $marker_ul_re = '[*+-]'; - $marker_ol_re = '\d+[\.]'; + # Re-usable patterns to match list item bullets and number markers: + $marker_ul_re = '[*+-]'; + $marker_ol_re = '\d+[\.]'; $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; - $marker_ol_start_re = '[0-9]+'; - + $list = $matches[1]; $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol"; - + $marker_any_re = ( $list_type == "ul" ? $marker_ul_re : $marker_ol_re ); - - # Get the start number for ordered list. - $ol_start = 1; - if ($list_type == 'ol') { - $ol_start_array = array(); - $ol_start_check = preg_match("/$marker_ol_start_re/", $matches[4], $ol_start_array); - if ($ol_start_check){ - $ol_start = $ol_start_array[0]; - } - } $list .= "\n"; $result = $this->processListItems($list, $marker_any_re); - - $result = $this->hashBlock("<$list_type start=\"$ol_start\">\n" . $result . ""); + + $result = $this->hashBlock("<$list_type>\n" . $result . ""); return "\n". $result ."\n\n"; } @@ -1564,6 +1553,18 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { # Predefined abbreviations. public $predef_abbr = array(); + # Class attribute to toggle "enhanced ordered list" behaviour + # setting this to true will allow ordered lists to start from the index + # number that is defined first. For example: + # 2. List item two + # 3. List item three + # + # becomes + #
    + #
  1. List item two
  2. + #
  3. List item three
  4. + #
+ public $enhanced_ordered_list = false; ### Parser Implementation ### @@ -3101,6 +3102,45 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { } } + protected function _doLists_callback($matches) { + # Re-usable patterns to match list item bullets and number markers: + $marker_ul_re = '[*+-]'; + $marker_ol_re = '\d+[\.]'; + $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; + $marker_ol_start_re = '[0-9]+'; + + $list = $matches[1]; + $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol"; + + $marker_any_re = ( $list_type == "ul" ? $marker_ul_re : $marker_ol_re ); + + $list .= "\n"; + $result = $this->processListItems($list, $marker_any_re); + + print "OVERRIDE "; + var_dump($this->enhanced_ordered_list); + + $ol_start = 1; + if ($this->enhanced_ordered_list) { + print "OVERRIDE"; + # Get the start number for ordered list. + if ($list_type == 'ol') { + $ol_start_array = array(); + $ol_start_check = preg_match("/$marker_ol_start_re/", $matches[4], $ol_start_array); + if ($ol_start_check){ + $ol_start = $ol_start_array[0]; + } + } + } + + if ($ol_start > 1 && $list_type == 'ol'){ + $result = $this->hashBlock("<$list_type start=\"$ol_start\">\n" . $result . ""); + } else { + $result = $this->hashBlock("<$list_type>\n" . $result . ""); + } + return "\n". $result ."\n\n"; + } + } From ae374da0b0a7a7c608f28230bd59e526d2aec7f8 Mon Sep 17 00:00:00 2001 From: "Matt Gorle matt@gorle.co.uk" Date: Tue, 16 Jul 2013 20:16:27 +0100 Subject: [PATCH 3/4] Removed debug text. --- Michelf/Markdown.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Michelf/Markdown.php b/Michelf/Markdown.php index 21239d1..a52255c 100644 --- a/Michelf/Markdown.php +++ b/Michelf/Markdown.php @@ -3117,12 +3117,8 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { $list .= "\n"; $result = $this->processListItems($list, $marker_any_re); - print "OVERRIDE "; - var_dump($this->enhanced_ordered_list); - $ol_start = 1; if ($this->enhanced_ordered_list) { - print "OVERRIDE"; # Get the start number for ordered list. if ($list_type == 'ol') { $ol_start_array = array(); From e984fa0a4b626cc90e9112dfcda0af86d67edca9 Mon Sep 17 00:00:00 2001 From: "Matt Gorle matt@gorle.co.uk" Date: Tue, 16 Jul 2013 22:31:12 +0100 Subject: [PATCH 4/4] Moved enhanced ordered list behaviour back into Markdown class. Moved enhanced_ordered_list field into Markdown class, default value is false. Made MarkdownExtra enable enhanced ordered list by default. --- Michelf/Markdown.php | 87 +++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 53 deletions(-) diff --git a/Michelf/Markdown.php b/Michelf/Markdown.php index a52255c..a161da8 100644 --- a/Michelf/Markdown.php +++ b/Michelf/Markdown.php @@ -59,6 +59,18 @@ class Markdown { public $predef_urls = array(); public $predef_titles = array(); + # Class attribute to toggle "enhanced ordered list" behaviour + # setting this to true will allow ordered lists to start from the index + # number that is defined first. For example: + # 2. List item two + # 3. List item three + # + # becomes + #
    + #
  1. List item two
  2. + #
  3. List item three
  4. + #
+ public $enhanced_ordered_list = false; ### Parser Implementation ### @@ -847,10 +859,11 @@ class Markdown { return $text; } protected function _doLists_callback($matches) { - # Re-usable patterns to match list item bullets and number markers: - $marker_ul_re = '[*+-]'; - $marker_ol_re = '\d+[\.]'; + # Re-usable patterns to match list item bullets and number markers: + $marker_ul_re = '[*+-]'; + $marker_ol_re = '\d+[\.]'; $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; + $marker_ol_start_re = '[0-9]+'; $list = $matches[1]; $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol"; @@ -860,7 +873,23 @@ class Markdown { $list .= "\n"; $result = $this->processListItems($list, $marker_any_re); - $result = $this->hashBlock("<$list_type>\n" . $result . ""); + $ol_start = 1; + if ($this->enhanced_ordered_list) { + # Get the start number for ordered list. + if ($list_type == 'ol') { + $ol_start_array = array(); + $ol_start_check = preg_match("/$marker_ol_start_re/", $matches[4], $ol_start_array); + if ($ol_start_check){ + $ol_start = $ol_start_array[0]; + } + } + } + + if ($ol_start > 1 && $list_type == 'ol'){ + $result = $this->hashBlock("<$list_type start=\"$ol_start\">\n" . $result . ""); + } else { + $result = $this->hashBlock("<$list_type>\n" . $result . ""); + } return "\n". $result ."\n\n"; } @@ -1553,19 +1582,6 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { # Predefined abbreviations. public $predef_abbr = array(); - # Class attribute to toggle "enhanced ordered list" behaviour - # setting this to true will allow ordered lists to start from the index - # number that is defined first. For example: - # 2. List item two - # 3. List item three - # - # becomes - #
    - #
  1. List item two
  2. - #
  3. List item three
  4. - #
- public $enhanced_ordered_list = false; - ### Parser Implementation ### public function __construct() { @@ -1594,6 +1610,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { "doAbbreviations" => 70, ); + $this->enhanced_ordered_list = true; parent::__construct(); } @@ -3101,42 +3118,6 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { return $matches[0]; } } - - protected function _doLists_callback($matches) { - # Re-usable patterns to match list item bullets and number markers: - $marker_ul_re = '[*+-]'; - $marker_ol_re = '\d+[\.]'; - $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; - $marker_ol_start_re = '[0-9]+'; - - $list = $matches[1]; - $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol"; - - $marker_any_re = ( $list_type == "ul" ? $marker_ul_re : $marker_ol_re ); - - $list .= "\n"; - $result = $this->processListItems($list, $marker_any_re); - - $ol_start = 1; - if ($this->enhanced_ordered_list) { - # Get the start number for ordered list. - if ($list_type == 'ol') { - $ol_start_array = array(); - $ol_start_check = preg_match("/$marker_ol_start_re/", $matches[4], $ol_start_array); - if ($ol_start_check){ - $ol_start = $ol_start_array[0]; - } - } - } - - if ($ol_start > 1 && $list_type == 'ol'){ - $result = $this->hashBlock("<$list_type start=\"$ol_start\">\n" . $result . ""); - } else { - $result = $this->hashBlock("<$list_type>\n" . $result . ""); - } - return "\n". $result ."\n\n"; - } - }