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

Compare commits

..

27 Commits
1.5.3 ... 1.6.0

Author SHA1 Message Date
3ebbd730b5 1.6.0 2015-10-04 19:44:32 +03:00
1f02626ed6 add link to caret.io 2015-10-01 18:47:31 +03:00
fa005fdb95 Merge pull request #336 from hkdobrev/late-static-binding
Use late static binding for Parsedown::instance()
2015-08-13 15:16:23 +03:00
5f40cab3e7 Use late static binding for Parsedown::instance()
Fixes erusev/parsedown-extra#67.

This introduces PHP 5.3+ late static binding to the Singleton pattern in Parsedown.
It will return an instance of Parsedown which inherits the class which
called the `instance()` method rather than always returning instance of just `Parsedown`.

Tests are testing this feature with a test class which inherits from Parsedown.
Notice that calling `instance()` with the default arguments after an instance of
`Parsedown` was already created, it will return it even though it is from just
an instance of `Parsedown`. So this is fixing the problem just partially.
2015-08-13 13:29:33 +03:00
0e89e3714b 1.5.4 2015-08-03 12:24:05 +03:00
6b24125f06 clean up 2015-07-31 17:01:14 +03:00
a589bcac79 resolve #342 2015-07-31 01:33:21 +03:00
a9dfc97ddc opening code fence doesn't need 2 regex groups 2015-07-16 16:57:13 +03:00
28774a4359 improve readme 2015-07-15 11:59:59 +03:00
b8b5711ee5 improve readme 2015-07-15 11:59:40 +03:00
9579e5f5e5 improve readme 2015-07-15 11:57:45 +03:00
7f7f6418a3 improve readme 2015-07-15 09:21:38 +03:00
ee81967749 improve readme 2015-07-03 17:11:23 +03:00
96e0810188 improve readme 2015-07-03 17:11:08 +03:00
99bd1bd678 improve readme 2015-07-03 17:06:52 +03:00
e7a6a06166 improve readme 2015-07-03 16:46:25 +03:00
eca5bb8262 improve readme 2015-07-03 16:45:22 +03:00
1312908056 improve readme 2015-07-03 16:42:47 +03:00
76b7d7babd improve readme 2015-07-03 16:39:51 +03:00
ba802c1c8d replace the term "incomplete" 2015-07-02 01:01:14 +03:00
438874e9a8 improve line 2015-06-25 01:05:05 +03:00
8e26f45dee improve readme 2015-06-15 17:38:15 +03:00
e2bb3eaaf8 clean up 2015-06-15 12:28:35 +03:00
0de61e7b3a improve readme 2015-06-15 12:09:57 +03:00
5b72dceb26 improve readme 2015-06-15 00:10:09 +03:00
95699c9ba6 improve readme 2015-06-14 22:55:21 +03:00
790066e9a7 improve readme 2015-05-26 13:37:45 +03:00
4 changed files with 67 additions and 36 deletions

View File

@ -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;

View File

@ -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.

View File

@ -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
View File

@ -0,0 +1,5 @@
<?php
class TestParsedown extends Parsedown
{
}