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

introduce more structure to parsing of unmarked inlines

This commit is contained in:
Emanuil Rusev 2015-01-08 15:19:43 +02:00
parent b1be886d65
commit fd0d8125e7

View File

@ -1087,7 +1087,7 @@ class Parsedown
$plainText = substr($text, 0, $markerPosition); $plainText = substr($text, 0, $markerPosition);
$markup .= $this->readUnmarkedText($plainText); $markup .= $this->unmarkedText($plainText);
$markup .= isset($Inline['markup']) ? $Inline['markup'] : $this->element($Inline['element']); $markup .= isset($Inline['markup']) ? $Inline['markup'] : $this->element($Inline['element']);
@ -1105,7 +1105,7 @@ class Parsedown
$markerPosition ++; $markerPosition ++;
} }
$markup .= $this->readUnmarkedText($text); $markup .= $this->unmarkedText($text);
return $markup; return $markup;
} }
@ -1397,17 +1397,28 @@ class Parsedown
# #
# ~ # ~
protected function readUnmarkedText($text) protected $unmarkedInlineTypes = array(
" \n" => 'Break',
'://' => 'Url',
);
# ~
protected function unmarkedText($text)
{ {
$text = $this->linkUrls($text); foreach ($this->unmarkedInlineTypes as $snippet => $inlineType)
# ~
if (strpos($text, "\n") === false)
{ {
return $text; if (strpos($text, $snippet) !== false)
{
$text = $this->{'unmarkedInline'.$inlineType}($text);
}
} }
return $text;
}
protected function unmarkedInlineBreak($text)
{
if ($this->breaksEnabled) if ($this->breaksEnabled)
{ {
$text = preg_replace('/[ ]*\n/', "<br />\n", $text); $text = preg_replace('/[ ]*\n/', "<br />\n", $text);
@ -1421,9 +1432,7 @@ class Parsedown
return $text; return $text;
} }
# ~ protected function unmarkedInlineUrl($text)
protected function linkUrls($text)
{ {
$re = '/\bhttps?:[\/]{2}[^\s<]+\b\/*/ui'; $re = '/\bhttps?:[\/]{2}[^\s<]+\b\/*/ui';