mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Compare commits
11 Commits
1.8.0-beta
...
1.7.4
Author | SHA1 | Date | |
---|---|---|---|
cb17b6477d | |||
21f99b156a | |||
791faca8af | |||
add8d18c80 | |||
7073ac3ed1 | |||
3d2b25b79d | |||
6d89393817 | |||
d60bcdc469 | |||
c390a9e406 | |||
0f1e9da8f4 | |||
bc003952fc |
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -1,6 +1,5 @@
|
||||
# Ignore all tests for archive
|
||||
/test export-ignore
|
||||
/.gitattributes export-ignore
|
||||
/.gitignore export-ignore
|
||||
/.travis.yml export-ignore
|
||||
/phpunit.xml.dist export-ignore
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
composer.lock
|
||||
vendor/
|
@ -13,13 +13,12 @@ matrix:
|
||||
- php: 7.0
|
||||
- php: 7.1
|
||||
- php: 7.2
|
||||
- php: 7.3
|
||||
- php: 7.4
|
||||
- php: nightly
|
||||
- php: hhvm
|
||||
- php: hhvm-nightly
|
||||
fast_finish: true
|
||||
allow_failures:
|
||||
- php: nightly
|
||||
- php: hhvm-nightly
|
||||
|
||||
install:
|
||||
- composer install --prefer-dist --no-interaction --no-progress
|
||||
|
1158
Parsedown.php
1158
Parsedown.php
File diff suppressed because it is too large
Load Diff
15
README.md
15
README.md
@ -19,21 +19,12 @@ Better Markdown Parser in PHP
|
||||
* Super Fast
|
||||
* Extensible
|
||||
* [GitHub flavored](https://help.github.com/articles/github-flavored-markdown)
|
||||
* Tested in 5.3 to 7.2 and in HHVM
|
||||
* Tested in 5.3 to 7.1 and in HHVM
|
||||
* [Markdown Extra extension](https://github.com/erusev/parsedown-extra)
|
||||
|
||||
### Installation
|
||||
#### Composer
|
||||
Install the [composer package] by running the following command:
|
||||
|
||||
composer require erusev/parsedown
|
||||
|
||||
#### Manual
|
||||
1. Download the "Source code" from the [latest release]
|
||||
2. Include `Parsedown.php`
|
||||
|
||||
[composer package]: https://packagist.org/packages/erusev/parsedown "The Parsedown package on packagist.org"
|
||||
[latest release]: https://github.com/erusev/parsedown/releases/latest "The latest release of Parsedown"
|
||||
Include `Parsedown.php` or install [the composer package](https://packagist.org/packages/erusev/parsedown).
|
||||
|
||||
### Example
|
||||
|
||||
@ -41,8 +32,6 @@ Install the [composer package] by running the following command:
|
||||
$Parsedown = new Parsedown();
|
||||
|
||||
echo $Parsedown->text('Hello _Parsedown_!'); # prints: <p>Hello <em>Parsedown</em>!</p>
|
||||
// you can also parse inline markdown only
|
||||
echo $Parsedown->line('Hello _Parsedown_!'); # prints: Hello <em>Parsedown</em>!
|
||||
```
|
||||
|
||||
More examples in [the wiki](https://github.com/erusev/parsedown/wiki/) and in [this video tutorial](http://youtu.be/wYZBY8DEikI).
|
||||
|
9
test/ParsedownTest.php
Executable file → Normal file
9
test/ParsedownTest.php
Executable file → Normal file
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
require 'SampleExtensions.php';
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@ -13,8 +14,7 @@ class ParsedownTest extends TestCase
|
||||
parent::__construct($name, $data, $dataName);
|
||||
}
|
||||
|
||||
private $dirs;
|
||||
protected $Parsedown;
|
||||
private $dirs, $Parsedown;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
@ -51,7 +51,6 @@ class ParsedownTest extends TestCase
|
||||
$expectedMarkup = str_replace("\r", "\n", $expectedMarkup);
|
||||
|
||||
$this->Parsedown->setSafeMode(substr($test, 0, 3) === 'xss');
|
||||
$this->Parsedown->setStrictMode(substr($test, 0, 6) === 'strict');
|
||||
|
||||
$actualMarkup = $this->Parsedown->text($markdown);
|
||||
|
||||
@ -160,12 +159,12 @@ MARKDOWN_WITH_MARKUP;
|
||||
<p><div><em>content</em></div></p>
|
||||
<p>sparse:</p>
|
||||
<p><div>
|
||||
<div class="inner">
|
||||
<div class="inner">
|
||||
<em>content</em>
|
||||
</div>
|
||||
</div></p>
|
||||
<p>paragraph</p>
|
||||
<p><style type="text/css">
|
||||
<p><style type="text/css">
|
||||
p {
|
||||
color: red;
|
||||
}
|
||||
|
@ -4,27 +4,26 @@ class UnsafeExtension extends Parsedown
|
||||
{
|
||||
protected function blockFencedCodeComplete($Block)
|
||||
{
|
||||
$text = $Block['element']['element']['text'];
|
||||
unset($Block['element']['element']['text']);
|
||||
$text = $Block['element']['text']['text'];
|
||||
unset($Block['element']['text']['text']);
|
||||
|
||||
// WARNING: There is almost always a better way of doing things!
|
||||
//
|
||||
// This example is one of them, unsafe behaviour is NOT needed here.
|
||||
// Only use this if you trust the input and have no idea what
|
||||
// the output HTML will look like (e.g. using an external parser).
|
||||
$Block['element']['element']['rawHtml'] = "<p>$text</p>";
|
||||
$Block['element']['text']['rawHtml'] = "<p>$text</p>";
|
||||
|
||||
return $Block;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TrustDelegatedExtension extends Parsedown
|
||||
{
|
||||
protected function blockFencedCodeComplete($Block)
|
||||
{
|
||||
$text = $Block['element']['element']['text'];
|
||||
unset($Block['element']['element']['text']);
|
||||
$text = $Block['element']['text']['text'];
|
||||
unset($Block['element']['text']['text']);
|
||||
|
||||
// WARNING: There is almost always a better way of doing things!
|
||||
//
|
||||
@ -32,8 +31,8 @@ class TrustDelegatedExtension extends Parsedown
|
||||
// Only use this if you are sure that the result being added into
|
||||
// rawHtml is safe.
|
||||
// (e.g. using an external parser with escaping capabilities).
|
||||
$Block['element']['element']['rawHtml'] = "<p>$text</p>";
|
||||
$Block['element']['element']['allowRawHtmlInSafeMode'] = true;
|
||||
$Block['element']['text']['rawHtml'] = "<p>$text</p>";
|
||||
$Block['element']['text']['allowRawHtmlInSafeMode'] = true;
|
||||
|
||||
return $Block;
|
||||
}
|
||||
|
@ -6,8 +6,4 @@
|
||||
<h6>h6</h6>
|
||||
<p>####### not a heading</p>
|
||||
<h1>closed h1</h1>
|
||||
<h1></h1>
|
||||
<h2></h2>
|
||||
<h1># of levels</h1>
|
||||
<h1># of levels #</h1>
|
||||
<h1>heading</h1>
|
||||
<p>#</p>
|
@ -14,12 +14,4 @@
|
||||
|
||||
# closed h1 #
|
||||
|
||||
#
|
||||
|
||||
##
|
||||
|
||||
# # of levels
|
||||
|
||||
# # of levels # #
|
||||
|
||||
#heading
|
||||
#
|
@ -5,9 +5,4 @@ echo $message;</code></pre>
|
||||
<hr />
|
||||
<pre><code>> not a quote
|
||||
- not a list item
|
||||
[not a reference]: http://foo.com</code></pre>
|
||||
<hr />
|
||||
<pre><code>foo
|
||||
|
||||
|
||||
bar</code></pre>
|
||||
[not a reference]: http://foo.com</code></pre>
|
@ -7,11 +7,4 @@
|
||||
|
||||
> not a quote
|
||||
- not a list item
|
||||
[not a reference]: http://foo.com
|
||||
|
||||
---
|
||||
|
||||
foo
|
||||
|
||||
|
||||
bar
|
||||
[not a reference]: http://foo.com
|
@ -1,40 +1,12 @@
|
||||
<ul>
|
||||
<li>li<ul>
|
||||
<li>li<ul>
|
||||
<li>li</li>
|
||||
<li>li</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>li</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>li</li>
|
||||
</ul>
|
||||
<hr />
|
||||
<li>li
|
||||
<ul>
|
||||
<li>level 1<ul>
|
||||
<li>level 2<ul>
|
||||
<li>level 3<ul>
|
||||
<li>level 4<ul>
|
||||
<li>level 5</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<hr />
|
||||
<li>li
|
||||
<ul>
|
||||
<li>a</li>
|
||||
<li>b</li>
|
||||
<li>c</li>
|
||||
<li>d</li>
|
||||
<li>e</li>
|
||||
<li>f</li>
|
||||
<li>g</li>
|
||||
<li>h</li>
|
||||
<li>i</li>
|
||||
<li>li</li>
|
||||
<li>li</li>
|
||||
</ul></li>
|
||||
<li>li</li>
|
||||
</ul></li>
|
||||
<li>li</li>
|
||||
</ul>
|
@ -3,24 +3,4 @@
|
||||
- li
|
||||
- li
|
||||
- li
|
||||
- li
|
||||
|
||||
---
|
||||
|
||||
- level 1
|
||||
- level 2
|
||||
- level 3
|
||||
- level 4
|
||||
- level 5
|
||||
|
||||
---
|
||||
|
||||
- a
|
||||
- b
|
||||
- c
|
||||
- d
|
||||
- e
|
||||
- f
|
||||
- g
|
||||
- h
|
||||
- i
|
||||
- li
|
@ -1,2 +1 @@
|
||||
<p>my email is <a href="mailto:me@example.com">me@example.com</a></p>
|
||||
<p>html tags shouldn't start an email autolink <strong>first.last@example.com</strong></p>
|
||||
<p>my email is <a href="mailto:me@example.com">me@example.com</a></p>
|
@ -1,3 +1 @@
|
||||
my email is <me@example.com>
|
||||
|
||||
html tags shouldn't start an email autolink <strong>first.last@example.com</strong>
|
||||
my email is <me@example.com>
|
@ -9,10 +9,5 @@ echo $message;</code></pre>
|
||||
echo "Hello World";
|
||||
?>
|
||||
<a href="http://auraphp.com" >Aura Project</a></code></pre>
|
||||
<pre><code>the following isn't quite enough to close
|
||||
```
|
||||
still a fenced code block</code></pre>
|
||||
<pre><code>foo
|
||||
|
||||
|
||||
bar</code></pre>
|
||||
<pre><code class="language-php"><?php
|
||||
echo "Hello World";</code></pre>
|
@ -24,15 +24,7 @@ echo "Hello World";
|
||||
<a href="http://auraphp.com" >Aura Project</a>
|
||||
```
|
||||
|
||||
````
|
||||
the following isn't quite enough to close
|
||||
```
|
||||
still a fenced code block
|
||||
````
|
||||
|
||||
```
|
||||
foo
|
||||
|
||||
|
||||
bar
|
||||
```php some-class
|
||||
<?php
|
||||
echo "Hello World";
|
||||
```
|
@ -2,10 +2,4 @@
|
||||
<p>paragraph</p>
|
||||
<!--
|
||||
multiline -->
|
||||
<p>paragraph</p>
|
||||
<!-- sss -->abc
|
||||
<ul>
|
||||
<li>abcd</li>
|
||||
<li>bbbb</li>
|
||||
<li>cccc</li>
|
||||
</ul>
|
||||
<p>paragraph</p>
|
@ -5,10 +5,4 @@ paragraph
|
||||
<!--
|
||||
multiline -->
|
||||
|
||||
paragraph
|
||||
|
||||
<!-- sss -->abc
|
||||
|
||||
* abcd
|
||||
* bbbb
|
||||
* cccc
|
||||
paragraph
|
@ -1,8 +1,6 @@
|
||||
<blockquote>
|
||||
<p>quote
|
||||
the rest of it</p>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<p>another paragraph
|
||||
the rest of it</p>
|
||||
</blockquote>
|
@ -1,3 +0,0 @@
|
||||
<div>Markup</div>
|
||||
_No markdown_ without blank line for **strict** compliance with CommonMark.
|
||||
<p><strong>Markdown</strong></p>
|
@ -1,4 +0,0 @@
|
||||
<div>Markup</div>
|
||||
_No markdown_ without blank line for **strict** compliance with CommonMark.
|
||||
|
||||
**Markdown**
|
@ -1,4 +0,0 @@
|
||||
<div>One markup on
|
||||
two lines</div>
|
||||
_No markdown_
|
||||
<p><strong>Markdown</strong></p>
|
@ -1,5 +0,0 @@
|
||||
<div>One markup on
|
||||
two lines</div>
|
||||
_No markdown_
|
||||
|
||||
**Markdown**
|
@ -1,3 +0,0 @@
|
||||
<div><p>Stripped markup</p></div>
|
||||
_No markdown_
|
||||
<p><strong>Markdown</strong></p>
|
@ -1,4 +0,0 @@
|
||||
<div><p>Stripped markup</p></div>
|
||||
_No markdown_
|
||||
|
||||
**Markdown**
|
@ -1,3 +0,0 @@
|
||||
<div>First markup</div><p>and second markup on the same line.</p>
|
||||
_No markdown_
|
||||
<p><strong>Markdown</strong></p>
|
@ -1,4 +0,0 @@
|
||||
<div>First markup</div><p>and second markup on the same line.</p>
|
||||
_No markdown_
|
||||
|
||||
**Markdown**
|
@ -1,4 +0,0 @@
|
||||
<div>First markup</div><p>and partial markup
|
||||
on two lines.</p>
|
||||
_No markdown_
|
||||
<p><strong>Markdown</strong></p>
|
@ -1,5 +0,0 @@
|
||||
<div>First markup</div><p>and partial markup
|
||||
on two lines.</p>
|
||||
_No markdown_
|
||||
|
||||
**Markdown**
|
@ -1,4 +0,0 @@
|
||||
<div><p>Stripped markup
|
||||
on two lines</p></div>
|
||||
_No markdown_
|
||||
<p><strong>Markdown</strong></p>
|
@ -1,5 +0,0 @@
|
||||
<div><p>Stripped markup
|
||||
on two lines</p></div>
|
||||
_No markdown_
|
||||
|
||||
**Markdown**
|
@ -10,7 +10,4 @@
|
||||
<p>large numbers:</p>
|
||||
<ol start="123">
|
||||
<li>one</li>
|
||||
</ol>
|
||||
<p>foo 1. the following should not start a list
|
||||
100.<br />
|
||||
200. </p>
|
||||
</ol>
|
@ -8,8 +8,4 @@ repeating numbers:
|
||||
|
||||
large numbers:
|
||||
|
||||
123. one
|
||||
|
||||
foo 1. the following should not start a list
|
||||
100.
|
||||
200.
|
||||
123. one
|
@ -1,18 +1,12 @@
|
||||
<hr>
|
||||
|
||||
paragraph
|
||||
<hr/>
|
||||
|
||||
paragraph
|
||||
<hr />
|
||||
|
||||
paragraph
|
||||
<hr class="foo" id="bar" />
|
||||
|
||||
paragraph
|
||||
<hr class="foo" id="bar"/>
|
||||
|
||||
paragraph
|
||||
<hr class="foo" id="bar" >
|
||||
|
||||
paragraph
|
@ -1,12 +0,0 @@
|
||||
<h1>trailing space</h1>
|
||||
<h2>trailing space</h2>
|
||||
<h1>leading and trailing space</h1>
|
||||
<h2>leading and trailing space</h2>
|
||||
<h1>1 leading space</h1>
|
||||
<h2>1 leading space</h2>
|
||||
<h1>3 leading spaces</h1>
|
||||
<h2>3 leading spaces</h2>
|
||||
<p>too many leading spaces
|
||||
==</p>
|
||||
<p>too many leading spaces
|
||||
--</p>
|
@ -1,29 +0,0 @@
|
||||
trailing space
|
||||
==
|
||||
|
||||
trailing space
|
||||
--
|
||||
|
||||
leading and trailing space
|
||||
==
|
||||
|
||||
leading and trailing space
|
||||
--
|
||||
|
||||
1 leading space
|
||||
==
|
||||
|
||||
1 leading space
|
||||
--
|
||||
|
||||
3 leading spaces
|
||||
==
|
||||
|
||||
3 leading spaces
|
||||
--
|
||||
|
||||
too many leading spaces
|
||||
==
|
||||
|
||||
too many leading spaces
|
||||
--
|
@ -8,19 +8,4 @@
|
||||
<p>no space after <code>></code>:</p>
|
||||
<blockquote>
|
||||
<p>quote</p>
|
||||
</blockquote>
|
||||
<hr />
|
||||
<blockquote>
|
||||
<blockquote>
|
||||
<blockquote>
|
||||
<p>Info 1 text</p>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<blockquote>
|
||||
<blockquote>
|
||||
<p>Info 2 text</p>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
</blockquote>
|
@ -4,10 +4,4 @@ indented:
|
||||
> quote
|
||||
|
||||
no space after `>`:
|
||||
>quote
|
||||
|
||||
---
|
||||
|
||||
>>> Info 1 text
|
||||
|
||||
>>> Info 2 text
|
||||
>quote
|
@ -34,42 +34,4 @@
|
||||
<td>cell 2.2</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<hr />
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="text-align: left;">header 1</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="text-align: left;">cell 1.1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="text-align: left;">cell 2.1</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<hr />
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>header 1</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>cell 1.1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>cell 2.1</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<hr />
|
||||
<p>Not a table, we haven't ended the paragraph:
|
||||
header 1 | header 2
|
||||
-------- | --------
|
||||
cell 1.1 | cell 1.2
|
||||
cell 2.1 | cell 2.2</p>
|
||||
</table>
|
@ -8,26 +8,4 @@ cell 2.1 | cell 2.2
|
||||
header 1 | header 2
|
||||
:------- | --------
|
||||
cell 1.1 | cell 1.2
|
||||
cell 2.1 | cell 2.2
|
||||
|
||||
---
|
||||
|
||||
header 1
|
||||
:-------
|
||||
cell 1.1
|
||||
cell 2.1
|
||||
|
||||
---
|
||||
|
||||
header 1
|
||||
-------|
|
||||
cell 1.1
|
||||
cell 2.1
|
||||
|
||||
---
|
||||
|
||||
Not a table, we haven't ended the paragraph:
|
||||
header 1 | header 2
|
||||
-------- | --------
|
||||
cell 1.1 | cell 1.2
|
||||
cell 2.1 | cell 2.2
|
@ -1,6 +1,8 @@
|
||||
<div>
|
||||
line 1
|
||||
<p>line 2
|
||||
line 3</p>
|
||||
<p>line 4</p>
|
||||
|
||||
line 2
|
||||
line 3
|
||||
|
||||
line 4
|
||||
</div>
|
@ -1,13 +0,0 @@
|
||||
<h1>h1</h1>
|
||||
<h2>h2</h2>
|
||||
<h3>h3</h3>
|
||||
<h4>h4</h4>
|
||||
<h5>h5</h5>
|
||||
<h6>h6</h6>
|
||||
<p>####### not a heading</p>
|
||||
<p>#not a heading</p>
|
||||
<h1>closed h1</h1>
|
||||
<h1></h1>
|
||||
<h2></h2>
|
||||
<h1># of levels</h1>
|
||||
<h1># of levels #</h1>
|
@ -1,25 +0,0 @@
|
||||
# h1
|
||||
|
||||
## h2
|
||||
|
||||
### h3
|
||||
|
||||
#### h4
|
||||
|
||||
##### h5
|
||||
|
||||
###### h6
|
||||
|
||||
####### not a heading
|
||||
|
||||
#not a heading
|
||||
|
||||
# closed h1 #
|
||||
|
||||
#
|
||||
|
||||
##
|
||||
|
||||
# # of levels
|
||||
|
||||
# # of levels # #
|
@ -1,4 +1,3 @@
|
||||
<p><del>strikethrough</del></p>
|
||||
<p>here's <del>one</del> followed by <del>another one</del></p>
|
||||
<p>~~ this ~~ is not one neither is ~this~</p>
|
||||
<p>escaped ~~this~~</p>
|
||||
<p>~~ this ~~ is not one neither is ~this~</p>
|
@ -2,6 +2,4 @@
|
||||
|
||||
here's ~~one~~ followed by ~~another one~~
|
||||
|
||||
~~ this ~~ is not one neither is ~this~
|
||||
|
||||
escaped \~\~this\~\~
|
||||
~~ this ~~ is not one neither is ~this~
|
@ -2,21 +2,9 @@
|
||||
<li>li</li>
|
||||
<li>li</li>
|
||||
</ul>
|
||||
<p>mixed unordered markers:</p>
|
||||
<p>mixed markers:</p>
|
||||
<ul>
|
||||
<li>li</li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li>li</li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li>li</li>
|
||||
</ul>
|
||||
<p>mixed ordered markers:</p>
|
||||
<ol>
|
||||
<li>starting at 1, list one</li>
|
||||
<li>number 2, list one</li>
|
||||
</ol>
|
||||
<ol start="3">
|
||||
<li>starting at 3, list two</li>
|
||||
</ol>
|
||||
</ul>
|
@ -1,14 +1,8 @@
|
||||
- li
|
||||
- li
|
||||
|
||||
mixed unordered markers:
|
||||
mixed markers:
|
||||
|
||||
* li
|
||||
+ li
|
||||
- li
|
||||
|
||||
mixed ordered markers:
|
||||
|
||||
1. starting at 1, list one
|
||||
2. number 2, list one
|
||||
3) starting at 3, list two
|
||||
- li
|
Reference in New Issue
Block a user