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

definitions are not blocks

This commit is contained in:
Emanuil Rusev 2014-04-27 01:54:52 +03:00
parent 4150e00dc4
commit cf7f32f891

View File

@ -49,7 +49,7 @@ class Parsedown
$markup = trim($markup, "\n"); $markup = trim($markup, "\n");
# clean up # clean up
$this->references = array(); $this->definitions = array();
return $markup; return $markup;
} }
@ -97,7 +97,6 @@ class Parsedown
'~' => array('FencedCode'), '~' => array('FencedCode'),
); );
# Draft
protected $definitionMarkers = array( protected $definitionMarkers = array(
'[' => array('Reference'), '[' => array('Reference'),
); );
@ -169,10 +168,29 @@ class Parsedown
# ~ # ~
$blockTypes = $this->unmarkedBlockTypes;
$marker = $text[0]; $marker = $text[0];
# Definitions
if (isset($this->definitionMarkers[$marker]))
{
foreach ($this->definitionMarkers[$marker] as $definitionType)
{
$Definition = $this->{'identify'.$definitionType}($Line, $CurrentBlock);
if (isset($Definition))
{
$this->definitions[$definitionType][$Definition['id']] = $Definition['data'];
continue 2;
}
}
}
# ~
$blockTypes = $this->unmarkedBlockTypes;
if (isset($this->blockMarkers[$marker])) if (isset($this->blockMarkers[$marker]))
{ {
foreach ($this->blockMarkers[$marker] as $blockType) foreach ($this->blockMarkers[$marker] as $blockType)
@ -310,22 +328,19 @@ class Parsedown
{ {
if (preg_match('/^\[(.+?)\]:[ ]*<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*$/', $Line['text'], $matches)) if (preg_match('/^\[(.+?)\]:[ ]*<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*$/', $Line['text'], $matches))
{ {
$label = strtolower($matches[1]); $Definition = array(
'id' => strtolower($matches[1]),
$this->references[$label] = array( 'data' => array(
'url' => $matches[2], 'url' => $matches[2],
),
); );
if (isset($matches[3])) if (isset($matches[3]))
{ {
$this->references[$label]['title'] = $matches[3]; $Definition['data']['title'] = $matches[3];
} }
$Block = array( return $Definition;
'element' => null,
);
return $Block;
} }
} }
@ -1104,9 +1119,9 @@ class Parsedown
{ {
$Link['label'] = strtolower($matches[1]); $Link['label'] = strtolower($matches[1]);
if (isset($this->references[$Link['label']])) if (isset($this->definitions['Reference'][$Link['label']]))
{ {
$Link += $this->references[$Link['label']]; $Link += $this->definitions['Reference'][$Link['label']];
$extent += strlen($matches[0]); $extent += strlen($matches[0]);
} }
@ -1115,9 +1130,9 @@ class Parsedown
return; return;
} }
} }
elseif ($this->references and isset($this->references[$Link['label']])) elseif (isset($this->definitions['Reference'][$Link['label']]))
{ {
$Link += $this->references[$Link['label']]; $Link += $this->definitions['Reference'][$Link['label']];
if (preg_match('/^[ ]*\[\]/', $substring, $matches)) if (preg_match('/^[ ]*\[\]/', $substring, $matches))
{ {
@ -1285,7 +1300,7 @@ class Parsedown
# Fields # Fields
# #
protected $references = array(); # » Definitions['reference'] protected $definitions;
# #
# Read-only # Read-only