mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
8baf537c12 | |||
05823567bc | |||
b7029ab176 | |||
102a947c7a | |||
7bb70186c1 | |||
3225c66863 | |||
d6dc5ba25b | |||
f5451a9eff | |||
849a89b121 | |||
28064a63b3 | |||
800aac5b56 | |||
b15d40e8a3 |
@ -110,7 +110,6 @@ class Parsedown
|
|||||||
|
|
||||||
foreach ($lines as $line)
|
foreach ($lines as $line)
|
||||||
{
|
{
|
||||||
#
|
|
||||||
# fenced elements
|
# fenced elements
|
||||||
|
|
||||||
switch ($element['type'])
|
switch ($element['type'])
|
||||||
@ -168,7 +167,6 @@ class Parsedown
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
|
||||||
# composite elements
|
# composite elements
|
||||||
|
|
||||||
switch ($element['type'])
|
switch ($element['type'])
|
||||||
@ -238,7 +236,6 @@ class Parsedown
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
|
||||||
# indentation sensitive types
|
# indentation sensitive types
|
||||||
|
|
||||||
$deindented_line = $line;
|
$deindented_line = $line;
|
||||||
@ -336,7 +333,6 @@ class Parsedown
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
|
||||||
# indentation insensitive types
|
# indentation insensitive types
|
||||||
|
|
||||||
switch ($deindented_line[0])
|
switch ($deindented_line[0])
|
||||||
@ -568,11 +564,15 @@ class Parsedown
|
|||||||
case 'code_block':
|
case 'code_block':
|
||||||
case 'fenced_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);
|
strpos($text, "\x1A\\") !== FALSE and $text = strtr($text, $this->escape_sequence_map);
|
||||||
|
|
||||||
$markup .= '<pre><code>'.$text.'</code></pre>'."\n";
|
$markup .= isset($element['language'])
|
||||||
|
? '<pre><code class="language-'.$element['language'].'">'.$text.'</code></pre>'
|
||||||
|
: '<pre><code>'.$text.'</code></pre>';
|
||||||
|
|
||||||
|
$markup .= "\n";
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -634,7 +634,7 @@ class Parsedown
|
|||||||
foreach ($matches as $matches)
|
foreach ($matches as $matches)
|
||||||
{
|
{
|
||||||
$element_text = $matches[1];
|
$element_text = $matches[1];
|
||||||
$element_text = htmlentities($element_text, ENT_NOQUOTES);
|
$element_text = htmlspecialchars($element_text, ENT_NOQUOTES, 'UTF-8');
|
||||||
|
|
||||||
# decodes escape sequences
|
# decodes escape sequences
|
||||||
|
|
||||||
@ -779,18 +779,23 @@ class Parsedown
|
|||||||
|
|
||||||
if (strpos($text, '_') !== FALSE)
|
if (strpos($text, '_') !== FALSE)
|
||||||
{
|
{
|
||||||
$text = preg_replace('/__(?=\S)(.+?)(?<=\S)__(?!_)/s', '<strong>$1</strong>', $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);
|
$text = preg_replace('/\b_(?=\S)(.+?)(?<=\S)_\b/s', '<em>$1</em>', $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($text, '*') !== FALSE)
|
if (strpos($text, '*') !== FALSE)
|
||||||
{
|
{
|
||||||
$text = preg_replace('/\*\*(?=\S)(.+?)(?<=\S)\*\*(?!\*)/s', '<strong>$1</strong>', $text);
|
$text = preg_replace('/\*\*(?=\S)([^*]+?)(?<=\S)\*\*/s', '<strong>$1</strong>', $text, -1, $count);
|
||||||
$text = preg_replace('/\*(?=\S)(.+?)(?<=\S)\*/s', '<em>$1</em>', $text);
|
$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);
|
$text = strtr($text, $map);
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
README.md
17
README.md
@ -1,8 +1,20 @@
|
|||||||
## Parsedown
|
## Parsedown
|
||||||
|
|
||||||
Fast, consistent and easy to use [Markdown][1] parser for PHP.
|
Better [Markdown][1] parser for PHP.
|
||||||
|
|
||||||
[Home](http://parsedown.org) · [Demo](http://parsedown.org/explorer/) · [Tests](http://parsedown.org/tests/)
|
***
|
||||||
|
|
||||||
|
[home](http://parsedown.org/) · [demo](http://parsedown.org/demo) · [tests](http://parsedown.org/tests/)
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
Features:
|
||||||
|
|
||||||
|
* [fast](http://parsedown.org/speed)
|
||||||
|
* [consistent](http://parsedown.org/consistency)
|
||||||
|
* [ GitHub Flavored ][2]
|
||||||
|
* tested in PHP 5.2, 5.3, 5.4 and 5.5
|
||||||
|
* friendly to international input
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
|
|
||||||
@ -19,3 +31,4 @@ echo $result; # prints: <p>Hello <strong>Parsedown</strong>!</p>
|
|||||||
```
|
```
|
||||||
|
|
||||||
[1]: http://daringfireball.net/projects/markdown/
|
[1]: http://daringfireball.net/projects/markdown/
|
||||||
|
[2]: https://help.github.com/articles/github-flavored-markdown
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
<p><strong><em>em strong</em></strong></p>
|
<p><strong><em>em strong</em> strong</strong></p>
|
||||||
<p><strong><em>one</em> at the start</strong></p>
|
<p><strong>strong <em>em strong</em></strong></p>
|
||||||
<p><strong>one at the <em>end</em></strong></p>
|
<p><strong>strong <em>em strong</em> strong</strong></p>
|
||||||
<p><strong>one <em>in the</em> middle</strong></p>
|
<p><strong>strong <em>em strong</em></strong></p>
|
||||||
<p><strong>one with <em>asterisks</em></strong></p>
|
|
@ -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__
|
**strong *em strong***
|
||||||
|
|
||||||
**one with *asterisks***
|
|
@ -1,4 +1,5 @@
|
|||||||
<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,5 +1,7 @@
|
|||||||
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
|
||||||
|
6
tests/data/strong_em.html
Normal file
6
tests/data/strong_em.html
Normal 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
11
tests/data/strong_em.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
***strong em***
|
||||||
|
|
||||||
|
*em **strong em***
|
||||||
|
|
||||||
|
***strong em** em*
|
||||||
|
|
||||||
|
___strong em___
|
||||||
|
|
||||||
|
_em __strong em___
|
||||||
|
|
||||||
|
___strong em__ em_
|
Reference in New Issue
Block a user