mirror of
https://github.com/erusev/parsedown.git
synced 2024-09-19 19:41:29 +02:00
refactor $element
This commit is contained in:
parent
4317add3a2
commit
5521afde31
@ -129,7 +129,7 @@ class Parsedown
|
|||||||
|
|
||||||
switch ($element['type'])
|
switch ($element['type'])
|
||||||
{
|
{
|
||||||
case 'fenced_code_block':
|
case 'fenced block':
|
||||||
|
|
||||||
if ( ! isset($element['closed']))
|
if ( ! isset($element['closed']))
|
||||||
{
|
{
|
||||||
@ -149,16 +149,16 @@ class Parsedown
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'markup':
|
case 'block-level markup':
|
||||||
|
|
||||||
if ( ! isset($element['closed']))
|
if ( ! isset($element['closed']))
|
||||||
{
|
{
|
||||||
if (preg_match('{<'.$element['subtype'].'>$}', $line)) # opening tag
|
if (preg_match('{<'.$element['root '].'>$}', $line)) # opening tag
|
||||||
{
|
{
|
||||||
$element['depth']++;
|
$element['depth']++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preg_match('{</'.$element['subtype'].'>$}', $line)) # closing tag
|
if (preg_match('{</'.$element['root '].'>$}', $line)) # closing tag
|
||||||
{
|
{
|
||||||
$element['depth'] > 0
|
$element['depth'] > 0
|
||||||
? $element['depth']--
|
? $element['depth']--
|
||||||
@ -274,7 +274,7 @@ class Parsedown
|
|||||||
|
|
||||||
if (preg_match('/^[ ]{4}(.*)/', $line, $matches))
|
if (preg_match('/^[ ]{4}(.*)/', $line, $matches))
|
||||||
{
|
{
|
||||||
if ($element['type'] === 'code_block')
|
if ($element['type'] === 'code block')
|
||||||
{
|
{
|
||||||
if (isset($element['interrupted']))
|
if (isset($element['interrupted']))
|
||||||
{
|
{
|
||||||
@ -290,7 +290,7 @@ class Parsedown
|
|||||||
$elements []= $element;
|
$elements []= $element;
|
||||||
|
|
||||||
$element = array(
|
$element = array(
|
||||||
'type' => 'code_block',
|
'type' => 'code block',
|
||||||
'text' => $matches[1],
|
'text' => $matches[1],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -311,7 +311,7 @@ class Parsedown
|
|||||||
$level = strlen($matches[1]);
|
$level = strlen($matches[1]);
|
||||||
|
|
||||||
$element = array(
|
$element = array(
|
||||||
'type' => 'h.',
|
'type' => 'heading',
|
||||||
'text' => $matches[2],
|
'text' => $matches[2],
|
||||||
'level' => $level,
|
'level' => $level,
|
||||||
);
|
);
|
||||||
@ -325,9 +325,9 @@ class Parsedown
|
|||||||
|
|
||||||
# setext heading (---)
|
# setext heading (---)
|
||||||
|
|
||||||
if ($line[0] === '-' and $element['type'] === 'p' and ! isset($element['interrupted']) and preg_match('/^[-]+[ ]*$/', $line))
|
if ($line[0] === '-' and $element['type'] === 'paragraph' and ! isset($element['interrupted']) and preg_match('/^[-]+[ ]*$/', $line))
|
||||||
{
|
{
|
||||||
$element['type'] = 'h.';
|
$element['type'] = 'heading';
|
||||||
$element['level'] = 2;
|
$element['level'] = 2;
|
||||||
|
|
||||||
continue 2;
|
continue 2;
|
||||||
@ -339,9 +339,9 @@ class Parsedown
|
|||||||
|
|
||||||
# setext heading (===)
|
# setext heading (===)
|
||||||
|
|
||||||
if ($line[0] === '=' and $element['type'] === 'p' and ! isset($element['interrupted']) and preg_match('/^[=]+[ ]*$/', $line))
|
if ($line[0] === '=' and $element['type'] === 'paragraph' and ! isset($element['interrupted']) and preg_match('/^[=]+[ ]*$/', $line))
|
||||||
{
|
{
|
||||||
$element['type'] = 'h.';
|
$element['type'] = 'heading';
|
||||||
$element['level'] = 1;
|
$element['level'] = 1;
|
||||||
|
|
||||||
continue 2;
|
continue 2;
|
||||||
@ -363,7 +363,7 @@ class Parsedown
|
|||||||
$elements []= $element;
|
$elements []= $element;
|
||||||
|
|
||||||
$element = array(
|
$element = array(
|
||||||
'type' => '',
|
'type' => 'self-closing tag',
|
||||||
'text' => $deindented_line,
|
'text' => $deindented_line,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -377,9 +377,9 @@ class Parsedown
|
|||||||
$elements []= $element;
|
$elements []= $element;
|
||||||
|
|
||||||
$element = array(
|
$element = array(
|
||||||
'type' => 'markup',
|
'type' => 'block-level markup',
|
||||||
'subtype' => strtolower($matches[1]),
|
|
||||||
'text' => $deindented_line,
|
'text' => $deindented_line,
|
||||||
|
'root ' => strtolower($matches[1]),
|
||||||
'depth' => 0,
|
'depth' => 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -442,7 +442,7 @@ class Parsedown
|
|||||||
$elements []= $element;
|
$elements []= $element;
|
||||||
|
|
||||||
$element = array(
|
$element = array(
|
||||||
'type' => 'fenced_code_block',
|
'type' => 'fenced block',
|
||||||
'text' => '',
|
'text' => '',
|
||||||
'fence' => $matches[1],
|
'fence' => $matches[1],
|
||||||
);
|
);
|
||||||
@ -513,7 +513,7 @@ class Parsedown
|
|||||||
|
|
||||||
# paragraph
|
# paragraph
|
||||||
|
|
||||||
if ($element['type'] === 'p')
|
if ($element['type'] === 'paragraph')
|
||||||
{
|
{
|
||||||
if (isset($element['interrupted']))
|
if (isset($element['interrupted']))
|
||||||
{
|
{
|
||||||
@ -533,7 +533,7 @@ class Parsedown
|
|||||||
$elements []= $element;
|
$elements []= $element;
|
||||||
|
|
||||||
$element = array(
|
$element = array(
|
||||||
'type' => 'p',
|
'type' => 'paragraph',
|
||||||
'text' => $line,
|
'text' => $line,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -553,7 +553,7 @@ class Parsedown
|
|||||||
{
|
{
|
||||||
switch ($element['type'])
|
switch ($element['type'])
|
||||||
{
|
{
|
||||||
case 'p':
|
case 'paragraph':
|
||||||
|
|
||||||
$text = $this->parse_span_elements($element['text']);
|
$text = $this->parse_span_elements($element['text']);
|
||||||
|
|
||||||
@ -583,8 +583,8 @@ class Parsedown
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'code_block':
|
case 'code block':
|
||||||
case 'fenced_code_block':
|
case 'fenced block':
|
||||||
|
|
||||||
$text = htmlspecialchars($element['text'], ENT_NOQUOTES, 'UTF-8');
|
$text = htmlspecialchars($element['text'], ENT_NOQUOTES, 'UTF-8');
|
||||||
|
|
||||||
@ -598,7 +598,7 @@ class Parsedown
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h.':
|
case 'heading':
|
||||||
|
|
||||||
$text = $this->parse_span_elements($element['text']);
|
$text = $this->parse_span_elements($element['text']);
|
||||||
|
|
||||||
@ -634,7 +634,7 @@ class Parsedown
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'markup':
|
case 'block-level markup':
|
||||||
|
|
||||||
$markup .= $this->parse_span_elements($element['text'])."\n";
|
$markup .= $this->parse_span_elements($element['text'])."\n";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user