mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
400c8f7d46 | |||
379cbf34b3 | |||
b6c8cac512 | |||
0e9202689e | |||
7249d02cff | |||
ecf86b073e | |||
b12973415f |
@ -75,22 +75,10 @@ class Parsedown
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Extracts link references.
|
|
||||||
|
|
||||||
if (preg_match_all('/^[ ]{0,3}\[(.+)\][ ]?:[ ]*\n?[ ]*(.+)$/m', $text, $matches, PREG_SET_ORDER))
|
|
||||||
{
|
|
||||||
foreach ($matches as $matches)
|
|
||||||
{
|
|
||||||
$this->reference_map[strtolower($matches[1])] = $matches[2];
|
|
||||||
|
|
||||||
$text = str_replace($matches[0], '', $text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# ~
|
# ~
|
||||||
|
|
||||||
$text = preg_replace('/\n\s*\n/', "\n\n", $text);
|
$text = preg_replace('/\n\s*\n/', "\n\n", $text);
|
||||||
$text = trim($text, "\n");
|
$text = trim($text, "\n ");
|
||||||
|
|
||||||
$lines = explode("\n", $text);
|
$lines = explode("\n", $text);
|
||||||
|
|
||||||
@ -217,7 +205,7 @@ class Parsedown
|
|||||||
|
|
||||||
# Quick Paragraph
|
# Quick Paragraph
|
||||||
|
|
||||||
if ($line[0] >= 'A' and $line[0] !== '_')
|
if ($line[0] >= 'a' or $line[0] >= 'A' and $line[0] <= 'Z')
|
||||||
{
|
{
|
||||||
goto paragraph; # trust me
|
goto paragraph; # trust me
|
||||||
}
|
}
|
||||||
@ -228,7 +216,12 @@ class Parsedown
|
|||||||
{
|
{
|
||||||
if ($element['type'] === 'code')
|
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];
|
$element['text'] .= "\n".$matches[1];
|
||||||
}
|
}
|
||||||
@ -284,7 +277,19 @@ class Parsedown
|
|||||||
|
|
||||||
# ~
|
# ~
|
||||||
|
|
||||||
$pure_line = ltrim($line);
|
$pure_line = $line[0] !== ' ' ? $line : ltrim($line);
|
||||||
|
|
||||||
|
# Link Reference
|
||||||
|
|
||||||
|
if ($pure_line[0] === '[' and preg_match('/^\[(.+?)\]:[ ]*([^ ]+)/', $pure_line, $matches))
|
||||||
|
{
|
||||||
|
$label = $matches[1];
|
||||||
|
$url = trim($matches[2], '<>');
|
||||||
|
|
||||||
|
$this->reference_map[$label] = $url;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
# Blockquote
|
# Blockquote
|
||||||
|
|
||||||
@ -555,11 +560,13 @@ class Parsedown
|
|||||||
|
|
||||||
# Inline Link / Image
|
# 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)
|
foreach ($matches as $matches)
|
||||||
{
|
{
|
||||||
$url = $this->escape_special_characters($matches[4]);
|
$url = $matches[4];
|
||||||
|
|
||||||
|
strpos($url, '&') !== FALSE and $url = preg_replace('/&(?!#?\w+;)/', '&', $url);
|
||||||
|
|
||||||
if ($matches[1]) # image
|
if ($matches[1]) # image
|
||||||
{
|
{
|
||||||
@ -599,7 +606,8 @@ class Parsedown
|
|||||||
if (isset($this->reference_map[$link_definition]))
|
if (isset($this->reference_map[$link_definition]))
|
||||||
{
|
{
|
||||||
$url = $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+;)/', '&', $url);
|
||||||
|
|
||||||
if ($matches[1]) # image
|
if ($matches[1]) # image
|
||||||
{
|
{
|
||||||
@ -631,7 +639,9 @@ class Parsedown
|
|||||||
{
|
{
|
||||||
foreach ($matches as $matches)
|
foreach ($matches as $matches)
|
||||||
{
|
{
|
||||||
$url = $this->escape_special_characters($matches[1]);
|
$url = $matches[1];
|
||||||
|
|
||||||
|
strpos($url, '&') !== FALSE and $url = preg_replace('/&(?!#?\w+;)/', '&', $url);
|
||||||
|
|
||||||
$element = '<a href=":href">:text</a>';
|
$element = '<a href=":href">:text</a>';
|
||||||
$element = str_replace(':text', $url, $element);
|
$element = str_replace(':text', $url, $element);
|
||||||
@ -651,7 +661,8 @@ class Parsedown
|
|||||||
|
|
||||||
# ~
|
# ~
|
||||||
|
|
||||||
$text = $this->escape_special_characters($text);
|
strpos($text, '&') !== FALSE and $text = preg_replace('/&(?!#?\w+;)/', '&', $text);
|
||||||
|
strpos($text, '<') !== FALSE and $text = preg_replace('/<(?!\/?\w.*?>)/', '<', $text);
|
||||||
|
|
||||||
# ~
|
# ~
|
||||||
|
|
||||||
@ -671,13 +682,4 @@ class Parsedown
|
|||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function escape_special_characters($text)
|
|
||||||
{
|
|
||||||
strpos($text, '&') !== FALSE and $text = preg_replace('/&(?!#?\w+;)/', '&', $text);
|
|
||||||
|
|
||||||
$text = str_replace('<', '<', $text);
|
|
||||||
|
|
||||||
return $text;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,9 +1,8 @@
|
|||||||
<p>Here's a regular code block:</p>
|
<p>Here's a code block:</p>
|
||||||
<pre><code><?php
|
<pre><code><?php
|
||||||
|
|
||||||
echo 'Hello World!';
|
$message = 'Hello World!';
|
||||||
|
echo $message;</code></pre>
|
||||||
?></code></pre>
|
|
||||||
<p>Here's one that holds a list:</p>
|
<p>Here's one that holds a list:</p>
|
||||||
<pre><code>- list item
|
<pre><code>- list item
|
||||||
- another list item</code></pre>
|
- another list item</code></pre>
|
@ -1,10 +1,9 @@
|
|||||||
Here's a regular code block:
|
Here's a code block:
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
echo 'Hello World!';
|
$message = 'Hello World!';
|
||||||
|
echo $message;
|
||||||
?>
|
|
||||||
|
|
||||||
Here's one that holds a list:
|
Here's one that holds a list:
|
||||||
|
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
<p>Here's a <a href="http://parsedown.org">reference link</a>.</p>
|
<p>Here's a <a href="http://parsedown.org">reference link</a>.</p>
|
||||||
<p>Here's <a href="http://parsedown.org">one</a> with an alternative syntax.</p>
|
|
||||||
<p>Here's <a href="http://parsedown.org">one</a> on the next line.</p>
|
<p>Here's <a href="http://parsedown.org">one</a> on the next line.</p>
|
||||||
<p>Here's <a href="http://parsedown.org">one</a> on 2 lines.</p>
|
|
||||||
<p>Here's <a href="http://parsedown.org/tests/">one</a> with a different URL.</p>
|
<p>Here's <a href="http://parsedown.org/tests/">one</a> with a different URL.</p>
|
||||||
<p>Here's <a href="http://parsedown.org">one</a> with a semantic name.</p>
|
<p>Here's <a href="http://parsedown.org">one</a> with a semantic name.</p>
|
||||||
<p>Here's <a href="http://parsedown.org">one</a> with definition name on the next line.</p>
|
<p>Here's <a href="http://parsedown.org">one</a> with definition name on the next line.</p>
|
||||||
<p>Here's [one][404] with no definition.</p>
|
<p>Here's [one][404] with no definition.</p>
|
||||||
<p>Here's an image: <img alt="Markdown Logo" src="/md.png"></p>
|
<p>Here's an image: <img alt="Markdown Logo" src="/md.png"></p>
|
||||||
<p>Here's an <a href="http://google.com">implicit one</a>.</p>
|
<p>Here's an <a href="http://google.com">implicit one</a>.</p>
|
||||||
<p>Here's an <a href="http://google.com">implicit one</a>.</p>
|
|
||||||
<p>Here's an <a href="http://google.com">implicit one</a> with an empty link definition.</p>
|
<p>Here's an <a href="http://google.com">implicit one</a> with an empty link definition.</p>
|
||||||
<p>Here's a <a href="http://parsedown.org">multiline
|
<p>Here's a <a href="http://parsedown.org">multiline
|
||||||
one</a> defined on 2 lines.</p>
|
one</a> defined on 2 lines.</p>
|
@ -2,21 +2,12 @@ Here's a [reference link][1].
|
|||||||
|
|
||||||
[1]: http://parsedown.org
|
[1]: http://parsedown.org
|
||||||
|
|
||||||
Here's [one] [2] with an alternative syntax.
|
Here's [one][2] on the next line.
|
||||||
|
[2]: http://parsedown.org
|
||||||
|
|
||||||
[2] :http://parsedown.org
|
Here's [one][3] with a different URL.
|
||||||
|
|
||||||
Here's [one][3] on the next line.
|
[3]: http://parsedown.org/tests/
|
||||||
[3]: http://parsedown.org
|
|
||||||
|
|
||||||
Here's [one][4] on 2 lines.
|
|
||||||
|
|
||||||
[4]:
|
|
||||||
http://parsedown.org
|
|
||||||
|
|
||||||
Here's [one][5] with a different URL.
|
|
||||||
|
|
||||||
[5]: http://parsedown.org/tests/
|
|
||||||
|
|
||||||
Here's [one][website] with a semantic name.
|
Here's [one][website] with a semantic name.
|
||||||
|
|
||||||
@ -33,8 +24,6 @@ Here's an image: ![Markdown Logo][image]
|
|||||||
|
|
||||||
Here's an [implicit one].
|
Here's an [implicit one].
|
||||||
|
|
||||||
Here's an [implicit one].
|
|
||||||
|
|
||||||
[implicit one]: http://google.com
|
[implicit one]: http://google.com
|
||||||
|
|
||||||
Here's an [implicit one][] with an empty link definition.
|
Here's an [implicit one][] with an empty link definition.
|
||||||
|
1
tests/data/span_level_html.html
Normal file
1
tests/data/span_level_html.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
<p>Here's an <b>important</b> <a href=''>link</a>.</p>
|
1
tests/data/span_level_html.md
Normal file
1
tests/data/span_level_html.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
Here's an <b>important</b> <a href=''>link</a>.
|
@ -4,5 +4,6 @@
|
|||||||
<p>4 < 5 and 6 > 5.</p>
|
<p>4 < 5 and 6 > 5.</p>
|
||||||
<p>Here's a <a href="http://example.com/?foo=1&bar=2">link</a> with an ampersand in the URL.</p>
|
<p>Here's a <a href="http://example.com/?foo=1&bar=2">link</a> with an ampersand in the URL.</p>
|
||||||
<p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
|
<p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
|
||||||
|
<p><a href="http://example.com/autolink?a=1&b=2">http://example.com/autolink?a=1&b=2</a></p>
|
||||||
<hr />
|
<hr />
|
||||||
<p>Based on <a href="http://daringfireball.net/projects/downloads/MarkdownTest_1.0.zip">the original</a> test suite.</p>
|
<p>Based on <a href="http://daringfireball.net/projects/downloads/MarkdownTest_1.0.zip">the original</a> test suite.</p>
|
@ -1,6 +1,6 @@
|
|||||||
AT&T has an ampersand in their name.
|
AT&T has an ampersand in their name.
|
||||||
|
|
||||||
AT&T is another way to write it.
|
AT&T is another way to write it.
|
||||||
|
|
||||||
This & that.
|
This & that.
|
||||||
|
|
||||||
@ -12,6 +12,8 @@ Here's an inline [link](/script?foo=1&bar=2).
|
|||||||
|
|
||||||
[1]: http://example.com/?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.
|
Based on [the original](http://daringfireball.net/projects/downloads/MarkdownTest_1.0.zip) test suite.
|
Reference in New Issue
Block a user