improve CommonMark compliance

This commit is contained in:
Emanuil Rusev 2014-12-02 22:23:43 +02:00
parent 495e7ac73b
commit 7ab3c60a77
5 changed files with 21 additions and 10 deletions

View File

@ -972,6 +972,7 @@ class Parsedown
'*' => array('Emphasis'),
'/' => array('Url'),
'<' => array('UrlTag', 'EmailTag', 'Tag', 'LessThan'),
'>' => array('GreaterThan'),
'[' => array('Link'),
'_' => array('Emphasis'),
'`' => array('InlineCode'),
@ -981,7 +982,7 @@ class Parsedown
# ~
protected $spanMarkerList = '*_!&[</`~\\';
protected $spanMarkerList = '*_!&[<>/`~\\';
#
# ~
@ -1132,6 +1133,14 @@ class Parsedown
);
}
protected function identifyGreaterThan()
{
return array(
'markup' => '&gt;',
'extent' => 1,
);
}
protected function identifyUrlTag($Excerpt)
{
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(https?:[\/]{2}[^\s]+?)>/i', $Excerpt['text'], $matches))
@ -1175,7 +1184,7 @@ class Parsedown
return;
}
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<\/?\w.*?>/', $Excerpt['text'], $matches))
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<\/?\w.*?>/s', $Excerpt['text'], $matches))
{
return array(
'markup' => $matches[0],
@ -1188,10 +1197,11 @@ class Parsedown
{
$marker = $Excerpt['text'][0];
if (preg_match('/^('.$marker.'+)[ ]*(.+?)[ ]*(?<!'.$marker.')\1(?!'.$marker.')/', $Excerpt['text'], $matches))
if (preg_match('/^('.$marker.'+)[ ]*(.+?)[ ]*(?<!'.$marker.')\1(?!'.$marker.')/s', $Excerpt['text'], $matches))
{
$text = $matches[2];
$text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
$text = preg_replace("/[ ]*\n/", ' ', $text);
return array(
'extent' => strlen($matches[0]),
@ -1267,8 +1277,8 @@ class Parsedown
$Element = array(
'name' => 'img',
'attributes' => array(
'alt' => $Link['text'],
'src' => $url,
'alt' => $Link['text'],
),
);
}
@ -1332,9 +1342,10 @@ class Parsedown
protected function readPlainText($text)
{
$breakMarker = $this->breaksEnabled ? "\n" : " \n";
$breakMarker = $this->breaksEnabled ? "\n" : array(" \n", "\\\n");
$text = str_replace($breakMarker, "<br />\n", $text);
$text = str_replace(" \n", "\n", $text);
return $text;
}

View File

@ -1 +1 @@
<p><img alt="Markdown Logo" src="/md.png" /></p>
<p><img src="/md.png" alt="Markdown Logo" /></p>

View File

@ -1 +1 @@
<p><img alt="alt" src="/md.png" title="title" /></p>
<p><img src="/md.png" alt="alt" title="title" /></p>

View File

@ -1,4 +1,4 @@
<p><a href="http://example.com">link</a> and <a href="/tests/">another link</a></p>
<p><a href="http://example.com"><code>link</code></a></p>
<p><a href="http://example.com"><img alt="MD Logo" src="http://parsedown.org/md.png" /></a></p>
<p><a href="http://example.com"><img alt="MD Logo" src="http://parsedown.org/md.png" /> and text</a></p>
<p><a href="http://example.com"><img src="http://parsedown.org/md.png" alt="MD Logo" /></a></p>
<p><a href="http://example.com"><img src="http://parsedown.org/md.png" alt="MD Logo" /> and text</a></p>

View File

@ -1,6 +1,6 @@
<p>AT&amp;T has an ampersand in their name</p>
<p>this &amp; that</p>
<p>4 &lt; 5 and 6 > 5</p>
<p>4 &lt; 5 and 6 &gt; 5</p>
<p><a href="http://example.com/autolink?a=1&amp;b=2">http://example.com/autolink?a=1&amp;b=2</a></p>
<p><a href="/script?a=1&amp;b=2">inline link</a></p>
<p><a href="http://example.com/?a=1&amp;b=2">reference link</a></p>