mheap/silex-markdown

This package is abandoned and no longer maintained. No replacement package was suggested.

Markdown extension for Silex

3.0.0 2017-10-05 11:17 UTC

This package is auto-updated.

Last update: 2020-11-26 18:29:45 UTC


README

Build Status

Requirements

This extension only works with PHP 7.1+ and Silex 2. Version 1.0.0 is compatible with Silex 1.

Installation

Install with composer:

composer require mheap/silex-markdown

Usage

First, you need to register the Markdown extension. This will use the default settings for the extension.

$app->register(new \SilexMarkdown\MarkdownExtension());

If you'd like to disable certain transformations, you can provide them when registering the extension. This will not convert headers from markdown to HTML.

$app->register(new MarkdownExtension(), array(
    'markdown.features'   => array(
        'header' => false,
    )
));

To render markdown, use $app['markdown']:

$app->get('/', function() use($app) {
    $html = $app['markdown']->transform('# Hello World'); // <h1>Hello World</h1>
});

If you're using Twig via Silex\Provider\TwigServiceProvider(), a markdown filter will be automatically registered for you. This allows you do do the following:

// In your route
$app->get('/', function() use($app) {
    $text = '# Hello World';
    $html = $app['twig']->render('example.twig', array(
        'input' => $text
    ));
});
// In your twig file
{{ input | markdown }}

Running the tests

There are no external dependencies for this library. Just composer install then run ./vendor/bin/phpunit