Update html_to_markdown.rst

This commit is contained in:
Thomas Landauer
2020-06-28 23:31:56 +02:00
committed by Fabien Potencier
parent f32950c872
commit 4b8e1891bd
+35 -17
View File
@@ -14,26 +14,19 @@ 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:
.. 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.
You can also use the filter on an included file:
You can also use the filter on an entire template which you ``include``:
.. code-block:: twig
{{ include('some_template.html.twig')|html_to_markdown }}
Output:
.. code-block:: markdown
Hello!
======
.. note::
The ``html_to_markdown`` filter is part of the ``MarkdownExtension`` which
@@ -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;
@@ -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 %}