在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):KnpLabs/KnpMarkdownBundle开源软件地址(OpenSource Url):https://github.com/KnpLabs/KnpMarkdownBundle开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):
Provide markdown conversion (based on Michel Fortin work) to your Symfony projects. INSTALLATIONAdd KnpMarkdownBundle to your project via Composer:
If you're not using Symfony Flex, you will also need to enable
the bundle in your That's it! Start using it! USAGEOnce the bundle is installed, you can autowire a 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 In Twig, you can use the {# 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 implementationCreate a service implementing # 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
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:
For more details, see the implementations in Parser/Preset. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论