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

Compare commits

...

7 Commits
0.5.0 ... 0.7.0

10 changed files with 70 additions and 51 deletions

View File

@ -5,7 +5,3 @@ php:
- 5.4 - 5.4
- 5.3 - 5.3
- 5.2 - 5.2
matrix:
allow_failures:
- php: 5.2

View File

@ -238,20 +238,11 @@ class Parsedown
break; break;
} }
# ~
if ($line[0] >= 'a' and $line[0] !== '~' or $line[0] >= 'A' and $line[0] <= 'Z')
{
goto paragraph;
}
# ~
$deindented_line = $line;
# #
# indentation sensitive types # indentation sensitive types
$deindented_line = $line;
switch ($line[0]) switch ($line[0])
{ {
case ' ': case ' ':
@ -500,9 +491,7 @@ class Parsedown
continue; continue;
} }
# ~ # paragraph
paragraph:
if ($element['type'] === 'p') if ($element['type'] === 'p')
{ {
@ -744,10 +733,13 @@ class Parsedown
} }
} }
# automatic link if (strpos($text, '://') !== FALSE)
if (strpos($text, '<') !== FALSE and preg_match_all('/<((https?|ftp|dict):[^\^\s]+?)>/i', $text, $matches, PREG_SET_ORDER))
{ {
switch (TRUE)
{
case preg_match_all('{<(https?:[/]{2}[^\s]+)>}i', $text, $matches, PREG_SET_ORDER):
case preg_match_all('{\b(https?:[/]{2}[^\s]+)\b}i', $text, $matches, PREG_SET_ORDER):
foreach ($matches as $matches) foreach ($matches as $matches)
{ {
$url = $matches[1]; $url = $matches[1];
@ -768,6 +760,9 @@ class Parsedown
$index ++; $index ++;
} }
break;
}
} }
# ~ # ~
@ -777,10 +772,15 @@ class Parsedown
# ~ # ~
if (strpos($text, '~~') !== FALSE)
{
$text = preg_replace('/~~(?=\S)(.+?)(?<=\S)~~/s', '<del>$1</del>', $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);
$text = preg_replace('/_(?=\S)(.+?)(?<=\S)_/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)

View File

@ -1,6 +1,6 @@
## Parsedown ## Parsedown
Parsedown is a Markdown parser for PHP. It is fast, consistent and easy to use. Fast, consistent and easy to use [Markdown][1] parser for PHP.
[Home](http://parsedown.org) &middot; [Demo](http://parsedown.org/explorer/) &middot; [Tests](http://parsedown.org/tests/) [Home](http://parsedown.org) &middot; [Demo](http://parsedown.org/explorer/) &middot; [Tests](http://parsedown.org/tests/)
@ -17,3 +17,5 @@ $result = Parsedown::instance()->parse($text);
echo $result; # prints: <p>Hello <strong>Parsedown</strong>!</p> echo $result; # prints: <p>Hello <strong>Parsedown</strong>!</p>
``` ```
[1]: http://daringfireball.net/projects/markdown/

View File

@ -20,20 +20,29 @@ class Test extends PHPUnit_Framework_TestCase
{ {
$provider = array(); $provider = array();
$DirectoryIterator = new DirectoryIterator(__DIR__ . '/' . self::provider_dir); $path = dirname(__FILE__).'/';
$DirectoryIterator = new DirectoryIterator($path . '/' . self::provider_dir);
foreach ($DirectoryIterator as $Item) foreach ($DirectoryIterator as $Item)
{ {
if ($Item->isFile() and $Item->getExtension() === 'md') if ($Item->isFile())
{ {
$filename = $Item->getFilename();
$extension = pathinfo($filename, PATHINFO_EXTENSION);
if ($extension !== 'md')
continue;
$basename = $Item->getBasename('.md'); $basename = $Item->getBasename('.md');
$markdown = file_get_contents(__DIR__ . '/' . self::provider_dir . $basename . '.md'); $markdown = file_get_contents($path . '/' . self::provider_dir . $basename . '.md');
if (!$markdown) if (!$markdown)
continue; continue;
$expected_markup = file_get_contents(__DIR__ . '/' . self::provider_dir . $basename . '.html'); $expected_markup = file_get_contents($path . '/' . self::provider_dir . $basename . '.html');
$expected_markup = str_replace("\r\n", "\n", $expected_markup); $expected_markup = str_replace("\r\n", "\n", $expected_markup);
$expected_markup = str_replace("\r", "\n", $expected_markup); $expected_markup = str_replace("\r", "\n", $expected_markup);
@ -44,4 +53,3 @@ class Test extends PHPUnit_Framework_TestCase
return $provider; return $provider;
} }
} }

View File

@ -2,4 +2,5 @@
<p><em>multiline <p><em>multiline
emphasis</em></p> emphasis</em></p>
<p>_ this _ is not an emphasis, neither is _ this_, _this _, or _this*</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>

View File

@ -5,4 +5,6 @@ emphasis_
_ this _ is not an emphasis, neither is _ this_, _this _, or _this* _ 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

View File

@ -0,0 +1,3 @@
<p><del>strikethrough</del></p>
<p>in the <del>middle</del> of a sentence</p>
<p>in the middle of a w<del>or</del>d</p>

View File

@ -0,0 +1,5 @@
~~strikethrough~~
in the ~~middle~~ of a sentence
in the middle of a w~~or~~d

View File

@ -0,0 +1 @@
<p>Here's an autolink <a href="http://example.com">http://example.com</a>.</p>

View File

@ -0,0 +1 @@
Here's an autolink http://example.com.