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

outdented is shorter and probably more accurate

This commit is contained in:
Emanuil Rusev 2014-02-02 23:41:06 +02:00
parent 5a525be070
commit 6e93b68692

View File

@ -164,11 +164,11 @@ class Parsedown
$indentation++; $indentation++;
} }
$deindented_line = $indentation > 0 ? ltrim($line) : $line; $outdented_line = $indentation > 0 ? ltrim($line) : $line;
# blank # blank
if ($deindented_line === '') if ($outdented_line === '')
{ {
$block['interrupted'] = true; $block['interrupted'] = true;
@ -194,7 +194,7 @@ class Parsedown
case 'li': case 'li':
if ($block['indentation'] === $indentation and preg_match('/^'.$block['marker'].'[ ]+(.*)/', $deindented_line, $matches)) if ($block['indentation'] === $indentation and preg_match('/^'.$block['marker'].'[ ]+(.*)/', $outdented_line, $matches))
{ {
unset($block['last']); unset($block['last']);
@ -330,15 +330,15 @@ class Parsedown
# indentation insensitive types # indentation insensitive types
switch ($deindented_line[0]) switch ($outdented_line[0])
{ {
case '<': case '<':
$position = strpos($deindented_line, '>'); $position = strpos($outdented_line, '>');
if ($position > 1) if ($position > 1)
{ {
$substring = substr($deindented_line, 1, $position - 1); $substring = substr($outdented_line, 1, $position - 1);
$substring = chop($substring); $substring = chop($substring);
@ -376,7 +376,7 @@ class Parsedown
{ {
$block = array( $block = array(
'type' => 'self-closing tag', 'type' => 'self-closing tag',
'text' => $deindented_line, 'text' => $outdented_line,
); );
unset($is_self_closing); unset($is_self_closing);
@ -386,13 +386,13 @@ class Parsedown
$block = array( $block = array(
'type' => 'markup', 'type' => 'markup',
'text' => $deindented_line, 'text' => $outdented_line,
'start' => '<'.$name.'>', 'start' => '<'.$name.'>',
'end' => '</'.$name.'>', 'end' => '</'.$name.'>',
'depth' => 0, 'depth' => 0,
); );
if (strpos($deindented_line, $block['end'])) if (strpos($outdented_line, $block['end']))
{ {
$block['closed'] = true; $block['closed'] = true;
} }
@ -406,7 +406,7 @@ class Parsedown
# quote # quote
if (preg_match('/^>[ ]?(.*)/', $deindented_line, $matches)) if (preg_match('/^>[ ]?(.*)/', $outdented_line, $matches))
{ {
$blocks []= $block; $blocks []= $block;
@ -426,7 +426,7 @@ class Parsedown
# reference # reference
if (preg_match('/^\[(.+?)\]:[ ]*(.+?)(?:[ ]+[\'"](.+?)[\'"])?[ ]*$/', $deindented_line, $matches)) if (preg_match('/^\[(.+?)\]:[ ]*(.+?)(?:[ ]+[\'"](.+?)[\'"])?[ ]*$/', $outdented_line, $matches))
{ {
$label = strtolower($matches[1]); $label = strtolower($matches[1]);
@ -449,7 +449,7 @@ class Parsedown
# fenced code block # fenced code block
if (preg_match('/^([`]{3,}|[~]{3,})[ ]*(\S+)?[ ]*$/', $deindented_line, $matches)) if (preg_match('/^([`]{3,}|[~]{3,})[ ]*(\S+)?[ ]*$/', $outdented_line, $matches))
{ {
$blocks []= $block; $blocks []= $block;
@ -476,7 +476,7 @@ class Parsedown
# hr # hr
if (preg_match('/^([-*_])([ ]{0,2}\1){2,}[ ]*$/', $deindented_line)) if (preg_match('/^([-*_])([ ]{0,2}\1){2,}[ ]*$/', $outdented_line))
{ {
$blocks []= $block; $blocks []= $block;
@ -489,7 +489,7 @@ class Parsedown
# li # li
if (preg_match('/^([*+-][ ]+)(.*)/', $deindented_line, $matches)) if (preg_match('/^([*+-][ ]+)(.*)/', $outdented_line, $matches))
{ {
$blocks []= $block; $blocks []= $block;
@ -513,7 +513,7 @@ class Parsedown
# li # li
if ($deindented_line[0] <= '9' and preg_match('/^(\d+[.][ ]+)(.*)/', $deindented_line, $matches)) if ($outdented_line[0] <= '9' and preg_match('/^(\d+[.][ ]+)(.*)/', $outdented_line, $matches))
{ {
$blocks []= $block; $blocks []= $block;