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

Compare commits

...

9 Commits

Author SHA1 Message Date
d24439ada0 improve test suite 2014-05-21 23:20:46 +03:00
1ae100beab improve comment 2014-05-17 17:37:17 +03:00
82a5a78a36 improve readme 2014-05-17 17:13:00 +03:00
4ede4340ab improve readme 2014-05-16 03:34:43 +03:00
170a6bf770 improve readme 2014-05-16 01:27:54 +03:00
21db821324 improve readme 2014-05-16 01:15:21 +03:00
b384839d15 update readme 2014-05-14 20:07:52 +03:00
2da10d277b resolve #105 2014-05-14 13:14:49 +03:00
532b5ede35 resolve #129 2014-05-14 01:11:05 +03:00
12 changed files with 107 additions and 92 deletions

View File

@ -18,11 +18,10 @@ class Parsedown
# #
# Philosophy # Philosophy
# Markdown is intended to be easy-to-read by humans - those of us who read # Parsedown recognises that the Markdown syntax is optimised for humans so
# line by line, left to right, top to bottom. In order to take advantage of # it tries to read like one. It goes through text line by line. It looks at
# this, Parsedown tries to read in a similar way. It breaks texts into # how lines start to identify blocks. It looks for special characters to
# lines, it iterates through them and it looks at how they start and relate # identify inline elements.
# to each other.
# #
# ~ # ~
@ -87,7 +86,7 @@ class Parsedown
'8' => array('List'), '8' => array('List'),
'9' => array('List'), '9' => array('List'),
':' => array('Table'), ':' => array('Table'),
'<' => array('Markup'), '<' => array('Comment', 'Markup'),
'=' => array('Setext'), '=' => array('Setext'),
'>' => array('Quote'), '>' => array('Quote'),
'_' => array('Rule'), '_' => array('Rule'),
@ -346,6 +345,43 @@ class Parsedown
return $Block; return $Block;
} }
#
# Comment
protected function identifyComment($Line)
{
if (isset($Line['text'][3]) and $Line['text'][3] === '-' and $Line['text'][2] === '-' and $Line['text'][1] === '!')
{
$Block = array(
'element' => $Line['body'],
);
if (preg_match('/-->$/', $Line['text']))
{
$Block['closed'] = true;
}
return $Block;
}
}
protected function addToComment($Line, array $Block)
{
if (isset($Block['closed']))
{
return;
}
$Block['element'] .= "\n" . $Line['body'];
if (preg_match('/-->$/', $Line['text']))
{
$Block['closed'] = true;
}
return $Block;
}
# #
# Fenced Code # Fenced Code
@ -601,8 +637,7 @@ class Parsedown
else else
{ {
$Block['depth'] = 0; $Block['depth'] = 0;
$Block['start'] = '<'.$matches[1].'>'; $Block['name'] = $matches[1];
$Block['end'] = '</'.$matches[1].'>';
} }
return $Block; return $Block;
@ -616,12 +651,12 @@ class Parsedown
return; return;
} }
if (stripos($Line['text'], $Block['start']) !== false) # opening tag if (preg_match('/<'.$Block['name'].'([ ][^\/]+)?>/', $Line['text'])) # opening tag
{ {
$Block['depth'] ++; $Block['depth'] ++;
} }
if (stripos($Line['text'], $Block['end']) !== false) # closing tag if (stripos($Line['text'], '</'.$Block['name'].'>') !== false) # closing tag
{ {
if ($Block['depth'] > 0) if ($Block['depth'] > 0)
{ {

View File

@ -2,8 +2,8 @@
Better [Markdown](http://en.wikipedia.org/wiki/Markdown) parser for PHP. Better [Markdown](http://en.wikipedia.org/wiki/Markdown) parser for PHP.
- [Demo](http://parsedown.org/demo) * [Demo](http://parsedown.org/demo)
- [Tests](http://parsedown.org/tests/) * [Test Suite](http://parsedown.org/tests/)
### Features ### Features
@ -12,6 +12,7 @@ Better [Markdown](http://en.wikipedia.org/wiki/Markdown) parser for PHP.
* [GitHub Flavored](https://help.github.com/articles/github-flavored-markdown) * [GitHub Flavored](https://help.github.com/articles/github-flavored-markdown)
* [Tested](https://travis-ci.org/erusev/parsedown) in PHP 5.2, 5.3, 5.4, 5.5, 5.6 and [hhvm](http://www.hhvm.com/) * [Tested](https://travis-ci.org/erusev/parsedown) in PHP 5.2, 5.3, 5.4, 5.5, 5.6 and [hhvm](http://www.hhvm.com/)
* Extensible * Extensible
* [Markdown Extra extension](https://github.com/erusev/parsedown-extra) <sup>new</sup>
### Installation ### Installation
@ -24,3 +25,16 @@ $Parsedown = new Parsedown();
echo $Parsedown->text('Hello _Parsedown_!'); # prints: <p>Hello <em>Parsedown</em>!</p> echo $Parsedown->text('Hello _Parsedown_!'); # prints: <p>Hello <em>Parsedown</em>!</p>
``` ```
More examples in [the wiki](https://github.com/erusev/parsedown/wiki/Usage).
### Questions
**How does Parsedown work?**<br/>
Parsedown recognises that the Markdown syntax is optimised for humans so it tries to read like one. It goes through text line by line. It looks at how lines start to identify blocks. It looks for special characters to identify inline elements.
**Why doesnt Parsedown use namespaces?**<br/>
Using namespaces would mean dropping support for PHP 5.2. Since Parsedown is a single class with an uncommon name, making this trade wouldn't make much sense.
**Who uses Parsedown?**<br/>
[phpDocumentor](http://www.phpdoc.org/), [Bolt CMS](http://bolt.cm/), [RaspberryPi.org](http://www.raspberrypi.org/) and [more](https://www.versioneye.com/php/erusev:parsedown/references).

View File

@ -0,0 +1,5 @@
<!-- single line -->
<p>paragraph</p>
<!--
multiline -->
<p>paragraph</p>

View File

@ -0,0 +1,8 @@
<!-- single line -->
paragraph
<!--
multiline -->
paragraph

View File

@ -1,5 +1,8 @@
<div>_content_</div> <div>_content_</div>
<p>sparse:</p> <p>sparse:</p>
<div> <div>
<div class="inner">
_content_ _content_
</div> </div>
</div>
<p>paragraph</p>

View File

@ -3,5 +3,9 @@
sparse: sparse:
<div> <div>
<div class="inner">
_content_ _content_
</div> </div>
</div>
paragraph

View File

@ -1,28 +0,0 @@
<p>Headings:</p>
<h2 id="overview">Overview</h2>
<p>blah</p>
<H2 id="block">Block Elements</H2>
<p>blah</p>
<h3 id="span">
Span Elements
</h3>
<p>blah</p>
<p>Hr's:</p>
<hr>
<p>blah</p>
<hr/>
<p>blah</p>
<hr />
<p>blah</p>
<hr>
<p>blah</p>
<hr/>
<p>blah</p>
<hr />
<p>blah</p>
<hr class="foo" id="bar" />
<p>blah</p>
<hr class="foo" id="bar"/>
<p>blah</p>
<hr class="foo" id="bar" >
<p>blah</p>

View File

@ -1,39 +0,0 @@
Headings:
<h2 id="overview">Overview</h2>
blah
<H2 id="block">Block Elements</H2>
blah
<h3 id="span">
Span Elements
</h3>
blah
Hr's:
<hr>
blah
<hr/>
blah
<hr />
blah
<hr>
blah
<hr/>
blah
<hr />
blah
<hr class="foo" id="bar" />
blah
<hr class="foo" id="bar"/>
blah
<hr class="foo" id="bar" >
blah

View File

@ -1,4 +0,0 @@
<hr />
<p>attributes:</p>
<hr style="background: #9bd;" />
<p>...</p>

View File

@ -1,7 +0,0 @@
<hr />
attributes:
<hr style="background: #9bd;" />
...

View File

@ -0,0 +1,12 @@
<hr>
<p>paragraph</p>
<hr/>
<p>paragraph</p>
<hr />
<p>paragraph</p>
<hr class="foo" id="bar" />
<p>paragraph</p>
<hr class="foo" id="bar"/>
<p>paragraph</p>
<hr class="foo" id="bar" >
<p>paragraph</p>

View File

@ -0,0 +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