parsedown/README.md

104 lines
4.9 KiB
Markdown
Raw Permalink Normal View History

2018-12-28 00:59:37 +03:00
<!-- ![Parsedown](https://i.imgur.com/yE8afYV.png) -->
2015-10-31 01:33:11 +03:00
2018-12-28 03:21:55 +03:00
<p align="center"><img alt="Parsedown" src="https://i.imgur.com/fKVY6Kz.png" width="240" /></p>
2018-12-28 03:19:44 +03:00
<h1>Parsedown</h1>
2018-12-28 02:56:45 +03:00
[![Build Status](https://travis-ci.org/erusev/parsedown.svg)](https://travis-ci.org/erusev/parsedown)
[![Total Downloads](https://poser.pugx.org/erusev/parsedown/d/total.svg)](https://packagist.org/packages/erusev/parsedown)
[![Version](https://poser.pugx.org/erusev/parsedown/v/stable.svg)](https://packagist.org/packages/erusev/parsedown)
[![License](https://poser.pugx.org/erusev/parsedown/license.svg)](https://packagist.org/packages/erusev/parsedown)
2015-03-18 21:43:30 +03:00
2018-12-28 01:41:14 +03:00
Better Markdown Parser in PHP - <a href="http://parsedown.org/demo">Demo</a>.
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
2018-12-28 01:36:04 +03:00
* [Super Fast](http://parsedown.org/speed)
2015-07-15 09:21:38 +03:00
* Extensible
2020-01-22 00:07:12 +03:00
* [GitHub flavored](https://github.github.com/gfm)
* [Tested](http://parsedown.org/tests/) in 5.3 to 7.3
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
2018-12-28 14:17:22 +03:00
Install the [composer package]:
composer require erusev/parsedown
2018-12-28 14:17:22 +03:00
Or download the [latest release] and 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
2018-12-28 00:51:07 +03: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>
2018-12-28 00:51:07 +03:00
```
You can also parse inline markdown only:
```php
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-12-28 01:36:04 +03:00
2018-02-28 20:01:31 +03:00
```php
2018-12-28 13:50:30 +03:00
$Parsedown->setSafeMode(true);
2018-02-28 20:01:31 +03:00
```
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-12-28 01:36:04 +03:00
> **WARNING:** This method isn't safe from XSS!
2018-03-01 21:44:11 +03:00
If you wish to escape HTML **in trusted input**, you can use the following:
2018-12-28 01:36:04 +03:00
2018-03-01 21:44:11 +03:00
```php
2018-12-28 13:50:30 +03:00
$Parsedown->setMarkupEscaped(true);
2018-03-01 21:44:11 +03:00
```
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
2019-03-12 23:49:21 +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/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).
2020-08-09 17:12:21 +03:00
**What else should I know?**
I also make [Nota](https://nota.md/) — a writing app designed for Markdown files :)