erusev/parsedown
Composer 安装命令:
composer require erusev/parsedown
包简介
Parser for Markdown.
README 文档
README
Better Markdown Parser in PHP — demo
Features
- One file
- No dependencies
- Super fast
- Extensible
- GitHub flavored
- Tested in PHP 7.1+
- Markdown Extra extension
Installation
Install the composer package:
composer require erusev/parsedown
Or download the latest release and include Parsedown.php
Example
$Parsedown = new Parsedown(); 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>!
More examples in the wiki and in this video tutorial.
Security
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.
To tell Parsedown that it is processing untrusted user-input, use the following:
$Parsedown->setSafeMode(true);
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.
In both cases you should strongly consider employing defence-in-depth measures, like deploying a Content-Security-Policy (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.
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.
Escaping HTML
WARNING: This method is not safe from XSS!
If you wish to escape HTML in trusted input, you can use the following:
$Parsedown->setMarkupEscaped(true);
Beware that this still allows users to insert unsafe scripting vectors, ex: [xss](javascript:alert%281%29).
Questions
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 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).
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 it compliant with CommonMark?
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.
Who uses it?
Laravel Framework, Bolt CMS, Grav CMS, Herbie CMS, Kirby CMS, October CMS, Pico CMS, Statamic CMS, phpDocumentor, RaspberryPi.org, Symfony Demo and more.
How can I help?
Use it, star it, share it and if you feel generous, sponsor me.
What else should I know?
I also make Nota — a notes app designed for local Markdown files.
erusev/parsedown 适用场景与选型建议
erusev/parsedown 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 156.14M 次下载、GitHub Stars 达 15.03k, 最近一次更新时间为 2013 年 07 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「parser」 「markdown」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 erusev/parsedown 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 erusev/parsedown 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 erusev/parsedown 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
An MT940 bank statement parser for PHP
Adds more BBCode
Laravel integration for the jsonapi.org parser
A modern HTML DOM parser for PHP using DOMDocument and Symfony CssSelector.
统计信息
- 总下载量: 156.14M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15119
- 点击次数: 21
- 依赖项目数: 837
- 推荐数: 30
其他信息
- 授权协议: MIT
- 更新时间: 2013-07-10