mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
3ebbd730b5 | |||
1f02626ed6 | |||
fa005fdb95 | |||
5f40cab3e7 | |||
0e89e3714b | |||
6b24125f06 | |||
a589bcac79 | |||
a9dfc97ddc | |||
28774a4359 | |||
b8b5711ee5 | |||
9579e5f5e5 | |||
7f7f6418a3 | |||
ee81967749 | |||
96e0810188 | |||
99bd1bd678 | |||
e7a6a06166 | |||
eca5bb8262 | |||
1312908056 | |||
76b7d7babd | |||
ba802c1c8d | |||
438874e9a8 | |||
8e26f45dee | |||
e2bb3eaaf8 | |||
0de61e7b3a | |||
5b72dceb26 | |||
95699c9ba6 | |||
790066e9a7 |
@ -17,7 +17,7 @@ class Parsedown
|
||||
{
|
||||
# ~
|
||||
|
||||
const version = '1.5.3';
|
||||
const version = '1.6.0';
|
||||
|
||||
# ~
|
||||
|
||||
@ -107,12 +107,6 @@ class Parsedown
|
||||
|
||||
# ~
|
||||
|
||||
protected $DefinitionTypes = array(
|
||||
'[' => array('Reference'),
|
||||
);
|
||||
|
||||
# ~
|
||||
|
||||
protected $unmarkedBlockTypes = array(
|
||||
'Code',
|
||||
);
|
||||
@ -169,7 +163,7 @@ class Parsedown
|
||||
|
||||
# ~
|
||||
|
||||
if (isset($CurrentBlock['incomplete']))
|
||||
if (isset($CurrentBlock['continuable']))
|
||||
{
|
||||
$Block = $this->{'block'.$CurrentBlock['type'].'Continue'}($Line, $CurrentBlock);
|
||||
|
||||
@ -185,8 +179,6 @@ class Parsedown
|
||||
{
|
||||
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
|
||||
}
|
||||
|
||||
unset($CurrentBlock['incomplete']);
|
||||
}
|
||||
}
|
||||
|
||||
@ -226,7 +218,7 @@ class Parsedown
|
||||
|
||||
if (method_exists($this, 'block'.$blockType.'Continue'))
|
||||
{
|
||||
$Block['incomplete'] = true;
|
||||
$Block['continuable'] = true;
|
||||
}
|
||||
|
||||
$CurrentBlock = $Block;
|
||||
@ -253,7 +245,7 @@ class Parsedown
|
||||
|
||||
# ~
|
||||
|
||||
if (isset($CurrentBlock['incomplete']) and method_exists($this, 'block'.$CurrentBlock['type'].'Complete'))
|
||||
if (isset($CurrentBlock['continuable']) and method_exists($this, 'block'.$CurrentBlock['type'].'Complete'))
|
||||
{
|
||||
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
|
||||
}
|
||||
@ -394,16 +386,16 @@ class Parsedown
|
||||
|
||||
protected function blockFencedCode($Line)
|
||||
{
|
||||
if (preg_match('/^(['.$Line['text'][0].']{3,})[ ]*([\w-]+)?[ ]*$/', $Line['text'], $matches))
|
||||
if (preg_match('/^['.$Line['text'][0].']{3,}[ ]*([\w-]+)?[ ]*$/', $Line['text'], $matches))
|
||||
{
|
||||
$Element = array(
|
||||
'name' => 'code',
|
||||
'text' => '',
|
||||
);
|
||||
|
||||
if (isset($matches[2]))
|
||||
if (isset($matches[1]))
|
||||
{
|
||||
$class = 'language-'.$matches[2];
|
||||
$class = 'language-'.$matches[1];
|
||||
|
||||
$Element['attributes'] = array(
|
||||
'class' => $class,
|
||||
@ -673,7 +665,9 @@ class Parsedown
|
||||
|
||||
if (preg_match('/^<(\w*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches))
|
||||
{
|
||||
if (in_array($matches[1], $this->textLevelElements))
|
||||
$element = strtolower($matches[1]);
|
||||
|
||||
if (in_array($element, $this->textLevelElements))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -987,15 +981,13 @@ class Parsedown
|
||||
{
|
||||
$markup = '';
|
||||
|
||||
$unexaminedText = $text;
|
||||
# $excerpt is based on the first occurrence of a marker
|
||||
|
||||
$markerPosition = 0;
|
||||
|
||||
while ($excerpt = strpbrk($unexaminedText, $this->inlineMarkerList))
|
||||
while ($excerpt = strpbrk($text, $this->inlineMarkerList))
|
||||
{
|
||||
$marker = $excerpt[0];
|
||||
|
||||
$markerPosition += strpos($unexaminedText, $marker);
|
||||
$markerPosition = strpos($text, $marker);
|
||||
|
||||
$Excerpt = array('text' => $excerpt, 'context' => $text);
|
||||
|
||||
@ -1008,34 +1000,42 @@ class Parsedown
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($Inline['position']) and $Inline['position'] > $markerPosition) # position is ahead of marker
|
||||
# makes sure that the inline belongs to "our" marker
|
||||
|
||||
if (isset($Inline['position']) and $Inline['position'] > $markerPosition)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
# sets a default inline position
|
||||
|
||||
if ( ! isset($Inline['position']))
|
||||
{
|
||||
$Inline['position'] = $markerPosition;
|
||||
}
|
||||
|
||||
# the text that comes before the inline
|
||||
$unmarkedText = substr($text, 0, $Inline['position']);
|
||||
|
||||
# compile the unmarked text
|
||||
$markup .= $this->unmarkedText($unmarkedText);
|
||||
|
||||
# compile the inline
|
||||
$markup .= isset($Inline['markup']) ? $Inline['markup'] : $this->element($Inline['element']);
|
||||
|
||||
# remove the examined text
|
||||
$text = substr($text, $Inline['position'] + $Inline['extent']);
|
||||
|
||||
$unexaminedText = $text;
|
||||
|
||||
$markerPosition = 0;
|
||||
|
||||
continue 2;
|
||||
}
|
||||
|
||||
$unexaminedText = substr($excerpt, 1);
|
||||
# the marker does not belong to an inline
|
||||
|
||||
$markerPosition ++;
|
||||
$unmarkedText = substr($text, 0, $markerPosition + 1);
|
||||
|
||||
$markup .= $this->unmarkedText($unmarkedText);
|
||||
|
||||
$text = substr($text, $markerPosition + 1);
|
||||
}
|
||||
|
||||
$markup .= $this->unmarkedText($text);
|
||||
@ -1476,7 +1476,7 @@ class Parsedown
|
||||
return self::$instances[$name];
|
||||
}
|
||||
|
||||
$instance = new self();
|
||||
$instance = new static();
|
||||
|
||||
self::$instances[$name] = $instance;
|
||||
|
||||
|
20
README.md
20
README.md
@ -5,15 +5,17 @@
|
||||
|
||||
Better Markdown Parser in PHP
|
||||
|
||||
[See Demo](http://parsedown.org/demo)
|
||||
[Demo](http://parsedown.org/demo) |
|
||||
[Benchmarks](http://parsedown.org/speed) |
|
||||
[Tests](http://parsedown.org/tests/) |
|
||||
[Documentation](https://github.com/erusev/parsedown/wiki/)
|
||||
|
||||
### Features
|
||||
|
||||
* [Fast](http://parsedown.org/speed)
|
||||
* [Consistent](http://parsedown.org/consistency)
|
||||
* Super Fast
|
||||
* [GitHub flavored](https://help.github.com/articles/github-flavored-markdown)
|
||||
* [Tested](http://parsedown.org/tests/) in PHP 5.3, 5.4, 5.5, 5.6 and [HHVM](http://www.hhvm.com/)
|
||||
* [Extensible](https://github.com/erusev/parsedown/wiki/Writing-Extensions)
|
||||
* Extensible
|
||||
* Tested in 5.3 to 5.6
|
||||
* [Markdown Extra extension](https://github.com/erusev/parsedown-extra)
|
||||
|
||||
### Installation
|
||||
@ -28,7 +30,7 @@ $Parsedown = new Parsedown();
|
||||
echo $Parsedown->text('Hello _Parsedown_!'); # prints: <p>Hello <em>Parsedown</em>!</p>
|
||||
```
|
||||
|
||||
More examples in [the wiki](https://github.com/erusev/parsedown/wiki/Usage) and in [this video tutorial](http://youtu.be/wYZBY8DEikI).
|
||||
More examples in [the wiki](https://github.com/erusev/parsedown/wiki/) and in [this video tutorial](http://youtu.be/wYZBY8DEikI).
|
||||
|
||||
### Questions
|
||||
|
||||
@ -48,4 +50,8 @@ It passes most of the CommonMark tests. Most of the tests that don't pass deal w
|
||||
|
||||
**How can I help?**
|
||||
|
||||
Use it, star it, share it and if you feel generous, [donate some money](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=528P3NZQMP8N2).
|
||||
Use it, star it, share it and if you feel generous, [donate](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=528P3NZQMP8N2).
|
||||
|
||||
---
|
||||
|
||||
You might also like [Caret](http://caret.io) - our Markdown editor for the desktop.
|
||||
|
@ -136,4 +136,24 @@ EXPECTED_HTML;
|
||||
$parsedownWithNoMarkup->setMarkupEscaped(true);
|
||||
$this->assertEquals($expectedHtml, $parsedownWithNoMarkup->text($markdownWithHtml));
|
||||
}
|
||||
|
||||
public function testLateStaticBinding()
|
||||
{
|
||||
include 'test/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
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user