No description, website, or topics provided.
PHP HTML
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
tests
.gitattributes Improve project Jul 14, 2016
.gitignore Updated to the new commonmark 0.11 API Sep 27, 2015
.php_cs Improve project Jul 14, 2016
.scrutinizer.yml Improve project Jul 14, 2016
.styleci.yml Improve project Jul 14, 2016
.travis.yml Fix travis configuration for tests Jul 14, 2016
CHANGELOG.md Improve project Jul 14, 2016
LICENSE Massive improvements Apr 27, 2016
README.md Improve project Jul 14, 2016
composer.json Travis doesn't know ln -r Jul 14, 2016
phpunit.xml.dist Improve project Jul 14, 2016

README.md

CommonMark Twig Renderer

Latest Stable Version Build Status StyleCI Scrutinizer Code Quality SensioLabsInsight

This extension allows you to use Twig templates to render CommonMark document.

Installation

This project can be installed via Composer:

composer require webuni/commonmark-twig-renderer

Usage

    use League\CommonMark\DocParser;
    use League\CommonMark\Environment;
    use Webuni\CommonMark\CommonMarkTwigExtension;
    use Webuni\CommonMark\TwigRenderer;
    
    $environment = Environment::createCommonMarkEnvironment();
    
    $twig = new Twig_Environment(CommonMarkTwigExtension::createTwigLoader()));
    $twig->addExtension(new CommonMarkTwigExtension());
    
    $parser = new DocParser($environment);
    
    // Here's our sample input
    $markdown = '# Hello World!';
    
    $documentAST = $parser->parse($markdown);
    
    $twigRenderer = new TwigRenderer($environment, $twig);
    echo $twigRenderer->renderBlock($documentAST);

Template customization

In Twig, each Commonmark Node is represented by a Twig block. To customize any part of how a node renders, you just need to override the appropriate block.

{% extends 'commonmark.html.twig' %}

{% block header -%}
    {% set content = block('_inline_children') -%}
    <h{{ node.level }}><a name="{{ content|striptags|lower }}"></a>{{ content|raw }}</h{{ node.level }}>
{%- endblock %}