mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Compare commits
62 Commits
Author | SHA1 | Date | |
---|---|---|---|
20ff8bbb57 | |||
bc21988fe5 | |||
e3c3e28554 | |||
f053740132 | |||
7a92a31739 | |||
6eca8796fb | |||
8876c0984e | |||
cbc4b3f612 | |||
0080ef218e | |||
f4e0234af0 | |||
5c22531e4d | |||
3978e33fd0 | |||
a37797ef34 | |||
e3cd271f16 | |||
f0b7b61c16 | |||
ed41fcf3d6 | |||
1fa8fae301 | |||
932bafe0f0 | |||
ac857809ab | |||
846274996a | |||
c145a75848 | |||
f17aa0438a | |||
38f4027d5e | |||
2cee8d8a2d | |||
cceefafd55 | |||
1c58e9d8d5 | |||
2772b034c6 | |||
a2ed1592bd | |||
3d7a473aa9 | |||
f671ae7364 | |||
490a8f35a4 | |||
94688f21cc | |||
693f2c4842 | |||
9545a295cf | |||
3d649081e5 | |||
32de2cedcc | |||
e7443a2bd8 | |||
10a7ff776c | |||
5ad15b87fa | |||
b166cab9a2 | |||
0f974bf34f | |||
3d7cdeec5f | |||
97953b193e | |||
c046a6b646 | |||
f1fefc257c | |||
6f23ec8203 | |||
23d4544986 | |||
5a4ff5d189 | |||
50ac4a06e8 | |||
003af26499 | |||
aa63058a88 | |||
15d56cdd27 | |||
93d77b0b47 | |||
c8072a1987 | |||
b008290917 | |||
9928c933d8 | |||
ddb3bd2107 | |||
e603c2378d | |||
3ebbd730b5 | |||
1f02626ed6 | |||
fa005fdb95 | |||
5f40cab3e7 |
@ -1,6 +1,7 @@
|
|||||||
language: php
|
language: php
|
||||||
|
|
||||||
php:
|
php:
|
||||||
|
- 7.1
|
||||||
- 7.0
|
- 7.0
|
||||||
- 5.6
|
- 5.6
|
||||||
- 5.5
|
- 5.5
|
||||||
@ -12,5 +13,4 @@ php:
|
|||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- php: 7.0
|
|
||||||
- php: hhvm-nightly
|
- php: hhvm-nightly
|
||||||
|
32
Parsedown.php
Executable file → Normal file
32
Parsedown.php
Executable file → Normal file
@ -17,7 +17,7 @@ class Parsedown
|
|||||||
{
|
{
|
||||||
# ~
|
# ~
|
||||||
|
|
||||||
const version = '1.5.4';
|
const version = '1.6.0';
|
||||||
|
|
||||||
# ~
|
# ~
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ class Parsedown
|
|||||||
# Blocks
|
# Blocks
|
||||||
#
|
#
|
||||||
|
|
||||||
private function lines(array $lines)
|
protected function lines(array $lines)
|
||||||
{
|
{
|
||||||
$CurrentBlock = null;
|
$CurrentBlock = null;
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ class Parsedown
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (method_exists($this, 'block'.$CurrentBlock['type'].'Complete'))
|
if ($this->isBlockCompletable($CurrentBlock['type']))
|
||||||
{
|
{
|
||||||
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
|
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
|
||||||
}
|
}
|
||||||
@ -216,7 +216,7 @@ class Parsedown
|
|||||||
$Block['identified'] = true;
|
$Block['identified'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method_exists($this, 'block'.$blockType.'Continue'))
|
if ($this->isBlockContinuable($blockType))
|
||||||
{
|
{
|
||||||
$Block['continuable'] = true;
|
$Block['continuable'] = true;
|
||||||
}
|
}
|
||||||
@ -245,7 +245,7 @@ class Parsedown
|
|||||||
|
|
||||||
# ~
|
# ~
|
||||||
|
|
||||||
if (isset($CurrentBlock['continuable']) and method_exists($this, 'block'.$CurrentBlock['type'].'Complete'))
|
if (isset($CurrentBlock['continuable']) and $this->isBlockCompletable($CurrentBlock['type']))
|
||||||
{
|
{
|
||||||
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
|
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
|
||||||
}
|
}
|
||||||
@ -278,6 +278,16 @@ class Parsedown
|
|||||||
return $markup;
|
return $markup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function isBlockContinuable($Type)
|
||||||
|
{
|
||||||
|
return method_exists($this, 'block'.$Type.'Continue');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function isBlockCompletable($Type)
|
||||||
|
{
|
||||||
|
return method_exists($this, 'block'.$Type.'Complete');
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Code
|
# Code
|
||||||
|
|
||||||
@ -505,6 +515,16 @@ class Parsedown
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if($name === 'ol')
|
||||||
|
{
|
||||||
|
$listStart = stristr($matches[0], '.', true);
|
||||||
|
|
||||||
|
if($listStart !== '1')
|
||||||
|
{
|
||||||
|
$Block['element']['attributes'] = array('start' => $listStart);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$Block['li'] = array(
|
$Block['li'] = array(
|
||||||
'name' => 'li',
|
'name' => 'li',
|
||||||
'handler' => 'li',
|
'handler' => 'li',
|
||||||
@ -1476,7 +1496,7 @@ class Parsedown
|
|||||||
return self::$instances[$name];
|
return self::$instances[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
$instance = new self();
|
$instance = new static();
|
||||||
|
|
||||||
self::$instances[$name] = $instance;
|
self::$instances[$name] = $instance;
|
||||||
|
|
||||||
|
11
README.md
11
README.md
@ -1,3 +1,5 @@
|
|||||||
|
> You might also like [Caret](http://caret.io?ref=parsedown) - our Markdown editor for Mac / Windows / Linux.
|
||||||
|
|
||||||
## Parsedown
|
## Parsedown
|
||||||
|
|
||||||
[](https://travis-ci.org/erusev/parsedown)
|
[](https://travis-ci.org/erusev/parsedown)
|
||||||
@ -12,10 +14,11 @@ Better Markdown Parser in PHP
|
|||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
|
* One File
|
||||||
* Super Fast
|
* Super Fast
|
||||||
* [GitHub flavored](https://help.github.com/articles/github-flavored-markdown)
|
|
||||||
* Extensible
|
* Extensible
|
||||||
* Tested in 5.3 to 5.6
|
* [GitHub flavored](https://help.github.com/articles/github-flavored-markdown)
|
||||||
|
* Tested in 5.3 to 7.1 and in HHVM
|
||||||
* [Markdown Extra extension](https://github.com/erusev/parsedown-extra)
|
* [Markdown Extra extension](https://github.com/erusev/parsedown-extra)
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
@ -36,7 +39,7 @@ More examples in [the wiki](https://github.com/erusev/parsedown/wiki/) and in [t
|
|||||||
|
|
||||||
**How does Parsedown work?**
|
**How does Parsedown work?**
|
||||||
|
|
||||||
It tries to read Markdown like a human. First, it looks at the lines. It’s interested in how the lines start. This helps it recognise blocks. It knows, for example, that if a line start with a `-` then it perhaps belong to a list. Once it recognises the blocks, it continues to the content. As it reads, it watches out for special characters. This helps it recognise inline elements (or inlines).
|
It tries to read Markdown like a human. First, it looks at the lines. It’s interested in how the lines start. This helps it recognise blocks. It knows, for example, that if a line starts with a `-` then perhaps it belongs to a list. Once it recognises the blocks, it continues to the content. As it reads, it watches out for special characters. This helps it recognise inline elements (or inlines).
|
||||||
|
|
||||||
We call this approach "line based". We believe that Parsedown is the first Markdown parser to use it. Since the release of Parsedown, other developers have used the same approach to develop other Markdown parsers in PHP and in other languages.
|
We call this approach "line based". We believe that Parsedown is the first Markdown parser to use it. Since the release of Parsedown, other developers have used the same approach to develop other Markdown parsers in PHP and in other languages.
|
||||||
|
|
||||||
@ -46,7 +49,7 @@ It passes most of the CommonMark tests. Most of the tests that don't pass deal w
|
|||||||
|
|
||||||
**Who uses it?**
|
**Who uses it?**
|
||||||
|
|
||||||
[phpDocumentor](http://www.phpdoc.org/), [October CMS](http://octobercms.com/), [Bolt CMS](http://bolt.cm/), [Kirby CMS](http://getkirby.com/), [Grav CMS](http://getgrav.org/), [Statamic CMS](http://www.statamic.com/), [RaspberryPi.org](http://www.raspberrypi.org/) and [more](https://www.versioneye.com/php/erusev:parsedown/references).
|
[phpDocumentor](http://www.phpdoc.org/), [October CMS](http://octobercms.com/), [Bolt CMS](http://bolt.cm/), [Kirby CMS](http://getkirby.com/), [Grav CMS](http://getgrav.org/), [Statamic CMS](http://www.statamic.com/), [Herbie CMS](http://www.getherbie.org/), [RaspberryPi.org](http://www.raspberrypi.org/) and [more](https://packagist.org/packages/erusev/parsedown/dependents).
|
||||||
|
|
||||||
**How can I help?**
|
**How can I help?**
|
||||||
|
|
||||||
|
@ -12,6 +12,9 @@
|
|||||||
"homepage": "http://erusev.com"
|
"homepage": "http://erusev.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.3.0"
|
||||||
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {"Parsedown": ""}
|
"psr-0": {"Parsedown": ""}
|
||||||
}
|
}
|
||||||
|
@ -136,4 +136,24 @@ EXPECTED_HTML;
|
|||||||
$parsedownWithNoMarkup->setMarkupEscaped(true);
|
$parsedownWithNoMarkup->setMarkupEscaped(true);
|
||||||
$this->assertEquals($expectedHtml, $parsedownWithNoMarkup->text($markdownWithHtml));
|
$this->assertEquals($expectedHtml, $parsedownWithNoMarkup->text($markdownWithHtml));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testLateStaticBinding()
|
||||||
|
{
|
||||||
|
include __DIR__ . '/TestParsedown.php';
|
||||||
|
|
||||||
|
$parsedown = Parsedown::instance();
|
||||||
|
$this->assertInstanceOf('Parsedown', $parsedown);
|
||||||
|
|
||||||
|
// After instance is already called on Parsedown
|
||||||
|
// subsequent calls with the same arguments return the same instance
|
||||||
|
$sameParsedown = TestParsedown::instance();
|
||||||
|
$this->assertInstanceOf('Parsedown', $sameParsedown);
|
||||||
|
$this->assertSame($parsedown, $sameParsedown);
|
||||||
|
|
||||||
|
$testParsedown = TestParsedown::instance('test late static binding');
|
||||||
|
$this->assertInstanceOf('TestParsedown', $testParsedown);
|
||||||
|
|
||||||
|
$sameInstanceAgain = TestParsedown::instance('test late static binding');
|
||||||
|
$this->assertSame($testParsedown, $sameInstanceAgain);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
5
test/TestParsedown.php
Normal file
5
test/TestParsedown.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class TestParsedown extends Parsedown
|
||||||
|
{
|
||||||
|
}
|
@ -8,6 +8,6 @@
|
|||||||
<li>two</li>
|
<li>two</li>
|
||||||
</ol>
|
</ol>
|
||||||
<p>large numbers:</p>
|
<p>large numbers:</p>
|
||||||
<ol>
|
<ol start="123">
|
||||||
<li>one</li>
|
<li>one</li>
|
||||||
</ol>
|
</ol>
|
Reference in New Issue
Block a user