knplabs/knp-markdown-bundle
最新稳定版本:1.10.0
Composer 安装命令:
composer require knplabs/knp-markdown-bundle
包简介
Knplabs markdown bundle transforms markdown into html
README 文档
README
WARNING: This bundle is abandoned in favor of markdown_to_html Twig filter. Please, consider using it instead. Migration should be easy because it also supports
michelf/php-markdownMarkdown parser that is used in this project under the hood.
Provide markdown conversion (based on Michel Fortin work) to your Symfony projects.
INSTALLATION
Add KnpMarkdownBundle to your project via Composer:
composer require knplabs/knp-markdown-bundle
If you're not using Symfony Flex, you will also need to enable
the bundle in your app/AppKernel.php file
(new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle()).
That's it! Start using it!
USAGE
Once the bundle is installed, you can autowire a MarkdownParserInterface
into any service or controller:
use Knp\Bundle\MarkdownBundle\MarkdownParserInterface; // from inside a controller public function index(MarkdownParserInterface $parser) { $html = $parser->transformMarkdown($text); } // or from inside a service private $parser; public function __construct(MarkdownParserInterface $parser) { $this->parser = $parser; } public function someMethod() { $html = $this->parser->transformMarkdown($text); }
There is also a public markdown.parser service you can use.
In Twig, you can use the markdown filter:
{# Use default parser #} {{ my_data|markdown }} {# If my_data is entered by a user, escape HTML tags before printing it #} {{ my_data|escape|markdown }} {# or strip HTML tags #} {{ my_data|striptags|markdown }} {# Or select specific parser #} {{ my_data|markdown('parserName') }}
Change the parser implementation
Create a service implementing Knp\Bundle\MarkdownBundle\MarkdownParserInterface,
then configure the bundle to use it:
# Symfony 3: app/config/config.yml # Symfony 4: config/packages/knp_markdown.yaml (you'll need to create this) knp_markdown: parser: service: my.markdown.parser
Alternatively if you are using the markdown.parser.sundown there are
options for enabling sundown extensions and render flags, see the
default Configuration with:
php bin/console config:dump-reference knp_markdown
This bundle comes with 5 parser services, 4 based on the same algorithm but providing different levels of compliance to the markdown specification, and one which is uses the php sundown extension:
- markdown.parser.max // fully compliant = slower (default implementation)
- markdown.parser.medium // expensive and uncommon features dropped
- markdown.parser.light // expensive features dropped
- markdown.parser.min // most features dropped = faster
- markdown.parser.sundown // faster and fully compliant (recommended)
markdown.parser.sundown requires the php sundown extension.
For more details, see the implementations in Parser/Preset.
knplabs/knp-markdown-bundle 适用场景与选型建议
knplabs/knp-markdown-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.93M 次下载、GitHub Stars 达 425, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「markdown」 「knp」 「knplabs」 「bundle」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 knplabs/knp-markdown-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 knplabs/knp-markdown-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 knplabs/knp-markdown-bundle 相关的其它包
同方向 / 同关键字的高下载量 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
Configure your knp menus with yaml files accross your project bundles
KnpMenu for CakePHP 3
KNP Menu Bundle integrations with Superdesk Publisher.
Adds more BBCode
PHP Library to interact with the NPPES NPI Registry API
统计信息
- 总下载量: 5.93M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 432
- 点击次数: 25
- 依赖项目数: 50
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04