mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
85ad014f74 | |||
22336a1bcc | |||
f713e380ee | |||
5b01915a63 | |||
18d112a614 | |||
1b9641ad03 |
@ -221,6 +221,8 @@ class Parsedown
|
|||||||
|
|
||||||
$element['lines'] []= $line;
|
$element['lines'] []= $line;
|
||||||
|
|
||||||
|
unset($element['interrupted']);
|
||||||
|
|
||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -627,38 +629,7 @@ class Parsedown
|
|||||||
|
|
||||||
$index = 0;
|
$index = 0;
|
||||||
|
|
||||||
# code span
|
# inline link or image (recursive)
|
||||||
|
|
||||||
if (strpos($text, '`') !== FALSE and preg_match_all('/`(.+?)`/', $text, $matches, PREG_SET_ORDER))
|
|
||||||
{
|
|
||||||
foreach ($matches as $matches)
|
|
||||||
{
|
|
||||||
$element_text = $matches[1];
|
|
||||||
$element_text = htmlspecialchars($element_text, ENT_NOQUOTES, 'UTF-8');
|
|
||||||
|
|
||||||
# decodes escape sequences
|
|
||||||
|
|
||||||
$this->escape_sequence_map
|
|
||||||
and strpos($element_text, "\x1A") !== FALSE
|
|
||||||
and $element_text = strtr($element_text, $this->escape_sequence_map);
|
|
||||||
|
|
||||||
# composes element
|
|
||||||
|
|
||||||
$element = '<code>'.$element_text.'</code>';
|
|
||||||
|
|
||||||
# encodes element
|
|
||||||
|
|
||||||
$code = "\x1A".'$'.$index;
|
|
||||||
|
|
||||||
$text = str_replace($matches[0], $code, $text);
|
|
||||||
|
|
||||||
$map[$code] = $element;
|
|
||||||
|
|
||||||
$index ++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# inline link or 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
|
||||||
{
|
{
|
||||||
@ -691,7 +662,7 @@ class Parsedown
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# reference link or image
|
# reference link or image (recursive)
|
||||||
|
|
||||||
if ($this->reference_map and strpos($text, '[') !== FALSE and preg_match_all('/(!?)\[(.+?)\](?:\n?[ ]?\[(.*?)\])?/ms', $text, $matches, PREG_SET_ORDER))
|
if ($this->reference_map and strpos($text, '[') !== FALSE and preg_match_all('/(!?)\[(.+?)\](?:\n?[ ]?\[(.*?)\])?/ms', $text, $matches, PREG_SET_ORDER))
|
||||||
{
|
{
|
||||||
@ -733,6 +704,39 @@ class Parsedown
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# code span
|
||||||
|
|
||||||
|
if (strpos($text, '`') !== FALSE and preg_match_all('/`(.+?)`/', $text, $matches, PREG_SET_ORDER))
|
||||||
|
{
|
||||||
|
foreach ($matches as $matches)
|
||||||
|
{
|
||||||
|
$element_text = $matches[1];
|
||||||
|
$element_text = htmlspecialchars($element_text, ENT_NOQUOTES, 'UTF-8');
|
||||||
|
|
||||||
|
# decodes escape sequences
|
||||||
|
|
||||||
|
$this->escape_sequence_map
|
||||||
|
and strpos($element_text, "\x1A") !== FALSE
|
||||||
|
and $element_text = strtr($element_text, $this->escape_sequence_map);
|
||||||
|
|
||||||
|
# composes element
|
||||||
|
|
||||||
|
$element = '<code>'.$element_text.'</code>';
|
||||||
|
|
||||||
|
# encodes element
|
||||||
|
|
||||||
|
$code = "\x1A".'$'.$index;
|
||||||
|
|
||||||
|
$text = str_replace($matches[0], $code, $text);
|
||||||
|
|
||||||
|
$map[$code] = $element;
|
||||||
|
|
||||||
|
$index ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# automatic link
|
||||||
|
|
||||||
if (strpos($text, '://') !== FALSE)
|
if (strpos($text, '://') !== FALSE)
|
||||||
{
|
{
|
||||||
switch (TRUE)
|
switch (TRUE)
|
||||||
|
13
README.md
13
README.md
@ -1,19 +1,19 @@
|
|||||||
## Parsedown
|
## Parsedown
|
||||||
|
|
||||||
Better [Markdown][1] parser for PHP.
|
Better [Markdown](http://daringfireball.net/projects/markdown/) parser for PHP.
|
||||||
|
|
||||||
***
|
***
|
||||||
|
|
||||||
[home](http://parsedown.org/) · [demo](http://parsedown.org/demo) · [tests](http://parsedown.org/tests/)
|
[demo](http://parsedown.org/demo) · [tests](http://parsedown.org/tests/)
|
||||||
|
|
||||||
***
|
***
|
||||||
|
|
||||||
Features:
|
### Features
|
||||||
|
|
||||||
* [fast](http://parsedown.org/speed)
|
* [fast](http://parsedown.org/speed)
|
||||||
* [consistent](http://parsedown.org/consistency)
|
* [consistent](http://parsedown.org/consistency)
|
||||||
* [ GitHub Flavored ][2]
|
* [GitHub Flavored](https://help.github.com/articles/github-flavored-markdown)
|
||||||
* tested in PHP 5.2, 5.3, 5.4 and 5.5
|
* [tested](https://travis-ci.org/erusev/parsedown) in PHP 5.2, 5.3, 5.4 and 5.5
|
||||||
* friendly to international input
|
* friendly to international input
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
@ -29,6 +29,3 @@ $result = Parsedown::instance()->parse($text);
|
|||||||
|
|
||||||
echo $result; # prints: <p>Hello <strong>Parsedown</strong>!</p>
|
echo $result; # prints: <p>Hello <strong>Parsedown</strong>!</p>
|
||||||
```
|
```
|
||||||
|
|
||||||
[1]: http://daringfireball.net/projects/markdown/
|
|
||||||
[2]: https://help.github.com/articles/github-flavored-markdown
|
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
<p><a href="http://example.com">link</a></p>
|
<p><a href="http://example.com">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"></a></p>
|
@ -1,3 +1,5 @@
|
|||||||
[link](http://example.com)
|
[link](http://example.com)
|
||||||
|
|
||||||
|
[`link`](http://example.com)
|
||||||
|
|
||||||
[](http://example.com)
|
[](http://example.com)
|
7
tests/data/multiline_list_paragraph.html
Normal file
7
tests/data/multiline_list_paragraph.html
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<p>li</p>
|
||||||
|
<p>line
|
||||||
|
line</p>
|
||||||
|
</li>
|
||||||
|
</ul>
|
4
tests/data/multiline_list_paragraph.md
Normal file
4
tests/data/multiline_list_paragraph.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
- li
|
||||||
|
|
||||||
|
line
|
||||||
|
line
|
@ -1,5 +1,4 @@
|
|||||||
<p>AT&T has an ampersand in their name</p>
|
<p>AT&T has an ampersand in their name</p>
|
||||||
<pre><code>Let's play some cards ♠ ♣ ♥ ♦</code></pre>
|
|
||||||
<p>AT&T is another way to write it</p>
|
<p>AT&T is another way to write it</p>
|
||||||
<p>this & that</p>
|
<p>this & that</p>
|
||||||
<p>4 < 5 and 6 > 5</p>
|
<p>4 < 5 and 6 > 5</p>
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
AT&T has an ampersand in their name
|
AT&T has an ampersand in their name
|
||||||
|
|
||||||
Let's play some cards ♠ ♣ ♥ ♦
|
|
||||||
|
|
||||||
AT&T is another way to write it
|
AT&T is another way to write it
|
||||||
|
|
||||||
this & that
|
this & that
|
||||||
|
@ -4,3 +4,4 @@
|
|||||||
<p><a href="http://example.com">multiline
|
<p><a href="http://example.com">multiline
|
||||||
one</a> defined on 2 lines</p>
|
one</a> defined on 2 lines</p>
|
||||||
<p><a href="http://example.com">one</a> with an upper case label</p>
|
<p><a href="http://example.com">one</a> with an upper case label</p>
|
||||||
|
<p><a href="http://example.com"><code>link</code></a></p>
|
@ -14,3 +14,5 @@ one][website] defined on 2 lines
|
|||||||
[one][label] with an upper case label
|
[one][label] with an upper case label
|
||||||
|
|
||||||
[LABEL]: http://example.com
|
[LABEL]: http://example.com
|
||||||
|
|
||||||
|
[`link`][website]
|
Reference in New Issue
Block a user