webuni / commonmark-twig-renderer
The Twig renderer for CommonMark PHP implementation
0.2.0
2016-07-14 12:50 UTC
Requires
- php: ^5.5|^7.0
- league/commonmark: ^0.13.2|^0.14
- twig/twig: ^1.17|^2.0@dev
Requires (Dev)
- friendsofphp/php-cs-fixer: ^1.9
- jgm/commonmark: 0.25
- phpunit/phpunit: ^4.0|^5.0
- sllh/php-cs-fixer-styleci-bridge: ^2.0
- symfony/finder: ^2.8|^3.0
- symfony/var-dumper: ^2.8|^3.0
- webuni/commonmark-attributes-extension: dev-master
This package is auto-updated.
Last update: 2024-11-07 04:43:16 UTC
README
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\CommonMarkConverter; use Webuni\CommonMark\TwigRenderer\CommonMarkTwig; $converter = new CommonMarkConverter(); CommonMarkTwig::setTwigRenderer($converter); echo $converter->convertToHtml('# Hello World!');
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 %}