mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
4af89c5087 | |||
0352f01c7e | |||
40c2dcfac7 | |||
097ec5e8a5 | |||
8ac52a2f30 | |||
4a6bb88239 | |||
609ad47c38 | |||
7d7e89f5c3 | |||
5aad1d42d2 | |||
3ff5c623f2 | |||
637b516694 | |||
31b811d3fe |
@ -1 +0,0 @@
|
|||||||
src_dir: .
|
|
11
.travis.yml
11
.travis.yml
@ -1,15 +1,6 @@
|
|||||||
language: php
|
language: php
|
||||||
|
|
||||||
php:
|
php:
|
||||||
|
- 5.5
|
||||||
- 5.4
|
- 5.4
|
||||||
- 5.3
|
- 5.3
|
||||||
|
|
||||||
before_script:
|
|
||||||
- composer require satooshi/php-coveralls:dev-master
|
|
||||||
- mkdir -p build/logs
|
|
||||||
|
|
||||||
script:
|
|
||||||
- phpunit --coverage-clover build/logs/clover.xml
|
|
||||||
|
|
||||||
after_script:
|
|
||||||
- php vendor/bin/coveralls
|
|
35
LICENSE.txt
35
LICENSE.txt
@ -1,21 +1,20 @@
|
|||||||
Copyright 2013 Emanuil Rusev
|
The MIT License (MIT)
|
||||||
http://erusev.com
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Copyright (c) 2013 Emanuil Rusev, erusev.com
|
||||||
a copy of this software and associated documentation files (the
|
|
||||||
"Software"), to deal in the Software without restriction, including
|
|
||||||
without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
included in all copies or substantial portions of the Software.
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
The above copyright notice and this permission notice shall be included in all
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
copies or substantial portions of the Software.
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@ -50,7 +50,8 @@ class Parsedown
|
|||||||
$text = preg_replace('{^\xEF\xBB\xBF|\x1A}', '', $text);
|
$text = preg_replace('{^\xEF\xBB\xBF|\x1A}', '', $text);
|
||||||
|
|
||||||
# Removes \r characters.
|
# Removes \r characters.
|
||||||
$text = str_replace("\r", '', $text);
|
$text = str_replace("\r\n", "\n", $text);
|
||||||
|
$text = str_replace("\r", "\n", $text);
|
||||||
|
|
||||||
# Replaces tabs with spaces.
|
# Replaces tabs with spaces.
|
||||||
$text = str_replace("\t", ' ', $text);
|
$text = str_replace("\t", ' ', $text);
|
||||||
@ -80,7 +81,7 @@ class Parsedown
|
|||||||
{
|
{
|
||||||
foreach ($matches as $matches)
|
foreach ($matches as $matches)
|
||||||
{
|
{
|
||||||
$this->reference_map[$matches[1]] = $matches[2];
|
$this->reference_map[strtolower($matches[1])] = $matches[2];
|
||||||
|
|
||||||
$text = str_replace($matches[0], '', $text);
|
$text = str_replace($matches[0], '', $text);
|
||||||
}
|
}
|
||||||
@ -108,8 +109,10 @@ class Parsedown
|
|||||||
|
|
||||||
private function parse_blocks($text)
|
private function parse_blocks($text)
|
||||||
{
|
{
|
||||||
|
$text = trim($text, "\n");
|
||||||
|
|
||||||
# Divides text into blocks.
|
# Divides text into blocks.
|
||||||
$blocks = preg_split('/\n\s*\n/', $text, -1, PREG_SPLIT_NO_EMPTY);
|
$blocks = preg_split('/\n\s*\n/', $text);
|
||||||
|
|
||||||
# Makes sure compound blocks get rendered.
|
# Makes sure compound blocks get rendered.
|
||||||
$blocks []= NULL;
|
$blocks []= NULL;
|
||||||
@ -157,7 +160,6 @@ class Parsedown
|
|||||||
{
|
{
|
||||||
$markup .= '<'.$list_type.'>'."\n";
|
$markup .= '<'.$list_type.'>'."\n";
|
||||||
|
|
||||||
# Of the same type and indentation.
|
|
||||||
$list_items = preg_split('/^([ ]{'.$list_indentation.'})'.$list_marker_pattern.'[ ]/m', $list, -1, PREG_SPLIT_NO_EMPTY);
|
$list_items = preg_split('/^([ ]{'.$list_indentation.'})'.$list_marker_pattern.'[ ]/m', $list, -1, PREG_SPLIT_NO_EMPTY);
|
||||||
|
|
||||||
foreach ($list_items as $list_item)
|
foreach ($list_items as $list_item)
|
||||||
@ -175,7 +177,7 @@ class Parsedown
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$list_item = $this->parse_lines($list_item);
|
$list_item = $this->parse_lines($list_item, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
$markup .= "\n".$list_item;
|
$markup .= "\n".$list_item;
|
||||||
@ -277,7 +279,7 @@ class Parsedown
|
|||||||
{
|
{
|
||||||
if (strpos($block, "\n"))
|
if (strpos($block, "\n"))
|
||||||
{
|
{
|
||||||
$markup .= $this->parse_lines($block);
|
$markup .= $this->parse_lines($block, TRUE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -292,7 +294,7 @@ class Parsedown
|
|||||||
return $markup;
|
return $markup;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parse_lines($text)
|
private function parse_lines($text, $paragraph_based = FALSE)
|
||||||
{
|
{
|
||||||
$text = trim($text, "\n");
|
$text = trim($text, "\n");
|
||||||
|
|
||||||
@ -473,9 +475,11 @@ class Parsedown
|
|||||||
{
|
{
|
||||||
if (isset($paragraph))
|
if (isset($paragraph))
|
||||||
{
|
{
|
||||||
$element_text = $this->parse_inline_elements($paragraph);
|
$paragraph_text = $this->parse_inline_elements($paragraph);
|
||||||
|
|
||||||
$markup .= '<p>'.$element_text.'</p>'."\n";
|
$markup .= $markup === '' && $paragraph_based === FALSE
|
||||||
|
? $paragraph_text
|
||||||
|
: '<p>'.$paragraph_text.'</p>'."\n";
|
||||||
|
|
||||||
unset($paragraph);
|
unset($paragraph);
|
||||||
}
|
}
|
||||||
@ -524,13 +528,19 @@ class Parsedown
|
|||||||
|
|
||||||
# Reference(d) Link / Image
|
# Reference(d) Link / Image
|
||||||
|
|
||||||
if ($this->reference_map and strpos($text, '[') !== FALSE and preg_match_all('/(!?)\[(.+?)\][ ]?\[(.+?)\]/', $text, $matches, PREG_SET_ORDER))
|
if ($this->reference_map and strpos($text, '[') !== FALSE and preg_match_all('/(!?)\[(.+?)\](?:\n?[ ]?\[(.*?)\])?/ms', $text, $matches, PREG_SET_ORDER))
|
||||||
{
|
{
|
||||||
foreach ($matches as $matches)
|
foreach ($matches as $matches)
|
||||||
{
|
{
|
||||||
if (array_key_exists($matches[3], $this->reference_map))
|
$link_difinition = isset($matches[3]) && $matches[3]
|
||||||
|
? $matches[3]
|
||||||
|
: $matches[2]; # implicit
|
||||||
|
|
||||||
|
$link_difinition = strtolower($link_difinition);
|
||||||
|
|
||||||
|
if (isset($this->reference_map[$link_difinition]))
|
||||||
{
|
{
|
||||||
$url = $this->reference_map[$matches[3]];
|
$url = $this->reference_map[$link_difinition];
|
||||||
|
|
||||||
if ($matches[1]) # image
|
if ($matches[1]) # image
|
||||||
{
|
{
|
||||||
@ -558,19 +568,19 @@ class Parsedown
|
|||||||
|
|
||||||
# Inline Link / Image
|
# Inline Link / Image
|
||||||
|
|
||||||
if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)\[(.*?)\]\((.*?)\)/', $text, $matches, PREG_SET_ORDER)) # inline
|
if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)(\[((?:[^][]+|(?2))*)\])\((.*?)\)/', $text, $matches, PREG_SET_ORDER)) # inline
|
||||||
{
|
{
|
||||||
foreach ($matches as $matches)
|
foreach ($matches as $matches)
|
||||||
{
|
{
|
||||||
if ($matches[1]) # image
|
if ($matches[1]) # image
|
||||||
{
|
{
|
||||||
$element = '<img alt="'.$matches[2].'" src="'.$matches[3].'">';
|
$element = '<img alt="'.$matches[3].'" src="'.$matches[4].'">';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$element_text = $this->parse_inline_elements($matches[2]);
|
$element_text = $this->parse_inline_elements($matches[3]);
|
||||||
|
|
||||||
$element = '<a href="'.$matches[3].'">'.$element_text.'</a>';
|
$element = '<a href="'.$matches[4].'">'.$element_text.'</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$element_text = $this->parse_inline_elements($matches[1]);
|
$element_text = $this->parse_inline_elements($matches[1]);
|
||||||
|
@ -34,6 +34,8 @@ class Test extends PHPUnit_Framework_TestCase
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
$expected_markup = file_get_contents(__DIR__ . '/' . self::provider_dir . $basename . '.html');
|
$expected_markup = file_get_contents(__DIR__ . '/' . self::provider_dir . $basename . '.html');
|
||||||
|
$expected_markup = str_replace("\r\n", "\n", $expected_markup);
|
||||||
|
$expected_markup = str_replace("\r", "\n", $expected_markup);
|
||||||
|
|
||||||
$provider [] = array($markdown, $expected_markup);
|
$provider [] = array($markdown, $expected_markup);
|
||||||
}
|
}
|
||||||
|
@ -15,3 +15,10 @@
|
|||||||
<p>Here's one with no space after markers:</p>
|
<p>Here's one with no space after markers:</p>
|
||||||
<p>-list item
|
<p>-list item
|
||||||
-another list item</p>
|
-another list item</p>
|
||||||
|
<p>Here's one where items contain line breaks:</p>
|
||||||
|
<ul>
|
||||||
|
<li>list
|
||||||
|
item</li>
|
||||||
|
<li>another
|
||||||
|
list item</li>
|
||||||
|
</ul>
|
@ -18,3 +18,10 @@ Here's one with no space after markers:
|
|||||||
|
|
||||||
-list item
|
-list item
|
||||||
-another list item
|
-another list item
|
||||||
|
|
||||||
|
Here's one where items contain line breaks:
|
||||||
|
|
||||||
|
- list
|
||||||
|
item
|
||||||
|
- another
|
||||||
|
list item
|
@ -0,0 +1,2 @@
|
|||||||
|
<p>Here's a <a href="http://parsedown.org">link</a>.</p>
|
||||||
|
<p>Here's an image link: <a href="http://daringfireball.net/projects/markdown/"><img alt="MD Logo" src="http://parsedown.org/md.png"></a>.</p>
|
@ -0,0 +1,3 @@
|
|||||||
|
Here's a [link](http://parsedown.org).
|
||||||
|
|
||||||
|
Here's an image link: [](http://daringfireball.net/projects/markdown/).
|
@ -4,5 +4,11 @@
|
|||||||
<p>Here's <a href="http://parsedown.org">one</a> on 2 lines.</p>
|
<p>Here's <a href="http://parsedown.org">one</a> on 2 lines.</p>
|
||||||
<p>Here's <a href="http://parsedown.org/tests/">one</a> with a different URL.</p>
|
<p>Here's <a href="http://parsedown.org/tests/">one</a> with a different URL.</p>
|
||||||
<p>Here's <a href="http://parsedown.org">one</a> with a semantic name.</p>
|
<p>Here's <a href="http://parsedown.org">one</a> with a semantic name.</p>
|
||||||
|
<p>Here's <a href="http://parsedown.org">one</a> with definition name on the next line.</p>
|
||||||
<p>Here's [one][404] with no definition.</p>
|
<p>Here's [one][404] with no definition.</p>
|
||||||
<p>Here's an image: <img alt="Markdown Logo" src="https://raw.github.com/dcurtis/markdown-mark/master/png/32x20-solid.png"></p>
|
<p>Here's an image: <img alt="Markdown Logo" src="https://raw.github.com/dcurtis/markdown-mark/master/png/32x20-solid.png"></p>
|
||||||
|
<p>Here's an <a href="http://google.com">implicit one</a>.</p>
|
||||||
|
<p>Here's an <a href="http://google.com">implicit one</a>.</p>
|
||||||
|
<p>Here's an <a href="http://google.com">implicit one</a> with an empty link definition.</p>
|
||||||
|
<p>Here's a <a href="http://parsedown.org">multiline
|
||||||
|
one</a> defined on 2 lines.</p>
|
@ -18,12 +18,26 @@ Here's [one][5] with a different URL.
|
|||||||
|
|
||||||
[5]: http://parsedown.org/tests/
|
[5]: http://parsedown.org/tests/
|
||||||
|
|
||||||
Here's [one][the website] with a semantic name.
|
Here's [one][website] with a semantic name.
|
||||||
|
|
||||||
[the website]: http://parsedown.org
|
[website]: http://parsedown.org
|
||||||
|
|
||||||
|
Here's [one]
|
||||||
|
[website] with definition name on the next line.
|
||||||
|
|
||||||
Here's [one][404] with no definition.
|
Here's [one][404] with no definition.
|
||||||
|
|
||||||
Here's an image: ![Markdown Logo][image]
|
Here's an image: ![Markdown Logo][image]
|
||||||
|
|
||||||
[image]: https://raw.github.com/dcurtis/markdown-mark/master/png/32x20-solid.png
|
[image]: https://raw.github.com/dcurtis/markdown-mark/master/png/32x20-solid.png
|
||||||
|
|
||||||
|
Here's an [implicit one].
|
||||||
|
|
||||||
|
Here's an [implicit one].
|
||||||
|
|
||||||
|
[implicit one]: http://google.com
|
||||||
|
|
||||||
|
Here's an [implicit one][] with an empty link definition.
|
||||||
|
|
||||||
|
Here's a [multiline
|
||||||
|
one][website] defined on 2 lines.
|
Reference in New Issue
Block a user