mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Implement unmarked text via AST
This commit is contained in:
parent
65d7bc5013
commit
adcba80502
|
@ -1070,6 +1070,41 @@ class Parsedown
|
|||
# ~
|
||||
#
|
||||
|
||||
protected function inlineText($text)
|
||||
{
|
||||
$Inline = array(
|
||||
'extent' => strlen($text),
|
||||
'element' => array(
|
||||
'handler' => 'elements',
|
||||
),
|
||||
);
|
||||
|
||||
if ($this->breaksEnabled)
|
||||
{
|
||||
$Inline['element']['text'] = self::pregReplaceElements(
|
||||
'/[ ]*\n/',
|
||||
array(
|
||||
array('name' => 'br'),
|
||||
array('text' => "\n"),
|
||||
),
|
||||
$text
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$Inline['element']['text'] = self::pregReplaceElements(
|
||||
'/(?:[ ][ ]+|[ ]*\\\\)\n/',
|
||||
array(
|
||||
array('name' => 'br'),
|
||||
array('text' => "\n"),
|
||||
),
|
||||
$text
|
||||
);
|
||||
}
|
||||
|
||||
return $Inline;
|
||||
}
|
||||
|
||||
protected function inlineCode($Excerpt)
|
||||
{
|
||||
$marker = $Excerpt['text'][0];
|
||||
|
@ -1391,17 +1426,7 @@ class Parsedown
|
|||
|
||||
protected function unmarkedText($text)
|
||||
{
|
||||
if ($this->breaksEnabled)
|
||||
{
|
||||
$text = preg_replace('/[ ]*\n/', "<br />\n", $text);
|
||||
}
|
||||
else
|
||||
{
|
||||
$text = preg_replace('/(?:[ ][ ]+|[ ]*\\\\)\n/', "<br />\n", $text);
|
||||
$text = str_replace(" \n", "\n", $text);
|
||||
}
|
||||
|
||||
return $text;
|
||||
return $this->element($this->inlineText($text)['element']);
|
||||
}
|
||||
|
||||
#
|
||||
|
@ -1526,6 +1551,39 @@ class Parsedown
|
|||
return $markup;
|
||||
}
|
||||
|
||||
#
|
||||
# AST Convenience
|
||||
#
|
||||
|
||||
/**
|
||||
* Replace occurrences $regexp with $Elements in $text. Return an array of
|
||||
* elements representing the replacement.
|
||||
*/
|
||||
protected static function pregReplaceElements($regexp, $Elements, $text)
|
||||
{
|
||||
$newElements = array();
|
||||
|
||||
while (preg_match($regexp, $text, $matches, PREG_OFFSET_CAPTURE))
|
||||
{
|
||||
$offset = $matches[0][1];
|
||||
$before = substr($text, 0, $offset);
|
||||
$after = substr($text, $offset + strlen($matches[0][0]));
|
||||
|
||||
$newElements[] = array('text' => $before);
|
||||
|
||||
foreach ($Elements as $Element)
|
||||
{
|
||||
$newElements[] = $Element;
|
||||
}
|
||||
|
||||
$text = $after;
|
||||
}
|
||||
|
||||
$newElements[] = array('text' => $text);
|
||||
|
||||
return $newElements;
|
||||
}
|
||||
|
||||
#
|
||||
# Deprecated Methods
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue
Block a user