nachonerd/silex-markdown-provider

使用 cebe/markdown 的 Silex 服务提供者

1.0.4 2015-09-12 00:52 UTC

This package is not auto-updated.

Last update: 2024-09-28 17:54:44 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License Build Status Code Climate Test Coverage Minimum PHP Version

SensioLabsInsight

描述

Silex 服务提供者使用 cebe/markdown. cebe/markdown 由 Carsten Brandt 创建。

许可证

GPL-3.0

要求

安装

composer require nachonerd/silex-markdown-provider

使用方法

在您的初始 Silex 文件(index.php 或类似文件)中包含以下行代码:

...
$app->register(
    new \NachoNerd\Silex\Markdown\Provider(),
    array(
        "nn.markdown.path" => __DIR__,
        "nn.markdown.flavor" => 'extra',
        "nn.markdown.filter" => '/\.md/'
    )
);
...

现在您可以通过 $app['nn.markdown'] 访问 cebe/markdown 的实例。

Twig 扩展

过滤器

  • markdown_parse 将指定的文本解析为 HTML
{{ "## Some text"|markdown_parse }}

.....

{{ texttoparse|markdown_parse }}
  • markdown_parse_file 将指定的文件解析为 HTML
{{ "some/file.md"|markdown_parse_file }}

.....

{{ filename|markdown_parse_file }}

函数

  • markdown_parse_last_file 将最后的 markdown 文件解析为 HTML,路径目录到 HTML
{{ markdown_parse_last_file() }}

示例

<?php
    require_once __DIR__.'/../vendor/autoload.php';

    $app = new Silex\Application();

    // Considering the config.yml files is in the same directory as index.php
    $app->register(
        new \NachoNerd\Silex\Finder\Provider(),
        array(
            "nn.markdown.path" => __DIR__,
            "nn.markdown.flavor" => original,
            "nn.markdown.filter" => '/\.md/'
        )
    );
    $app->boot();

    ...
    // traditional markdown and parse full text
    $parser = $app[nn.markdown];
    $hmtl = $parser->parse($markdown);
    $hmtl = $parser->parseFile($filename);
    $finder = $parser->getAllFiles($filename);
    $finder = $parser->getNLastFiles(10);
    ...