nachonerd/silex-markdown-provider

Silex Service Provider using cebe/markdown

1.0.4 2015-09-12 00:52 UTC

This package is not auto-updated.

Last update: 2024-04-13 15:34:05 UTC


README

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

SensioLabsInsight

Description

Silex Service Provider using cebe/markdown. cebe/markdown was created by Carsten Brandt.

License

GPL-3.0

Requirements

Install

composer require nachonerd/silex-markdown-provider

Usage

Include following line of code somewhere in your initial Silex file (index.php or whatever):

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

Now you have access to instance of cebe/markdown throw $app['nn.markdown'].

Twig Extension

Filters

  • markdown_parse Parse specified text to html
{{ "## Some text"|markdown_parse }}

.....

{{ texttoparse|markdown_parse }}
  • markdown_parse_file Parse specified file to html
{{ "some/file.md"|markdown_parse_file }}

.....

{{ filename|markdown_parse_file }}

Functions

  • markdown_parse_last_file Parse last file in markdown,path directory to html
{{ markdown_parse_last_file() }}

Example

<?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);
    ...