Skip to content

Commit

Permalink
minor twigphp#3361 Update html_to_markdown.rst (ThomasLandauer)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.x branch.

Discussion
----------

Update html_to_markdown.rst

Integrating some findings of twigphp#3357

Commits
-------

4b8e189 Update html_to_markdown.rst
  • Loading branch information
fabpot committed Jul 5, 2020
2 parents 92398cb + 4b8e189 commit 2505176
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions doc/filters/html_to_markdown.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,18 @@ The ``html_to_markdown`` filter converts a block of HTML to Markdown:
</html>
{% endapply %}
You can also add some options by passing them as an argument to the filter:
You can also use the filter on an entire template which you ``include``:

.. code-block:: twig
{% apply html_to_markdown({hard_break: false}) %}
<html>
<h1>Hello!</h1>
</html>
{% endapply %}
.. note::

The options are the ones provided by the ``league/html-to-markdown`` package.
{{ include('some_template.html.twig')|html_to_markdown }}
You can also use the filter on an included file:
Output:

.. code-block:: twig
.. code-block:: markdown
{{ include('some_template.html.twig')|html_to_markdown }}
Hello!
======
.. note::

Expand All @@ -43,8 +36,14 @@ You can also use the filter on an included file:
$ composer req twig/markdown-extra
Then, use the ``twig/extra-bundle`` on Symfony projects or add the extension
explicitly on the Twig environment::
On Symfony projects, you can automatically enable it by installing the
``twig/extra-bundle``:

.. code-block:: bash
$ composer req twig/extra-bundle
Or add the extension explicitly on the Twig environment::

use Twig\Extra\Markdown\MarkdownExtension;

Expand All @@ -64,3 +63,22 @@ You can also use the filter on an included file:
}
}
});

``html_to_markdown`` is just a frontend; the actual conversion is done by one of
the following compatible libraries, from which you can choose:

* [erusev/parsedown](https://github.com/erusev/parsedown)
* [thephpleague/html-to-markdown](https://github.com/thephpleague/html-to-markdown)
* [michelf/php-markdown](https://github.com/michelf/php-markdown)

Depending on the library, you can also add some options by passing them as an argument
to the filter. Example for ``league/html-to-markdown``:

.. code-block:: twig
{% apply html_to_markdown({hard_break: false}) %}
<html>
<h1>Hello!</h1>
</html>
{% endapply %}

0 comments on commit 2505176

Please sign in to comment.