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

Compare commits

..

5 Commits
0.7.6 ... 0.7.7

Author SHA1 Message Date
df6fe915c6 Merge pull request #48 from kaamaru/master
Fix HTML Bug
2013-12-18 10:36:06 -08:00
576b0ea761 Fix HTML Bug
If you add markdown after HTML on the same line, all the remaining markdown will not be parsed.

Demo:
Add "<span></span> *test*" without quotes to the top of a markdown page on it's own line and then parse.
2013-12-18 12:32:49 +00:00
0f027dc04b Merge pull request #47 from malorisdead/link-titles
Add ability to specify link titles on inline and reference links.
2013-12-15 14:56:12 -08:00
179862bd6e improve readme 2013-12-15 03:32:34 +02:00
019a4af2af Added ability to specify link titles to inline and reference links.
Fixed whitespace bug with reference link regex.
Updated tests.
2013-12-14 02:13:53 -05:00
6 changed files with 42 additions and 9 deletions

View File

@ -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:
@ -631,7 +642,7 @@ class Parsedown
# inline link / inline image (recursive)
if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)(\[((?:[^\[\]]|(?2))*)\])\((.*?)\)/', $text, $matches, PREG_SET_ORDER))
if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)(\[((?:[^\[\]]|(?2))*)\])\((.*?)(?:\s+["\'\(](.*?)["\'\)])?\)/', $text, $matches, PREG_SET_ORDER))
{
foreach ($matches as $matches)
{
@ -647,7 +658,14 @@ class Parsedown
{
$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>';
}
}
# ~
@ -688,7 +706,14 @@ class Parsedown
{
$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>';
}
}
# ~

View File

@ -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) &middot; [tests](http://parsedown.org/tests/)
[ [demo](http://parsedown.org/demo) ] [ [tests](http://parsedown.org/tests/) ]
***

View File

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

View File

@ -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"

View File

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

View File

@ -2,4 +2,6 @@
[`link`](http://example.com)
[link with title](http://example.com "Example")
[![MD Logo](http://parsedown.org/md.png)](http://example.com)