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

Compare commits

..

12 Commits
0.6.0 ... 0.7.3

Author SHA1 Message Date
7bb70186c1 simplify test for em strong 2013-11-23 13:35:15 +02:00
3225c66863 ***strong em** inside of em* should produce valid markup 2013-11-23 13:19:06 +02:00
d6dc5ba25b update introduction text to match website 2013-11-23 09:26:44 +02:00
f5451a9eff Merge pull request #37 from hkdobrev/htmlspecialshars-utf8 2013-11-22 13:23:21 -08:00
849a89b121 Use UTF-8 encoding for htmlspecialchars. See #36.
Prior to PHP 5.4.0 the default encoding for `htmlentities()`
and `htmlspecialchars` is "ISO-8859-1". For PHP 5.4+ is "UTF-8".

This ensures always the right encoding is used no matter the PHP version
and the locale settings.
2013-11-22 23:06:20 +02:00
28064a63b3 simplify encoding of special characters 2013-11-22 21:57:21 +02:00
800aac5b56 Merge pull request #36 from josephok/patch-1 2013-11-22 11:21:38 -08:00
b15d40e8a3 Update Parsedown.php
Changes the htmlentities() to htmlspecialchars(). The htmlentities() has some problems encoding non-english words(like Chinese)
2013-11-22 23:05:26 +08:00
ddc5b7e2dd implement URL auto-linking 2013-11-22 00:20:45 +02:00
5a563008aa implement GFM strikethrough 2013-11-21 13:39:00 +02:00
b6f795962f resolve #21 2013-11-21 00:59:30 +02:00
cdb2646063 update readme to match website 2013-11-20 23:10:03 +02:00
14 changed files with 82 additions and 34 deletions

View File

@ -568,7 +568,7 @@ class Parsedown
case 'code_block':
case 'fenced_code_block':
$text = htmlentities($element['text'], ENT_NOQUOTES);
$text = htmlspecialchars($element['text'], ENT_NOQUOTES, 'UTF-8');
strpos($text, "\x1A\\") !== FALSE and $text = strtr($text, $this->escape_sequence_map);
@ -634,7 +634,7 @@ class Parsedown
foreach ($matches as $matches)
{
$element_text = $matches[1];
$element_text = htmlentities($element_text, ENT_NOQUOTES);
$element_text = htmlspecialchars($element_text, ENT_NOQUOTES, 'UTF-8');
# decodes escape sequences
@ -733,29 +733,35 @@ class Parsedown
}
}
# automatic link
if (strpos($text, '<') !== FALSE and preg_match_all('/<((https?|ftp|dict):[^\^\s]+?)>/i', $text, $matches, PREG_SET_ORDER))
if (strpos($text, '://') !== FALSE)
{
foreach ($matches as $matches)
switch (TRUE)
{
$url = $matches[1];
case preg_match_all('{<(https?:[/]{2}[^\s]+)>}i', $text, $matches, PREG_SET_ORDER):
case preg_match_all('{\b(https?:[/]{2}[^\s]+)\b}i', $text, $matches, PREG_SET_ORDER):
strpos($url, '&') !== FALSE and $url = preg_replace('/&(?!#?\w+;)/', '&amp;', $url);
foreach ($matches as $matches)
{
$url = $matches[1];
$element = '<a href=":href">:text</a>';
$element = str_replace(':text', $url, $element);
$element = str_replace(':href', $url, $element);
strpos($url, '&') !== FALSE and $url = preg_replace('/&(?!#?\w+;)/', '&amp;', $url);
# ~
$element = '<a href=":href">:text</a>';
$element = str_replace(':text', $url, $element);
$element = str_replace(':href', $url, $element);
$code = "\x1A".'$'.$index;
# ~
$text = str_replace($matches[0], $code, $text);
$code = "\x1A".'$'.$index;
$map[$code] = $element;
$text = str_replace($matches[0], $code, $text);
$index ++;
$map[$code] = $element;
$index ++;
}
break;
}
}
@ -766,20 +772,30 @@ class Parsedown
# ~
if (strpos($text, '~~') !== FALSE)
{
$text = preg_replace('/~~(?=\S)(.+?)(?<=\S)~~/s', '<del>$1</del>', $text);
}
if (strpos($text, '_') !== FALSE)
{
$text = preg_replace('/__(?=\S)(.+?)(?<=\S)__(?!_)/s', '<strong>$1</strong>', $text);
$text = preg_replace('/_(?=\S)(.+?)(?<=\S)_/s', '<em>$1</em>', $text);
$text = preg_replace('/__(?=\S)([^_]+?)(?<=\S)__/s', '<strong>$1</strong>', $text, -1, $count);
$count or $text = preg_replace('/__(?=\S)(.+?)(?<=\S)__(?!_)/s', '<strong>$1</strong>', $text);
$text = preg_replace('/\b_(?=\S)(.+?)(?<=\S)_\b/s', '<em>$1</em>', $text);
}
if (strpos($text, '*') !== FALSE)
{
$text = preg_replace('/\*\*(?=\S)(.+?)(?<=\S)\*\*(?!\*)/s', '<strong>$1</strong>', $text);
$text = preg_replace('/\*(?=\S)(.+?)(?<=\S)\*/s', '<em>$1</em>', $text);
$text = preg_replace('/\*\*(?=\S)([^*]+?)(?<=\S)\*\*/s', '<strong>$1</strong>', $text, -1, $count);
$count or $text = preg_replace('/\*\*(?=\S)(.+?)(?<=\S)\*\*(?!\*)/s', '<strong>$1</strong>', $text);
$text = preg_replace('/\*(?=\S)([^*]+?)(?<=\S)\*/s', '<em>$1</em>', $text, -1, $count);
$count or $text = preg_replace('/\*(?=\S)(.+?)(?<=\S)\*(?!\*)/s', '<em>$1</em>', $text);
}
$text = strtr($text, $map);
return $text;
}
}
}

View File

@ -1,8 +1,8 @@
## Parsedown
Parsedown is a Markdown parser for PHP. It is fast, consistent and easy to use.
Fast and consistent [Markdown][1] parser for PHP.
[Home](http://parsedown.org) &middot; [Demo](http://parsedown.org/explorer/) &middot; [Tests](http://parsedown.org/tests/)
[Home](http://parsedown.org) &middot; [Demo](http://parsedown.org/explorer/) &middot; [Tests](http://parsedown.org/tests/)
### Installation
@ -17,3 +17,5 @@ $result = Parsedown::instance()->parse($text);
echo $result; # prints: <p>Hello <strong>Parsedown</strong>!</p>
```
[1]: http://daringfireball.net/projects/markdown/

View File

@ -1,5 +1,4 @@
<p><strong><em>em strong</em></strong></p>
<p><strong><em>one</em> at the start</strong></p>
<p><strong>one at the <em>end</em></strong></p>
<p><strong>one <em>in the</em> middle</strong></p>
<p><strong>one with <em>asterisks</em></strong></p>
<p><strong><em>em strong</em> strong</strong></p>
<p><strong>strong <em>em strong</em></strong></p>
<p><strong>strong <em>em strong</em> strong</strong></p>
<p><strong>strong <em>em strong</em></strong></p>

View File

@ -1,9 +1,7 @@
___em strong___
___em strong_ strong__
___one_ at the start__
__strong _em strong___
__one at the _end___
__strong _em strong_ strong__
__one _in the_ middle__
**one with *asterisks***
**strong *em strong***

View File

@ -2,4 +2,5 @@
<p><em>multiline
emphasis</em></p>
<p>_ this _ is not an emphasis, neither is _ this_, _this _, or _this*</p>
<p>this_is_not_an_emphasis</p>
<p>an empty emphasis __ ** is not an emphasis</p>

View File

@ -5,4 +5,6 @@ emphasis_
_ this _ is not an emphasis, neither is _ this_, _this _, or _this*
this_is_not_an_emphasis
an empty emphasis __ ** is not an emphasis

View File

@ -1,4 +1,5 @@
<p>AT&amp;T has an ampersand in their name</p>
<pre><code>Let's play some cards ♠ ♣ ♥ ♦</code></pre>
<p>AT&amp;T is another way to write it</p>
<p>this &amp; that</p>
<p>4 &lt; 5 and 6 > 5</p>

View File

@ -1,5 +1,7 @@
AT&T has an ampersand in their name
Let's play some cards ♠ ♣ ♥ ♦
AT&T is another way to write it
this & that

View File

@ -0,0 +1,3 @@
<p><del>strikethrough</del></p>
<p>in the <del>middle</del> of a sentence</p>
<p>in the middle of a w<del>or</del>d</p>

View File

@ -0,0 +1,5 @@
~~strikethrough~~
in the ~~middle~~ of a sentence
in the middle of a w~~or~~d

View File

@ -0,0 +1,6 @@
<p><em><strong>strong em</strong></em> </p>
<p><em>em <strong>strong em</strong></em></p>
<p><em><strong>strong em</strong> em</em></p>
<p><em><strong>strong em</strong></em></p>
<p><em>em <strong>strong em</strong></em></p>
<p><em><strong>strong em</strong> em</em></p>

11
tests/data/strong_em.md Normal file
View File

@ -0,0 +1,11 @@
***strong em***
*em **strong em***
***strong em** em*
___strong em___
_em __strong em___
___strong em__ em_

View File

@ -0,0 +1 @@
<p>Here's an autolink <a href="http://example.com">http://example.com</a>.</p>

View File

@ -0,0 +1 @@
Here's an autolink http://example.com.