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
495e7ac73b
commit
7ab3c60a77
@ -972,6 +972,7 @@ class Parsedown
|
|||||||
'*' => array('Emphasis'),
|
'*' => array('Emphasis'),
|
||||||
'/' => array('Url'),
|
'/' => array('Url'),
|
||||||
'<' => array('UrlTag', 'EmailTag', 'Tag', 'LessThan'),
|
'<' => array('UrlTag', 'EmailTag', 'Tag', 'LessThan'),
|
||||||
|
'>' => array('GreaterThan'),
|
||||||
'[' => array('Link'),
|
'[' => array('Link'),
|
||||||
'_' => array('Emphasis'),
|
'_' => array('Emphasis'),
|
||||||
'`' => array('InlineCode'),
|
'`' => array('InlineCode'),
|
||||||
@ -981,7 +982,7 @@ class Parsedown
|
|||||||
|
|
||||||
# ~
|
# ~
|
||||||
|
|
||||||
protected $spanMarkerList = '*_!&[</`~\\';
|
protected $spanMarkerList = '*_!&[<>/`~\\';
|
||||||
|
|
||||||
#
|
#
|
||||||
# ~
|
# ~
|
||||||
@ -1132,6 +1133,14 @@ class Parsedown
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function identifyGreaterThan()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'markup' => '>',
|
||||||
|
'extent' => 1,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected function identifyUrlTag($Excerpt)
|
protected function identifyUrlTag($Excerpt)
|
||||||
{
|
{
|
||||||
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(https?:[\/]{2}[^\s]+?)>/i', $Excerpt['text'], $matches))
|
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(https?:[\/]{2}[^\s]+?)>/i', $Excerpt['text'], $matches))
|
||||||
@ -1175,7 +1184,7 @@ class Parsedown
|
|||||||
return;
|
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(
|
return array(
|
||||||
'markup' => $matches[0],
|
'markup' => $matches[0],
|
||||||
@ -1188,10 +1197,11 @@ class Parsedown
|
|||||||
{
|
{
|
||||||
$marker = $Excerpt['text'][0];
|
$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 = $matches[2];
|
||||||
$text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
|
$text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
|
||||||
|
$text = preg_replace("/[ ]*\n/", ' ', $text);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'extent' => strlen($matches[0]),
|
'extent' => strlen($matches[0]),
|
||||||
@ -1267,8 +1277,8 @@ class Parsedown
|
|||||||
$Element = array(
|
$Element = array(
|
||||||
'name' => 'img',
|
'name' => 'img',
|
||||||
'attributes' => array(
|
'attributes' => array(
|
||||||
'alt' => $Link['text'],
|
|
||||||
'src' => $url,
|
'src' => $url,
|
||||||
|
'alt' => $Link['text'],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1332,9 +1342,10 @@ class Parsedown
|
|||||||
|
|
||||||
protected function readPlainText($text)
|
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($breakMarker, "<br />\n", $text);
|
||||||
|
$text = str_replace(" \n", "\n", $text);
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
<p><img alt="Markdown Logo" src="/md.png" /></p>
|
<p><img src="/md.png" alt="Markdown Logo" /></p>
|
@ -1 +1 @@
|
|||||||
<p><img alt="alt" src="/md.png" title="title" /></p>
|
<p><img src="/md.png" alt="alt" title="title" /></p>
|
@ -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">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"><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 src="http://parsedown.org/md.png" alt="MD Logo" /></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" /> and text</a></p>
|
@ -1,6 +1,6 @@
|
|||||||
<p>AT&T has an ampersand in their name</p>
|
<p>AT&T has an ampersand in their name</p>
|
||||||
<p>this & that</p>
|
<p>this & that</p>
|
||||||
<p>4 < 5 and 6 > 5</p>
|
<p>4 < 5 and 6 > 5</p>
|
||||||
<p><a href="http://example.com/autolink?a=1&b=2">http://example.com/autolink?a=1&b=2</a></p>
|
<p><a href="http://example.com/autolink?a=1&b=2">http://example.com/autolink?a=1&b=2</a></p>
|
||||||
<p><a href="/script?a=1&b=2">inline link</a></p>
|
<p><a href="/script?a=1&b=2">inline link</a></p>
|
||||||
<p><a href="http://example.com/?a=1&b=2">reference link</a></p>
|
<p><a href="http://example.com/?a=1&b=2">reference link</a></p>
|
Loading…
Reference in New Issue
Block a user