mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
df6fe915c6 | |||
576b0ea761 | |||
0f027dc04b | |||
179862bd6e | |||
019a4af2af | |||
51a08fad85 | |||
7fb08f334a |
@ -399,11 +399,16 @@ class Parsedown
|
||||
|
||||
# reference
|
||||
|
||||
if (preg_match('/^\[(.+?)\]:[ ]*([^ ]+)/', $deindented_line, $matches))
|
||||
if (preg_match('/^\[(.+?)\]:\s*([^\s]+)(?:\s+["\'\(](.+)["\'\)])?/', $deindented_line, $matches))
|
||||
{
|
||||
$label = strtolower($matches[1]);
|
||||
|
||||
$this->reference_map[$label] = trim($matches[2], '<>');;
|
||||
$this->reference_map[$label] = trim($matches[2], '<>');
|
||||
|
||||
if (isset($matches[3]))
|
||||
{
|
||||
$this->reference_map[$label.":title"] = $matches[3];
|
||||
}
|
||||
|
||||
continue 2;
|
||||
}
|
||||
@ -613,6 +618,12 @@ class Parsedown
|
||||
isset($element['last']) and $markup .= '</'.$list_type.'>'."\n";
|
||||
|
||||
break;
|
||||
|
||||
case 'markup':
|
||||
|
||||
$markup .= $this->parse_span_elements($element['text'])."\n";
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@ -629,9 +640,9 @@ class Parsedown
|
||||
|
||||
$index = 0;
|
||||
|
||||
# inline link or image (recursive)
|
||||
# inline link / inline image (recursive)
|
||||
|
||||
if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)(\[((?:[^\[\]]|(?2))*)\])\((.*?)\)/', $text, $matches, PREG_SET_ORDER)) # inline
|
||||
if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)(\[((?:[^\[\]]|(?2))*)\])\((.*?)(?:\s+["\'\(](.*?)["\'\)])?\)/', $text, $matches, PREG_SET_ORDER))
|
||||
{
|
||||
foreach ($matches as $matches)
|
||||
{
|
||||
@ -643,11 +654,18 @@ class Parsedown
|
||||
{
|
||||
$element = '<img alt="'.$matches[3].'" src="'.$url.'">';
|
||||
}
|
||||
else
|
||||
else # link
|
||||
{
|
||||
$element_text = $this->parse_span_elements($matches[3]);
|
||||
|
||||
$element = '<a href="'.$url.'">'.$element_text.'</a>';
|
||||
if (isset($matches[5]))
|
||||
{
|
||||
$element = '<a href="'.$url.'" title="'.$matches[5].'">'.$element_text.'</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$element = '<a href="'.$url.'">'.$element_text.'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
# ~
|
||||
@ -662,7 +680,7 @@ class Parsedown
|
||||
}
|
||||
}
|
||||
|
||||
# reference link or image (recursive)
|
||||
# reference link / reference image (recursive)
|
||||
|
||||
if ($this->reference_map and strpos($text, '[') !== FALSE and preg_match_all('/(!?)\[(.+?)\](?:\n?[ ]?\[(.*?)\])?/ms', $text, $matches, PREG_SET_ORDER))
|
||||
{
|
||||
@ -684,11 +702,18 @@ class Parsedown
|
||||
{
|
||||
$element = '<img alt="'.$matches[2].'" src="'.$url.'">';
|
||||
}
|
||||
else # anchor
|
||||
else # link
|
||||
{
|
||||
$element_text = $this->parse_span_elements($matches[2]);
|
||||
|
||||
$element = '<a href="'.$url.'">'.$element_text.'</a>';
|
||||
if (isset($this->reference_map[$link_definition.":title"]))
|
||||
{
|
||||
$element = '<a href="'.$url.'" title="'.$this->reference_map[$link_definition.":title"].'">'.$element_text.'</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$element = '<a href="'.$url.'">'.$element_text.'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
# ~
|
||||
@ -784,18 +809,15 @@ class Parsedown
|
||||
if (strpos($text, '_') !== FALSE)
|
||||
{
|
||||
$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', '$1<em>$2</em>$3', $text);
|
||||
$text = preg_replace('/__(?=\S)([^_]+?)(?<=\S)__/s', '<strong>$1</strong>', $text, -1, $count);
|
||||
}
|
||||
|
||||
if (strpos($text, '*') !== FALSE)
|
||||
{
|
||||
$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 = 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);
|
||||
}
|
||||
|
||||
$text = strtr($text, $map);
|
||||
|
@ -1,10 +1,10 @@
|
||||
## Parsedown
|
||||
|
||||
Better [Markdown](http://daringfireball.net/projects/markdown/) parser for PHP.
|
||||
Better [Markdown](http://en.wikipedia.org/wiki/Markdown) parser for PHP.
|
||||
|
||||
***
|
||||
|
||||
[demo](http://parsedown.org/demo) · [tests](http://parsedown.org/tests/)
|
||||
[ [demo](http://parsedown.org/demo) ] [ [tests](http://parsedown.org/tests/) ]
|
||||
|
||||
***
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
<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>
|
||||
<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>
|
@ -4,4 +4,8 @@ __strong _em strong___
|
||||
|
||||
__strong _em strong_ strong__
|
||||
|
||||
**strong *em strong***
|
||||
***em strong* strong**
|
||||
|
||||
**strong *em strong***
|
||||
|
||||
**strong *em strong* strong**
|
@ -3,4 +3,5 @@
|
||||
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>
|
||||
<p>an empty emphasis __ ** is not an emphasis</p>
|
||||
<p>*mixed *<em>double and</em> single asterisk** spans</p>
|
@ -7,4 +7,6 @@ _ this _ is not an emphasis, neither is _ this_, _this _, or _this*
|
||||
|
||||
this_is_not_an_emphasis
|
||||
|
||||
an empty emphasis __ ** is not an emphasis
|
||||
an empty emphasis __ ** is not an emphasis
|
||||
|
||||
*mixed **double and* single asterisk** spans
|
@ -1,2 +1,3 @@
|
||||
<p>an <a href="http://example.com">implicit</a> reference link</p>
|
||||
<p>an <a href="http://example.com">implicit</a> reference link with an empty link definition</p>
|
||||
<p>an <a href="http://example.com">implicit</a> reference link with an empty link definition</p>
|
||||
<p>an <a href="http://example.com" title="Example">explicit</a> reference link with a title</p>
|
@ -2,4 +2,8 @@ an [implicit] reference link
|
||||
|
||||
[implicit]: http://example.com
|
||||
|
||||
an [implicit][] reference link with an empty link definition
|
||||
an [implicit][] reference link with an empty link definition
|
||||
|
||||
an [explicit][example] reference link with a title
|
||||
|
||||
[example]: http://example.com "Example"
|
@ -1,3 +1,4 @@
|
||||
<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" title="Example">link with title</a></p>
|
||||
<p><a href="http://example.com"><img alt="MD Logo" src="http://parsedown.org/md.png"></a></p>
|
@ -2,4 +2,6 @@
|
||||
|
||||
[`link`](http://example.com)
|
||||
|
||||
[link with title](http://example.com "Example")
|
||||
|
||||
[](http://example.com)
|
Reference in New Issue
Block a user