mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
improve CommonMark compliance
This commit is contained in:
parent
4c24e68b42
commit
361febf7c6
@ -301,8 +301,13 @@ class Parsedown
|
||||
#
|
||||
# Code
|
||||
|
||||
protected function identifyCodeBlock($Line)
|
||||
protected function identifyCodeBlock($Line, $Block = null)
|
||||
{
|
||||
if (isset($Block) and ! isset($Block['type']) and ! isset($Block['interrupted']))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ($Line['indent'] >= 4)
|
||||
{
|
||||
$text = substr($Line['body'], 4);
|
||||
@ -968,6 +973,7 @@ class Parsedown
|
||||
|
||||
protected $SpanTypes = array(
|
||||
'!' => array('Link'), # ?
|
||||
'"' => array('QuotationMark'),
|
||||
'&' => array('Ampersand'),
|
||||
'*' => array('Emphasis'),
|
||||
'/' => array('Url'),
|
||||
@ -982,7 +988,7 @@ class Parsedown
|
||||
|
||||
# ~
|
||||
|
||||
protected $spanMarkerList = '*_!&[<>/`~\\';
|
||||
protected $spanMarkerList = '!"*_&[<>/`~\\';
|
||||
|
||||
#
|
||||
# ~
|
||||
@ -1141,6 +1147,14 @@ class Parsedown
|
||||
);
|
||||
}
|
||||
|
||||
protected function identifyQuotationMark()
|
||||
{
|
||||
return array(
|
||||
'markup' => '"',
|
||||
'extent' => 1,
|
||||
);
|
||||
}
|
||||
|
||||
protected function identifyUrlTag($Excerpt)
|
||||
{
|
||||
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(https?:[\/]{2}[^\s]+?)>/i', $Excerpt['text'], $matches))
|
||||
@ -1162,15 +1176,22 @@ class Parsedown
|
||||
|
||||
protected function identifyEmailTag($Excerpt)
|
||||
{
|
||||
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(\S+?@\S+?)>/', $Excerpt['text'], $matches))
|
||||
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<((mailto:)?\S+?@\S+?)>/i', $Excerpt['text'], $matches))
|
||||
{
|
||||
$url = $matches[1];
|
||||
|
||||
if ( ! isset($matches[2]))
|
||||
{
|
||||
$url = 'mailto:' . $url;
|
||||
}
|
||||
|
||||
return array(
|
||||
'extent' => strlen($matches[0]),
|
||||
'element' => array(
|
||||
'name' => 'a',
|
||||
'text' => $matches[1],
|
||||
'attributes' => array(
|
||||
'href' => 'mailto:'.$matches[1],
|
||||
'href' => $url,
|
||||
),
|
||||
),
|
||||
);
|
||||
@ -1342,10 +1363,20 @@ class Parsedown
|
||||
|
||||
protected function readPlainText($text)
|
||||
{
|
||||
$breakMarker = $this->breaksEnabled ? "\n" : array(" \n", "\\\n");
|
||||
if (strpos($text, "\n") === false)
|
||||
{
|
||||
return $text;
|
||||
}
|
||||
|
||||
$text = str_replace($breakMarker, "<br />\n", $text);
|
||||
$text = str_replace(" \n", "\n", $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;
|
||||
}
|
||||
|
@ -124,11 +124,11 @@ MARKDOWN_WITH_MARKUP;
|
||||
</div>
|
||||
</div></p>
|
||||
<p>paragraph</p>
|
||||
<p><style type="text/css"></p>
|
||||
<pre><code>p {
|
||||
color: red;
|
||||
}</code></pre>
|
||||
<p></style></p>
|
||||
<p><style type="text/css">
|
||||
p {
|
||||
color: red;
|
||||
}
|
||||
</style></p>
|
||||
<p>comment</p>
|
||||
<p><!-- html comment --></p>
|
||||
EXPECTED_HTML;
|
||||
|
Loading…
Reference in New Issue
Block a user