Skip to content
Markdown support for Twig
Branch: master
Clone or download
fabpot minor #4 Fix league/commonmark constraint (colinodell)
This PR was merged into the 1.0-dev branch.

Discussion
----------

Fix league/commonmark constraint

The `League\CommonMark\CommonMarkConverter` class was introduced in version 0.4.0.  (It used a different namespace in previous versions.)  I have promised to not break backward-compatibility in any future 1.x release per https://github.com/thephpleague/commonmark#versioning so this constraint should be safe.

Commits
-------

5d0b95b Fix league/commonmark constraint
Latest commit 52d0d44 Feb 25, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src tweaked default configuration for HTML to Markdown Feb 25, 2019
test strip tags by default in html_to_markdown Feb 25, 2019
.gitignore
.php_cs.dist
CHANGELOG.md
LICENSE added initial version Feb 24, 2019
README.md
composer.json
phpunit.xml.dist added initial version Feb 24, 2019

README.md

Twig Markdown Extension

This package provides a Markdown to HTML filter (markdown) and an HTML to Markdown filter (html_to_markdown) for Twig and a Symfony bundle.

If you are not using Symfony, register the extension on Twig's Environment manually:

use Twig\Markdown\MarkdownExtension;
use Twig\Environment;

$twig = new Environment(...);
$twig->addExtension(new MarkdownExtension());

Use the markdown and html_to_markdown filters from a Twig template:

{% filter markdown %}
Title
======

Hello!
{% endfilter %}

{% filter html_to_markdown %}
    <html>
        <h1>Hello!</h1>
    </html>
{% endfilter %}

Note that you can indent the Markdown content as leading whitespaces will be removed consistently before conversion:

{% filter markdown %}
    Title
    ======

    Hello!
{% endfilter %}

You can also add some options by passing them as an argument to the filter:

{% filter html_to_markdown({hard_break: false}) %}
    <html>
        <h1>Hello!</h1>
    </html>
{% endfilter %}

You can also use the filters on an included file:

{{ include('some_template.html.twig')|html_to_markdown }}

{{ include('some_template.markdown.twig')|markdown }}
You can’t perform that action at this time.