Skip to content

nachonerd/silex-markdown-provider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Silex Markdown Provider

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