Merge branch 'lib' of git://github.com/mattgorle/php-markdown into lib

Conflicts:
	Michelf/Markdown.php
This commit is contained in:
Michel Fortin 2015-02-28 22:17:31 -05:00
commit 1e17706669

View file

@ -65,6 +65,19 @@ class Markdown implements MarkdownInterface {
# Optional header id="" generation callback function.
public $header_id_func = null;
# 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
# <ol start="2">
# <li>List item two</li>
# <li>List item three</li>
# </ol>
public $enhanced_ordered_list = false;
### Parser Implementation ###
# Regex to match balanced [brackets].
@ -886,16 +899,33 @@ class Markdown implements MarkdownInterface {
$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);
$result = $this->hashBlock("<$list_type>\n" . $result . "</$list_type>");
$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 . "</$list_type>");
} else {
$result = $this->hashBlock("<$list_type>\n" . $result . "</$list_type>");
}
return "\n". $result ."\n\n";
}
@ -1620,7 +1650,6 @@ abstract class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
# Predefined abbreviations.
public $predef_abbr = array();
### Parser Implementation ###
public function __construct() {
@ -1649,6 +1678,7 @@ abstract class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
"doAbbreviations" => 70,
);
$this->enhanced_ordered_list = true;
parent::__construct();
}
@ -3185,5 +3215,4 @@ abstract class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
return $matches[0];
}
}
}