mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
0d28808392 | |||
78960cf792 | |||
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']);
|
||||
}
|
||||
@ -701,6 +692,8 @@ class Parsedown
|
||||
if (isset($matches[2]) or in_array($matches[1], $this->voidElements))
|
||||
{
|
||||
$Block['closed'] = true;
|
||||
|
||||
$Block['void'] = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -758,6 +751,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 +935,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 +1323,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'];
|
||||
@ -1380,10 +1377,7 @@ class Parsedown
|
||||
#
|
||||
# ~
|
||||
|
||||
protected $unmarkedInlineTypes = array(
|
||||
"\n" => 'Break',
|
||||
'://' => 'Url',
|
||||
);
|
||||
protected $unmarkedInlineTypes = array("\n" => 'Break', '://' => 'Url');
|
||||
|
||||
# ~
|
||||
|
||||
@ -1507,7 +1501,7 @@ class Parsedown
|
||||
# Fields
|
||||
#
|
||||
|
||||
protected $Definitions;
|
||||
protected $DefinitionData;
|
||||
|
||||
#
|
||||
# Read-only
|
||||
|
Reference in New Issue
Block a user