Silex Service Provider using cebe/markdown. cebe/markdown was created by Carsten Brandt.
GPL-3.0
- PHP version 5.4
- Composer
- SILEX
- Synfony Finder
- cebe/markdown
- PHP Unit 4.7.x (optional)
- PHP_CodeSniffer 2.x (optional)
composer require nachonerd/silex-markdown-provider
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'].
- 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 }}
- markdown_parse_last_file Parse last file in markdown,path directory to 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);
...