mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Allow parsedown to specify list start attribute
Readability improvements
This commit is contained in:
parent
932bafe0f0
commit
1fa8fae301
@ -502,23 +502,30 @@ 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(
|
||||||
'indent' => $Line['indent'],
|
'indent' => $Line['indent'],
|
||||||
'pattern' => preg_replace('/\(|\)/', '', $pattern),
|
'pattern' => $pattern,
|
||||||
'element' => array(
|
'element' => array(
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'handler' => 'elements',
|
'handler' => 'elements',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if($name === 'ol' && $matches[2] !== '1') $Block['element']['attributes'] = array('start' => $matches[2]);
|
if($name === 'ol')
|
||||||
|
{
|
||||||
|
$list_num = explode ('.', $matches[0], 1)[0];
|
||||||
|
if($list_num !== '1')
|
||||||
|
{
|
||||||
|
$Block['element']['attributes'] = array('start' => $list_num);
|
||||||
|
}
|
||||||
|
}
|
||||||
$Block['li'] = array(
|
$Block['li'] = array(
|
||||||
'name' => 'li',
|
'name' => 'li',
|
||||||
'handler' => 'li',
|
'handler' => 'li',
|
||||||
'text' => array(
|
'text' => array(
|
||||||
$matches[3],
|
$matches[2],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
$Block['element']['text'] []= & $Block['li'];
|
$Block['element']['text'] []= & $Block['li'];
|
||||||
|
Loading…
Reference in New Issue
Block a user