mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
a06cdfb814 | |||
6bee326c92 | |||
3fe867d294 | |||
f08d017bcb | |||
e61a6114b0 | |||
9ed72ccd09 | |||
09e1184d9f | |||
2de60a9a8b | |||
73a75299f5 |
@ -32,8 +32,7 @@ class Parsedown
|
||||
$this->DefinitionData = array();
|
||||
|
||||
# standardize line breaks
|
||||
$text = str_replace("\r\n", "\n", $text);
|
||||
$text = str_replace("\r", "\n", $text);
|
||||
$text = str_replace(array("\r\n", "\r"), "\n", $text);
|
||||
|
||||
# remove surrounding line breaks
|
||||
$text = trim($text, "\n");
|
||||
@ -482,7 +481,7 @@ class Parsedown
|
||||
$level ++;
|
||||
}
|
||||
|
||||
if ($level > 6 or $Line['text'][$level] !== ' ')
|
||||
if ($level > 6)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -892,6 +891,11 @@ class Parsedown
|
||||
|
||||
protected function blockTableContinue($Line, array $Block)
|
||||
{
|
||||
if (isset($Block['interrupted']))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ($Line['text'][0] === '|' or strpos($Line['text'], '|'))
|
||||
{
|
||||
$Elements = array();
|
||||
@ -901,9 +905,9 @@ class Parsedown
|
||||
$row = trim($row);
|
||||
$row = trim($row, '|');
|
||||
|
||||
$cells = explode('|', $row);
|
||||
preg_match_all('/(?:(\\\\[|])|[^|`]|`[^`]+`|`)+/', $row, $matches);
|
||||
|
||||
foreach ($cells as $index => $cell)
|
||||
foreach ($matches[0] as $index => $cell)
|
||||
{
|
||||
$cell = trim($cell);
|
||||
|
||||
@ -1298,7 +1302,7 @@ class Parsedown
|
||||
return;
|
||||
}
|
||||
|
||||
if (preg_match('/^\([ ]*([^ ]+?)(?:[ ]+(".+?"|\'.+?\'))?[ ]*\)/', $remainder, $matches))
|
||||
if (preg_match('/^[(]((?:[^ (]|[(][^ )]+[)])+)(?:[ ]+("[^"]+"|\'[^\']+\'))?[)]/', $remainder, $matches))
|
||||
{
|
||||
$Element['attributes']['href'] = $matches[1];
|
||||
|
||||
@ -1507,7 +1511,7 @@ class Parsedown
|
||||
# Read-only
|
||||
|
||||
protected $specialCharacters = array(
|
||||
'\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!',
|
||||
'\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!', '|',
|
||||
);
|
||||
|
||||
protected $StrongRegex = array(
|
||||
|
18
README.md
18
README.md
@ -10,9 +10,8 @@ Better Markdown Parser in PHP
|
||||
* [Consistent](http://parsedown.org/consistency)
|
||||
* [GitHub flavored](https://help.github.com/articles/github-flavored-markdown)
|
||||
* [Tested](http://parsedown.org/tests/) in PHP 5.2, 5.3, 5.4, 5.5, 5.6 and [hhvm](http://www.hhvm.com/)
|
||||
* Extensible
|
||||
* [Extensible](https://github.com/erusev/parsedown/wiki/Writing-Extensions)
|
||||
* [Markdown Extra extension](https://github.com/erusev/parsedown-extra)
|
||||
* [JavaScript port](https://github.com/hkdobrev/parsedown.js) under development
|
||||
|
||||
### Installation
|
||||
|
||||
@ -30,17 +29,20 @@ More examples in [the wiki](https://github.com/erusev/parsedown/wiki/Usage) and
|
||||
|
||||
### Questions
|
||||
|
||||
**How does Parsedown work?**<br/>
|
||||
**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).
|
||||
|
||||
**Why doesn’t Parsedown use namespaces?**<br/>
|
||||
It'd mean no support for PHP 5.2. Would it be worth it?
|
||||
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.
|
||||
|
||||
**Is Parsedown compliant with CommonMark?**
|
||||
|
||||
**Is Parsedown compliant with CommonMark?**<br/>
|
||||
The majority of the CommonMark tests pass. Most of the tests that don't pass deal with cases that are quite extreme. Yet, we are working on them. As CommonMark matures, compliance should improve.
|
||||
|
||||
**Who uses Parsedown?**<br/>
|
||||
**Who uses Parsedown?**
|
||||
|
||||
[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).
|
||||
|
||||
**How can I help?**<br/>
|
||||
**How can I help?**
|
||||
|
||||
Use the project, tell friends about it and if you feel generous, [donate some money](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=528P3NZQMP8N2).
|
||||
|
@ -1,4 +1,4 @@
|
||||
<p><a href="http://example.com">link</a> and <a href="/tests/">another link</a></p>
|
||||
<p><a href="http://example.com">link</a> and <a href="/url-with-(parentheses)">another link</a></p>
|
||||
<p><a href="http://example.com"><code>link</code></a></p>
|
||||
<p><a href="http://example.com"><img src="http://parsedown.org/md.png" alt="MD Logo" /></a></p>
|
||||
<p><a href="http://example.com"><img src="http://parsedown.org/md.png" alt="MD Logo" /> and text</a></p>
|
@ -1,4 +1,4 @@
|
||||
[link](http://example.com) and [another link](/tests/)
|
||||
[link](http://example.com) and [another link](/url-with-(parentheses))
|
||||
|
||||
[`link`](http://example.com)
|
||||
|
||||
|
@ -1 +1,4 @@
|
||||
<p><a href="http://example.com" title="Title">single quotes</a> and <a href="http://example.com" title="Title">double quotes</a></p>
|
||||
<p><a href="http://example.com" title="Title">single quotes</a></p>
|
||||
<p><a href="http://example.com" title="Title">double quotes</a></p>
|
||||
<p><a href="http://example.com" title="2 Words">space</a></p>
|
||||
<p><a href="http://example.com/url-(parentheses)" title="Title">parentheses</a></p>
|
@ -1 +1,7 @@
|
||||
[single quotes](http://example.com 'Title') and [double quotes](http://example.com "Title")
|
||||
[single quotes](http://example.com 'Title')
|
||||
|
||||
[double quotes](http://example.com "Title")
|
||||
|
||||
[space](http://example.com "2 Words")
|
||||
|
||||
[parentheses](http://example.com/url-(parentheses) "Title")
|
@ -11,8 +11,12 @@
|
||||
<td><del>cell</del> 1.2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>cell</code> 2.1</td>
|
||||
<td>cell 2.2</td>
|
||||
<td><code>|</code> 2.1</td>
|
||||
<td>| 2.2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>\|</code> 2.1</td>
|
||||
<td><a href="/">link</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
@ -1,4 +1,5 @@
|
||||
| _header_ 1 | header 2 |
|
||||
| ------------ | ------------ |
|
||||
| _cell_ 1.1 | ~~cell~~ 1.2 |
|
||||
| `cell` 2.1 | cell 2.2 |
|
||||
| `|` 2.1 | \| 2.2 |
|
||||
| `\|` 2.1 | [link](/) |
|
Reference in New Issue
Block a user