kwattro/markdown-bundle

集成 Sundown 解析器的组件

安装次数: 3,322

依赖: 2

建议者: 0

安全性: 0

星级: 5

关注者: 2

分支: 4

类型:symfony-bundle

dev-master 2014-08-06 10:37 UTC

This package is not auto-updated.

Last update: 2024-09-14 11:40:40 UTC


README

此组件可以让您轻松地在您的 Symfony 应用程序中使用 markdown 解析器。

查看实际应用: http://www.frenchycode.com/billets/3/voir/test_du_kwattromarkdownbundle 状态

此组件处于开发阶段。请随时贡献。

Build Status

待办事项

  • 合并参数与 DI 配置
  • 添加所有可能的扩展到 DI 配置
  • 添加标志功能
  • 将配置文件转换为 .xml
  • 使 Twig 扩展使用 Markdown 类
  • 添加一些测试
  • 结构化文档
  • 请求反馈

开源社区

此组件封装了众多优秀开发者的成果

Sundown 基于 Natacha Porté 的原始 Upskirt 解析器,由 Vicent Marti (@tanoku) 和以下作者进行了许多补充

Ben Noordhuis, Bruno Michel, Joseph Koshy, Krzysztof Kowalczyk, Samuel Bronson,
Shuhei Tanuma

php-sundown 是由 [chobie] (https://github.com/chobie/php-sundown) 制作的 Sundown 项目的 php 封装

安装

在您的服务器上安装 sundown 和 php-sundown

git clone https://github.com/chobie/php-sundown.git php-sundown -b development
cd php-sundown
# this command will fetch submodule and copy neccesary files to src dir and compile it.
rake submodule compile
sudo rake install

# enable the sundown extension by adding the following line to your php.ini
extension=sundown.so

下载 KwattroMarkdownBundle

将以下内容添加到您的 deps 文件中

[KwattroMarkdownBundle]
    git=http://github.com/kwattro/KwattroMarkdownBundle.git
    target=/bundles/Kwattro/MarkdownBundle

然后运行以下命令

php bin/vendors install

注册组件

Kwattro 命名空间添加到自动加载器

# /app/autoload.php
$loader->registerNamespaces(array(
//...
'Kwattro' => __DIR__.'/../vendor/bundles',
));

最后,在您的 AppKernel 中注册组件

# /app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
    //...
    new Kwattro\MarkdownBundle\KwattroMarkdownBundle(),
    );
}

如何使用

在您的 twig 模板中

您可以在 Twig 模板中轻松使用 markdown 解析器

{{ body | markdown }}

在控制器中使用 kwattro_markdown 服务名称

$markdown = $this->container->get('kwattro_markdown');
$string = $body; //Some string to transform
$output = $markdown->render($string);

您可以根据需要自定义扩展和渲染。第二个数组参数用于标志。

在控制器中
$md = $this->container->get('kwattro_markdown');
$string = $body; // some string to transform
$output = $md->render($string, array('autolink' => false), array(), 'xhtml')
在模板中
{{ body | markdown( {'autolink': false}, {}, 'html') }}

语法

有关 Markdown 语法 的更多信息,请访问 markdown 作者的 [网站] (http://daringfireball.net/projects/markdown/)

配置参考

您可以通过 config.yml 文件简单配置组件

kwattro_markdown:
    twig_extension: ~ // default is the twig extension provided by the bundle
    renderer : ~ // default `html` You can choose between html | xhtml | base | custom
    render_class: ~ based off the renderer chosen, you have to specify one if "custom" is chosen
    extensions:
        no_intra_emphasis: false
        tables: true
        fenced_code_blocks: true
        autolink: true
        strikethrough: true
        lax_html_blocks: false
        space_after_headers: true
        superscript: false
    flags:
        filter_html: false
        no_images: false
        no_links: false
        no_styles: false
        safe_links_only: false
        with_toc_data: false
        hard_wrap: true
        xhtml: true