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

Compare commits

..

8 Commits
0.8.3 ... 0.9.0

Author SHA1 Message Date
f0fbdaa6ca backtick within code span 2014-01-22 21:28:29 +02:00
e20c0a29bd nested elements should render on a new line 2014-01-22 21:28:29 +02:00
712dd23d30 simplify parsing of list 2014-01-22 21:28:29 +02:00
68f2871996 resolve #3 2014-01-22 21:28:29 +02:00
17e7e33847 name image title test 2014-01-22 21:28:29 +02:00
7cb9646d98 simplify compiling of links 2014-01-22 21:28:29 +02:00
325bdd9ff6 improve readme 2014-01-21 23:15:02 +02:00
2a0700abda resolve #61 2014-01-20 22:19:23 +02:00
6 changed files with 45 additions and 19 deletions

View File

@ -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>';

View File

@ -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
View 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
View File

@ -0,0 +1 @@
my email is <me@example.com>

View File

@ -0,0 +1 @@
<p><img alt="alt" src="/md.png" title="title" /></p>

View File

@ -0,0 +1 @@
![alt](/md.png "title")