yivoff/commonmark-bundle
Composer 安装命令:
composer require yivoff/commonmark-bundle
包简介
Symfony bundle integrating League CommonMark for Symfony 6.2+ applications
README 文档
README
A Symfony 5+ bundle to integrate league/commonmark v2, allowing you to set multiple Commonmark converters.
Requirements
This bundle requires PHP 8+ and Symfony 5+.
Installation
composer require yivoff/commonmark-bundle
If for some reason you are running without Symfony Flex, enable the bundle as
usual adding Yivoff\CommonmarkBundle\YivoffCommonmarkBundle to the bundle's array.
Configuration
You'll need to enable at least one converter to use the bundle.
Create a YAML configuration file at path config/packages/aymdev_commonmark.yaml.
Here is an example configuration declaring 2 converters:
yivoff_commonmark: converters: commonmark: options: commonmark: enable_em: false github: type: github my_custom: type: custom extensions: - League\CommonMark\Extension\Autolink\AutolinkExtension - League\CommonMark\Extension\InlinesOnly\InlinesOnlyExtension
Setting up at least one converter is mandatory, but all settings are optional. By default,
a converter without setting a type will be created as a CommonMark converter.
Converter type
The type key can be used to choose between a CommonMark, a GitHub Flavoured or a Custom converter.
By default, if not type is chosen, CommonMark will be chosen.
Converter options
You can use the options key holds the configuration passed to the converter, as an array.
Check the CommonMark documentation to learn more about the available options.
Converter extensions
The CommonMark and Github Flavoured have a predefined set of extensions installed, which cannot be changed.
But custom starts with no extensions, and you pick and choose
which extensions you want to enable using the
extensions key.
This key has no effect on github or commonmark type converters.
Using the converters
As services
Each of the defined converters is available as a service within the container.
The id is generated with the following format: yivoff_commonmark.converters.converter_name.
For the converters in the configuration example three services would be generated:
yivoff_commonmark.converters.commonmarkyivoff_commonmark.converters.githubyivoff_commonmark.converters.my_custom
Additionally, the bundle registers an alias for each service, so one can use the service directly for autowiring.
Again, for the above example the registered aliases would be:
League\CommonMark\ConverterInterface $commonmarkLeague\CommonMark\ConverterInterface $githubLeague\CommonMark\ConverterInterface $myCustom
Usage in templates
The bundle defines a Twig filter: commonmark.
If you have defined multiple converters, you need to pass the name of the converter you want to use:
{{ some_markdown_content|commonmark('github') }}
But If you have only one converter defined, the parameter can be omitted.
{{ some_markdown_content|commonmark }}
yivoff/commonmark-bundle 适用场景与选型建议
yivoff/commonmark-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.43k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 08 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 yivoff/commonmark-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yivoff/commonmark-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.43k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-08-24