mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
definitions are blocks
in the old implementation it wasn’t possible to have multiline definitions
This commit is contained in:
parent
3eb6d349f0
commit
8f2e9c7cf6
@ -29,7 +29,7 @@ class Parsedown
|
||||
function text($text)
|
||||
{
|
||||
# make sure no definitions are set
|
||||
$this->Definitions = array();
|
||||
$this->DefinitionData = array();
|
||||
|
||||
# standardize line breaks
|
||||
$text = str_replace("\r\n", "\n", $text);
|
||||
@ -104,6 +104,7 @@ class Parsedown
|
||||
'<' => array('Comment', 'Markup'),
|
||||
'=' => array('SetextHeader'),
|
||||
'>' => array('Quote'),
|
||||
'[' => array('Reference'),
|
||||
'_' => array('Rule'),
|
||||
'`' => array('FencedCode'),
|
||||
'|' => array('Table'),
|
||||
@ -199,21 +200,6 @@ class Parsedown
|
||||
|
||||
$marker = $text[0];
|
||||
|
||||
if (isset($this->DefinitionTypes[$marker]))
|
||||
{
|
||||
foreach ($this->DefinitionTypes[$marker] as $definitionType)
|
||||
{
|
||||
$Definition = $this->{'definition'.$definitionType}($Line, $CurrentBlock);
|
||||
|
||||
if (isset($Definition))
|
||||
{
|
||||
$this->Definitions[$definitionType][$Definition['id']] = $Definition['data'];
|
||||
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# ~
|
||||
|
||||
$blockTypes = $this->unmarkedBlockTypes;
|
||||
@ -290,6 +276,11 @@ class Parsedown
|
||||
|
||||
foreach ($Blocks as $Block)
|
||||
{
|
||||
if (isset($Block['hidden']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$markup .= "\n";
|
||||
$markup .= isset($Block['markup']) ? $Block['markup'] : $this->element($Block['element']);
|
||||
}
|
||||
@ -758,6 +749,35 @@ class Parsedown
|
||||
return $Block;
|
||||
}
|
||||
|
||||
#
|
||||
# Reference
|
||||
|
||||
protected function blockReference($Line)
|
||||
{
|
||||
if (preg_match('/^\[(.+?)\]:[ ]*<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*$/', $Line['text'], $matches))
|
||||
{
|
||||
$id = strtolower($matches[1]);
|
||||
|
||||
$Data = array(
|
||||
'url' => $matches[2],
|
||||
'title' => null,
|
||||
);
|
||||
|
||||
if (isset($matches[3]))
|
||||
{
|
||||
$Data['title'] = $matches[3];
|
||||
}
|
||||
|
||||
$this->DefinitionData['Reference'][$id] = $Data;
|
||||
|
||||
$Block = array(
|
||||
'hidden' => true,
|
||||
);
|
||||
|
||||
return $Block;
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Table
|
||||
|
||||
@ -913,31 +933,6 @@ class Parsedown
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Definitions
|
||||
#
|
||||
|
||||
protected function definitionReference($Line)
|
||||
{
|
||||
if (preg_match('/^\[(.+?)\]:[ ]*<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*$/', $Line['text'], $matches))
|
||||
{
|
||||
$Definition = array(
|
||||
'id' => strtolower($matches[1]),
|
||||
'data' => array(
|
||||
'url' => $matches[2],
|
||||
'title' => null,
|
||||
),
|
||||
);
|
||||
|
||||
if (isset($matches[3]))
|
||||
{
|
||||
$Definition['data']['title'] = $matches[3];
|
||||
}
|
||||
|
||||
return $Definition;
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# ~
|
||||
#
|
||||
@ -1326,12 +1321,12 @@ class Parsedown
|
||||
$definition = strtolower($Element['text']);
|
||||
}
|
||||
|
||||
if ( ! isset($this->Definitions['Reference'][$definition]))
|
||||
if ( ! isset($this->DefinitionData['Reference'][$definition]))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$Definition = $this->Definitions['Reference'][$definition];
|
||||
$Definition = $this->DefinitionData['Reference'][$definition];
|
||||
|
||||
$Element['attributes']['href'] = $Definition['url'];
|
||||
$Element['attributes']['title'] = $Definition['title'];
|
||||
@ -1507,7 +1502,7 @@ class Parsedown
|
||||
# Fields
|
||||
#
|
||||
|
||||
protected $Definitions;
|
||||
protected $DefinitionData;
|
||||
|
||||
#
|
||||
# Read-only
|
||||
|
Loading…
Reference in New Issue
Block a user