mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
f0fbdaa6ca | |||
e20c0a29bd | |||
712dd23d30 | |||
68f2871996 | |||
17e7e33847 | |||
7cb9646d98 | |||
325bdd9ff6 | |||
2a0700abda |
@ -182,13 +182,11 @@ class Parsedown
|
||||
|
||||
$elements []= $element;
|
||||
|
||||
$element = array(
|
||||
'type' => 'li',
|
||||
'indentation' => $matches[1],
|
||||
'last' => true,
|
||||
'lines' => array(
|
||||
preg_replace('/^[ ]{0,4}/', '', $matches[3]),
|
||||
),
|
||||
unset($element['first']);
|
||||
|
||||
$element['last'] = true;
|
||||
$element['lines'] = array(
|
||||
preg_replace('/^[ ]{0,4}/', '', $matches[3]),
|
||||
);
|
||||
}
|
||||
|
||||
@ -477,6 +475,7 @@ class Parsedown
|
||||
'type' => 'li',
|
||||
'ordered' => false,
|
||||
'indentation' => $matches[1],
|
||||
'first' => true,
|
||||
'last' => true,
|
||||
'lines' => array(
|
||||
preg_replace('/^[ ]{0,4}/', '', $matches[2]),
|
||||
@ -497,6 +496,7 @@ class Parsedown
|
||||
'type' => 'li',
|
||||
'ordered' => true,
|
||||
'indentation' => $matches[1],
|
||||
'first' => true,
|
||||
'last' => true,
|
||||
'lines' => array(
|
||||
preg_replace('/^[ ]{0,4}/', '', $matches[2]),
|
||||
@ -563,6 +563,11 @@ class Parsedown
|
||||
else
|
||||
{
|
||||
$markup .= $text;
|
||||
|
||||
if (isset($elements[2]))
|
||||
{
|
||||
$markup .= "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -616,11 +621,11 @@ class Parsedown
|
||||
|
||||
case 'li':
|
||||
|
||||
if (isset($element['ordered'])) # first
|
||||
if (isset($element['first']))
|
||||
{
|
||||
$list_type = $element['ordered'] ? 'ol' : 'ul';
|
||||
$type = $element['ordered'] ? 'ol' : 'ul';
|
||||
|
||||
$markup .= '<'.$list_type.'>'."\n";
|
||||
$markup .= '<'.$type.'>'."\n";
|
||||
}
|
||||
|
||||
if (isset($element['interrupted']) and ! isset($element['last']))
|
||||
@ -632,7 +637,12 @@ class Parsedown
|
||||
|
||||
$markup .= '<li>'.$text.'</li>'."\n";
|
||||
|
||||
isset($element['last']) and $markup .= '</'.$list_type.'>'."\n";
|
||||
if (isset($element['last']))
|
||||
{
|
||||
$type = $element['ordered'] ? 'ol' : 'ul';
|
||||
|
||||
$markup .= '</'.$type.'>'."\n";
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@ -785,15 +795,21 @@ class Parsedown
|
||||
|
||||
if ($element['!'])
|
||||
{
|
||||
$markup .= '<img alt="'.$element['a'].'" src="'.$element['»'].'" />';
|
||||
$markup .= '<img alt="'.$element['a'].'" src="'.$element['»'].'"';
|
||||
|
||||
isset($element['#']) and $markup .= ' title="'.$element['#'].'"';
|
||||
|
||||
$markup .= ' />';
|
||||
}
|
||||
else
|
||||
{
|
||||
$element['a'] = $this->parse_span_elements($element['a'], $markers);
|
||||
|
||||
$markup .= isset($element['#'])
|
||||
? '<a href="'.$element['»'].'" title="'.$element['#'].'">'.$element['a'].'</a>'
|
||||
: '<a href="'.$element['»'].'">'.$element['a'].'</a>';
|
||||
$markup .= '<a href="'.$element['»'].'"';
|
||||
|
||||
isset($element['#']) and $markup .= ' title="'.$element['#'].'"';
|
||||
|
||||
$markup .= '>'.$element['a'].'</a>';
|
||||
}
|
||||
|
||||
unset($element);
|
||||
@ -885,6 +901,12 @@ class Parsedown
|
||||
|
||||
$offset = strlen($matches[0]);
|
||||
}
|
||||
elseif (strpos($text, '@') > 1 and preg_match('/<(\S+?@\S+?)>/', $text, $matches))
|
||||
{
|
||||
$markup .= '<a href="mailto:'.$matches[1].'">'.$matches[1].'</a>';
|
||||
|
||||
$offset = strlen($matches[0]);
|
||||
}
|
||||
elseif (preg_match('/^<\/?\w.*?>/', $text, $matches))
|
||||
{
|
||||
$markup .= $matches[0];
|
||||
@ -926,9 +948,9 @@ class Parsedown
|
||||
|
||||
case '`':
|
||||
|
||||
if (preg_match('/^`(.+?)`/', $text, $matches))
|
||||
if (preg_match('/^(`+)(.+?)\1(?!`)/', $text, $matches))
|
||||
{
|
||||
$element_text = $matches[1];
|
||||
$element_text = $matches[2];
|
||||
$element_text = htmlspecialchars($element_text, ENT_NOQUOTES, 'UTF-8');
|
||||
|
||||
$markup .= '<code>'.$element_text.'</code>';
|
||||
|
@ -13,8 +13,8 @@ Better [Markdown](http://en.wikipedia.org/wiki/Markdown) parser for PHP.
|
||||
* [fast](http://parsedown.org/speed)
|
||||
* [consistent](http://parsedown.org/consistency)
|
||||
* [GitHub Flavored](https://help.github.com/articles/github-flavored-markdown)
|
||||
* friendly to international input
|
||||
* [tested](https://travis-ci.org/erusev/parsedown) in PHP 5.2, 5.3, 5.4, 5.5 and [hhvm](http://www.hhvm.com/)
|
||||
* friendly to international input
|
||||
|
||||
### Installation
|
||||
|
||||
@ -23,7 +23,7 @@ Include `Parsedown.php` or install [the composer package](https://packagist.org/
|
||||
### Example
|
||||
|
||||
```php
|
||||
$text = 'Hello _Parsedown_!';
|
||||
$text = 'Hello *Parsedown*!';
|
||||
|
||||
$result = Parsedown::instance()->parse($text);
|
||||
|
||||
|
1
tests/data/email.html
Normal file
1
tests/data/email.html
Normal file
@ -0,0 +1 @@
|
||||
<p>my email is <a href="mailto:me@example.com">me@example.com</a></p>
|
1
tests/data/email.md
Normal file
1
tests/data/email.md
Normal file
@ -0,0 +1 @@
|
||||
my email is <me@example.com>
|
1
tests/data/image_title.html
Normal file
1
tests/data/image_title.html
Normal file
@ -0,0 +1 @@
|
||||
<p><img alt="alt" src="/md.png" title="title" /></p>
|
1
tests/data/image_title.md
Normal file
1
tests/data/image_title.md
Normal file
@ -0,0 +1 @@
|
||||

|
Reference in New Issue
Block a user