https://github.com/webuni/commonmark-twig-renderer
https://github.com/webuni/commonmark-twig-renderer
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/webuni/commonmark-twig-renderer
- Owner: webuni
- License: mit
- Created: 2015-06-01T13:40:09.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2021-05-06T21:41:44.000Z (about 5 years ago)
- Last Synced: 2024-08-01T05:28:00.153Z (almost 2 years ago)
- Language: PHP
- Size: 40 KB
- Stars: 7
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
CommonMark Twig Renderer
========================
[](https://packagist.org/packages/webuni/commonmark-twig-renderer)
[](https://travis-ci.org/webuni/commonmark-twig-renderer)
[](https://scrutinizer-ci.com/g/webuni/commonmark-twig-renderer/?branch=master)
[](https://insight.sensiolabs.com/projects/4c3133a1-1a5b-4de4-958a-a3cd4b87f10f)
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
-----
```php
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.
```twig
{% extends 'commonmark.html.twig' %}
{% block header -%}
{% set content = block('_inline_children') -%}
{{ content|raw }}
{%- endblock %}
```