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

Compare commits

...

6 Commits
0.4.1 ... 0.4.4

7 changed files with 46 additions and 41 deletions

View File

@ -78,7 +78,7 @@ class Parsedown
# ~
$text = preg_replace('/\n\s*\n/', "\n\n", $text);
$text = trim($text, "\n");
$text = trim($text, "\n ");
$lines = explode("\n", $text);
@ -205,7 +205,7 @@ class Parsedown
# Quick Paragraph
if ($line[0] >= 'A' and $line[0] !== '_' and $line[0] !== '[')
if ($line[0] >= 'a' or $line[0] >= 'A' and $line[0] <= 'Z')
{
goto paragraph; # trust me
}
@ -216,7 +216,12 @@ class Parsedown
{
if ($element['type'] === 'code')
{
isset($element['interrupted']) and $element['text'] .= "\n";
if (isset($element['interrupted']))
{
$element['text'] .= "\n";
unset ($element['interrupted']);
}
$element['text'] .= "\n".$matches[1];
}
@ -272,7 +277,7 @@ class Parsedown
# ~
$pure_line = ltrim($line);
$pure_line = $line[0] !== ' ' ? $line : ltrim($line);
# Link Reference
@ -555,11 +560,13 @@ class Parsedown
# Inline Link / Image
if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)(\[((?:[^][]+|(?2))*)\])\((.*?)\)/', $text, $matches, PREG_SET_ORDER)) # inline
if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)(\[((?:[^\[\]]|(?2))*)\])\((.*?)\)/', $text, $matches, PREG_SET_ORDER)) # inline
{
foreach ($matches as $matches)
{
$url = $this->escape_special_characters($matches[4]);
$url = $matches[4];
strpos($url, '&') !== FALSE and $url = preg_replace('/&(?!#?\w+;)/', '&amp;', $url);
if ($matches[1]) # image
{
@ -599,7 +606,8 @@ class Parsedown
if (isset($this->reference_map[$link_definition]))
{
$url = $this->reference_map[$link_definition];
$url = $this->escape_special_characters($url);
strpos($url, '&') !== FALSE and $url = preg_replace('/&(?!#?\w+;)/', '&amp;', $url);
if ($matches[1]) # image
{
@ -631,7 +639,9 @@ class Parsedown
{
foreach ($matches as $matches)
{
$url = $this->escape_special_characters($matches[1]);
$url = $matches[1];
strpos($url, '&') !== FALSE and $url = preg_replace('/&(?!#?\w+;)/', '&amp;', $url);
$element = '<a href=":href">:text</a>';
$element = str_replace(':text', $url, $element);
@ -651,8 +661,9 @@ class Parsedown
# ~
$text = $this->escape_special_characters($text);
strpos($text, '&') !== FALSE and $text = preg_replace('/&(?!#?\w+;)/', '&amp;', $text);
strpos($text, '<') !== FALSE and $text = preg_replace('/<(?!\/?\w.*?>)/', '&lt;', $text);
# ~
if (strpos($text, '_') !== FALSE)
@ -671,13 +682,4 @@ class Parsedown
return $text;
}
private function escape_special_characters($text)
{
strpos($text, '&') !== FALSE and $text = preg_replace('/&(?!#?\w+;)/', '&amp;', $text);
$text = str_replace('<', '&lt;', $text);
return $text;
}
}

View File

@ -1,9 +1,8 @@
<p>Here's a regular code block:</p>
<pre><code>&lt;?php
echo 'Hello World!';
?&gt;</code></pre>
<p>Here's one that holds a list:</p>
<pre><code>- list item
<p>Here's a code block:</p>
<pre><code>&lt;?php
$message = 'Hello World!';
echo $message;</code></pre>
<p>Here's one that holds a list:</p>
<pre><code>- list item
- another list item</code></pre>

View File

@ -1,13 +1,12 @@
Here's a regular code block:
<?php
echo 'Hello World!';
?>
Here's one that holds a list:
- list item
- another list item
Here's a code block:
<?php
$message = 'Hello World!';
echo $message;
Here's one that holds a list:
- list item
- another list item

View File

@ -0,0 +1 @@
<p>Here's an <b>important</b> <a href=''>link</a>.</p>

View File

@ -0,0 +1 @@
Here's an <b>important</b> <a href=''>link</a>.

View File

@ -4,5 +4,6 @@
<p>4 &lt; 5 and 6 > 5.</p>
<p>Here's a <a href="http://example.com/?foo=1&amp;bar=2">link</a> with an ampersand in the URL.</p>
<p>Here's an inline <a href="/script?foo=1&amp;bar=2">link</a>.</p>
<p><a href="http://example.com/autolink?a=1&amp;b=2">http://example.com/autolink?a=1&amp;b=2</a></p>
<hr />
<p>Based on <a href="http://daringfireball.net/projects/downloads/MarkdownTest_1.0.zip">the original</a> test suite.</p>

View File

@ -1,6 +1,6 @@
AT&T has an ampersand in their name.
AT&amp;T is another way to write it.
AT&T is another way to write it.
This & that.
@ -12,6 +12,8 @@ Here's an inline [link](/script?foo=1&bar=2).
[1]: http://example.com/?foo=1&bar=2
<http://example.com/autolink?a=1&b=2>
---
Based on [the original](http://daringfireball.net/projects/downloads/MarkdownTest_1.0.zip) test suite.