parsedown/README.md

107 lines
4.9 KiB
Markdown
Raw Normal View History

2018-12-27 23:23:17 +03:00
![Parsedown Logo](https://i.imgur.com/yE8afYV.png)
2015-10-31 01:33:11 +03:00
2018-12-28 00:46:53 +03:00
<h3 align="center">Parsedown</h3>
2018-12-28 00:46:53 +03:00
<p align="center">Better Markdown Editor in PHP<p>
2015-03-18 21:43:30 +03:00
2018-12-28 00:46:53 +03:00
<p align="center">
<a href="http://parsedown.org/demo">Demo</a> |
<a href="http://parsedown.org/speed">Benchmarks</a> |
<a href="http://parsedown.org/tests/">Tests</a> |
<a href="https://github.com/erusev/parsedown/wiki/">Wiki</a>
</p>
<p align="center">
<a href="https://travis-ci.org/erusev/parsedown">
<img src="https://img.shields.io/travis/erusev/parsedown/master.svg?style=flat-square">
</a>
<a href="https://packagist.org/packages/erusev/parsedown">
<img src="http://img.shields.io/packagist/dt/erusev/parsedown.svg?style=flat-square">
</a>
</p>
2013-11-23 17:58:58 +04:00
2018-12-27 23:32:54 +03:00
## Features
2013-11-23 17:58:58 +04:00
2016-07-27 11:05:24 +03:00
* One File
2017-11-06 17:54:00 +03:00
* No Dependencies
2015-07-15 09:21:38 +03:00
* Super Fast
* Extensible
2016-07-27 11:05:24 +03:00
* [GitHub flavored](https://help.github.com/articles/github-flavored-markdown)
2018-04-02 21:52:26 +03:00
* Tested in 5.3 to 7.2 and in HHVM
2015-01-10 15:53:08 +03:00
* [Markdown Extra extension](https://github.com/erusev/parsedown-extra)
2013-07-23 11:36:28 +04:00
2018-12-27 23:32:54 +03:00
## Installation
#### Composer
Install the [composer package] by running the following command:
composer require erusev/parsedown
#### Manual
1. Download the "Source code" from the [latest release]
2. Include `Parsedown.php`
[composer package]: https://packagist.org/packages/erusev/parsedown "The Parsedown package on packagist.org"
[latest release]: https://github.com/erusev/parsedown/releases/latest "The latest release of Parsedown"
2013-07-24 00:32:45 +04:00
2018-12-27 23:32:54 +03:00
## Example
2013-07-24 00:32:45 +04:00
2014-02-21 04:49:59 +04:00
``` php
2014-05-17 18:13:00 +04:00
$Parsedown = new Parsedown();
2013-07-24 00:32:45 +04:00
2014-05-17 18:13:00 +04:00
echo $Parsedown->text('Hello _Parsedown_!'); # prints: <p>Hello <em>Parsedown</em>!</p>
// you can also parse inline markdown only
echo $Parsedown->line('Hello _Parsedown_!'); # prints: Hello <em>Parsedown</em>!
2013-11-13 03:38:29 +04:00
```
2014-05-16 02:15:21 +04:00
2015-07-03 17:06:52 +03:00
More examples in [the wiki](https://github.com/erusev/parsedown/wiki/) and in [this video tutorial](http://youtu.be/wYZBY8DEikI).
2014-05-17 18:13:00 +04:00
2018-12-27 23:32:54 +03:00
## Security
2017-10-22 16:00:43 +03:00
2018-03-01 22:54:58 +03:00
Parsedown is capable of escaping user-input within the HTML that it generates. Additionally Parsedown will apply sanitisation to additional scripting vectors (such as scripting link destinations) that are introduced by the markdown syntax itself.
2018-03-01 21:44:11 +03:00
To tell Parsedown that it is processing untrusted user-input, use the following:
2018-02-28 20:01:31 +03:00
```php
$parsedown = new Parsedown;
$parsedown->setSafeMode(true);
```
2018-03-01 22:54:58 +03:00
If instead, you wish to allow HTML within untrusted user-input, but still want output to be free from XSS it is recommended that you make use of a HTML sanitiser that allows HTML tags to be whitelisted, like [HTML Purifier](http://htmlpurifier.org/).
2018-03-01 21:44:11 +03:00
2018-03-02 04:13:58 +03:00
In both cases you should strongly consider employing defence-in-depth measures, like [deploying a Content-Security-Policy](https://scotthelme.co.uk/content-security-policy-an-introduction/) (a browser security feature) so that your page is likely to be safe even if an attacker finds a vulnerability in one of the first lines of defence above.
2018-03-01 21:44:11 +03:00
#### Security of Parsedown Extensions
Safe mode does not necessarily yield safe results when using extensions to Parsedown. Extensions should be evaluated on their own to determine their specific safety against XSS.
2018-12-27 23:32:54 +03:00
## Escaping HTML
2018-03-01 21:44:11 +03:00
> ⚠️  **WARNING:** This method isn't safe from XSS!
If you wish to escape HTML **in trusted input**, you can use the following:
```php
$parsedown = new Parsedown;
$parsedown->setMarkupEscaped(true);
```
Beware that this still allows users to insert unsafe scripting vectors, such as links like `[xss](javascript:alert%281%29)`.
2017-10-22 16:00:43 +03:00
2018-12-27 23:32:54 +03:00
## Questions
2014-05-16 02:15:21 +04:00
2015-01-13 16:18:35 +03:00
**How does Parsedown work?**
2016-10-25 17:22:17 +03:00
It tries to read Markdown like a human. First, it looks at the lines. Its 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).
2014-05-16 02:15:21 +04:00
2015-01-13 16:28:18 +03:00
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.
2015-01-13 16:18:35 +03:00
2015-01-24 02:26:59 +03:00
**Is it compliant with CommonMark?**
2014-05-16 02:15:21 +04:00
2015-01-24 05:54:01 +03:00
It passes most of the CommonMark tests. Most of the tests that don't pass deal with cases that are quite uncommon. Still, as CommonMark matures, compliance should improve.
2014-09-09 15:30:17 +04:00
2015-01-24 02:26:59 +03:00
**Who uses it?**
2015-01-13 16:18:35 +03:00
[Laravel Framework](https://laravel.com/), [Bolt CMS](http://bolt.cm/), [Grav CMS](http://getgrav.org/), [Herbie CMS](http://www.getherbie.org/), [Kirby CMS](http://getkirby.com/), [October CMS](http://octobercms.com/), [Pico CMS](http://picocms.org), [Statamic CMS](http://www.statamic.com/), [phpDocumentor](http://www.phpdoc.org/), [RaspberryPi.org](http://www.raspberrypi.org/), [Symfony demo](https://github.com/symfony/symfony-demo) and [more](https://packagist.org/packages/erusev/parsedown/dependents).
2014-12-10 18:19:05 +03:00
2015-01-24 02:27:48 +03:00
**How can I help?**
2015-01-13 16:18:35 +03:00
2015-06-15 00:10:09 +03:00
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).