1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Allow parsedown to specify list start attribute

Syntax preferences to match surrounding code
This commit is contained in:
Aidan Woods 2016-10-05 18:15:47 +01:00 committed by GitHub
parent e3cd271f16
commit a37797ef34

View File

@ -503,6 +503,7 @@ class Parsedown
protected function blockList($Line) protected function blockList($Line)
{ {
list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]+[.]'); list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]+[.]');
if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches)) if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches))
{ {
$Block = array( $Block = array(
@ -513,14 +514,16 @@ class Parsedown
'handler' => 'elements', 'handler' => 'elements',
), ),
); );
if($name === 'ol') if($name === 'ol')
{ {
$list_num = stristr($matches[0], ".", true); $listStart = stristr($matches[0], ".", true);
if($list_num !== '1') if($listStart !== '1')
{ {
$Block['element']['attributes'] = array('start' => $list_num); $Block['element']['attributes'] = array('start' => $listStart);
} }
} }
$Block['li'] = array( $Block['li'] = array(
'name' => 'li', 'name' => 'li',
'handler' => 'li', 'handler' => 'li',
@ -528,7 +531,9 @@ class Parsedown
$matches[2], $matches[2],
), ),
); );
$Block['element']['text'] []= & $Block['li']; $Block['element']['text'] []= & $Block['li'];
return $Block; return $Block;
} }
} }