[upd] Parsedown to 1.6.0
This commit is contained in:
parent
0605188d4e
commit
e68e261882
1 changed files with 42 additions and 32 deletions
|
@ -17,7 +17,7 @@ class Parsedown
|
||||||
{
|
{
|
||||||
# ~
|
# ~
|
||||||
|
|
||||||
const version = '1.5.3';
|
const version = '1.6.0';
|
||||||
|
|
||||||
# ~
|
# ~
|
||||||
|
|
||||||
|
@ -107,12 +107,6 @@ function setUrlsLinked($urlsLinked)
|
||||||
|
|
||||||
# ~
|
# ~
|
||||||
|
|
||||||
protected $DefinitionTypes = array(
|
|
||||||
'[' => array('Reference'),
|
|
||||||
);
|
|
||||||
|
|
||||||
# ~
|
|
||||||
|
|
||||||
protected $unmarkedBlockTypes = array(
|
protected $unmarkedBlockTypes = array(
|
||||||
'Code',
|
'Code',
|
||||||
);
|
);
|
||||||
|
@ -121,7 +115,7 @@ function setUrlsLinked($urlsLinked)
|
||||||
# Blocks
|
# Blocks
|
||||||
#
|
#
|
||||||
|
|
||||||
private function lines(array $lines)
|
protected function lines(array $lines)
|
||||||
{
|
{
|
||||||
$CurrentBlock = null;
|
$CurrentBlock = null;
|
||||||
|
|
||||||
|
@ -169,7 +163,7 @@ private function lines(array $lines)
|
||||||
|
|
||||||
# ~
|
# ~
|
||||||
|
|
||||||
if (isset($CurrentBlock['incomplete']))
|
if (isset($CurrentBlock['continuable']))
|
||||||
{
|
{
|
||||||
$Block = $this->{'block'.$CurrentBlock['type'].'Continue'}($Line, $CurrentBlock);
|
$Block = $this->{'block'.$CurrentBlock['type'].'Continue'}($Line, $CurrentBlock);
|
||||||
|
|
||||||
|
@ -181,12 +175,10 @@ private function lines(array $lines)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (method_exists($this, 'block'.$CurrentBlock['type'].'Complete'))
|
if ($this->isBlockCompletable($CurrentBlock['type']))
|
||||||
{
|
{
|
||||||
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
|
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($CurrentBlock['incomplete']);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,9 +216,9 @@ private function lines(array $lines)
|
||||||
$Block['identified'] = true;
|
$Block['identified'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method_exists($this, 'block'.$blockType.'Continue'))
|
if ($this->isBlockContinuable($blockType))
|
||||||
{
|
{
|
||||||
$Block['incomplete'] = true;
|
$Block['continuable'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$CurrentBlock = $Block;
|
$CurrentBlock = $Block;
|
||||||
|
@ -253,7 +245,7 @@ private function lines(array $lines)
|
||||||
|
|
||||||
# ~
|
# ~
|
||||||
|
|
||||||
if (isset($CurrentBlock['incomplete']) and method_exists($this, 'block'.$CurrentBlock['type'].'Complete'))
|
if (isset($CurrentBlock['continuable']) and $this->isBlockCompletable($CurrentBlock['type']))
|
||||||
{
|
{
|
||||||
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
|
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
|
||||||
}
|
}
|
||||||
|
@ -286,6 +278,16 @@ private function lines(array $lines)
|
||||||
return $markup;
|
return $markup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function isBlockContinuable($Type)
|
||||||
|
{
|
||||||
|
return method_exists($this, 'block'.$Type.'Continue');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function isBlockCompletable($Type)
|
||||||
|
{
|
||||||
|
return method_exists($this, 'block'.$Type.'Complete');
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Code
|
# Code
|
||||||
|
|
||||||
|
@ -394,16 +396,16 @@ protected function blockCommentContinue($Line, array $Block)
|
||||||
|
|
||||||
protected function blockFencedCode($Line)
|
protected function blockFencedCode($Line)
|
||||||
{
|
{
|
||||||
if (preg_match('/^(['.$Line['text'][0].']{3,})[ ]*([\w-]+)?[ ]*$/', $Line['text'], $matches))
|
if (preg_match('/^['.$Line['text'][0].']{3,}[ ]*([\w-]+)?[ ]*$/', $Line['text'], $matches))
|
||||||
{
|
{
|
||||||
$Element = array(
|
$Element = array(
|
||||||
'name' => 'code',
|
'name' => 'code',
|
||||||
'text' => '',
|
'text' => '',
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isset($matches[2]))
|
if (isset($matches[1]))
|
||||||
{
|
{
|
||||||
$class = 'language-'.$matches[2];
|
$class = 'language-'.$matches[1];
|
||||||
|
|
||||||
$Element['attributes'] = array(
|
$Element['attributes'] = array(
|
||||||
'class' => $class,
|
'class' => $class,
|
||||||
|
@ -673,7 +675,9 @@ protected function blockMarkup($Line)
|
||||||
|
|
||||||
if (preg_match('/^<(\w*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches))
|
if (preg_match('/^<(\w*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches))
|
||||||
{
|
{
|
||||||
if (in_array($matches[1], $this->textLevelElements))
|
$element = strtolower($matches[1]);
|
||||||
|
|
||||||
|
if (in_array($element, $this->textLevelElements))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -987,15 +991,13 @@ public function line($text)
|
||||||
{
|
{
|
||||||
$markup = '';
|
$markup = '';
|
||||||
|
|
||||||
$unexaminedText = $text;
|
# $excerpt is based on the first occurrence of a marker
|
||||||
|
|
||||||
$markerPosition = 0;
|
while ($excerpt = strpbrk($text, $this->inlineMarkerList))
|
||||||
|
|
||||||
while ($excerpt = strpbrk($unexaminedText, $this->inlineMarkerList))
|
|
||||||
{
|
{
|
||||||
$marker = $excerpt[0];
|
$marker = $excerpt[0];
|
||||||
|
|
||||||
$markerPosition += strpos($unexaminedText, $marker);
|
$markerPosition = strpos($text, $marker);
|
||||||
|
|
||||||
$Excerpt = array('text' => $excerpt, 'context' => $text);
|
$Excerpt = array('text' => $excerpt, 'context' => $text);
|
||||||
|
|
||||||
|
@ -1008,34 +1010,42 @@ public function line($text)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($Inline['position']) and $Inline['position'] > $markerPosition) # position is ahead of marker
|
# makes sure that the inline belongs to "our" marker
|
||||||
|
|
||||||
|
if (isset($Inline['position']) and $Inline['position'] > $markerPosition)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# sets a default inline position
|
||||||
|
|
||||||
if ( ! isset($Inline['position']))
|
if ( ! isset($Inline['position']))
|
||||||
{
|
{
|
||||||
$Inline['position'] = $markerPosition;
|
$Inline['position'] = $markerPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# the text that comes before the inline
|
||||||
$unmarkedText = substr($text, 0, $Inline['position']);
|
$unmarkedText = substr($text, 0, $Inline['position']);
|
||||||
|
|
||||||
|
# compile the unmarked text
|
||||||
$markup .= $this->unmarkedText($unmarkedText);
|
$markup .= $this->unmarkedText($unmarkedText);
|
||||||
|
|
||||||
|
# compile the inline
|
||||||
$markup .= isset($Inline['markup']) ? $Inline['markup'] : $this->element($Inline['element']);
|
$markup .= isset($Inline['markup']) ? $Inline['markup'] : $this->element($Inline['element']);
|
||||||
|
|
||||||
|
# remove the examined text
|
||||||
$text = substr($text, $Inline['position'] + $Inline['extent']);
|
$text = substr($text, $Inline['position'] + $Inline['extent']);
|
||||||
|
|
||||||
$unexaminedText = $text;
|
|
||||||
|
|
||||||
$markerPosition = 0;
|
|
||||||
|
|
||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
$unexaminedText = substr($excerpt, 1);
|
# the marker does not belong to an inline
|
||||||
|
|
||||||
$markerPosition ++;
|
$unmarkedText = substr($text, 0, $markerPosition + 1);
|
||||||
|
|
||||||
|
$markup .= $this->unmarkedText($unmarkedText);
|
||||||
|
|
||||||
|
$text = substr($text, $markerPosition + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$markup .= $this->unmarkedText($text);
|
$markup .= $this->unmarkedText($text);
|
||||||
|
@ -1476,7 +1486,7 @@ static function instance($name = 'default')
|
||||||
return self::$instances[$name];
|
return self::$instances[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
$instance = new self();
|
$instance = new static();
|
||||||
|
|
||||||
self::$instances[$name] = $instance;
|
self::$instances[$name] = $instance;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue