Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/twigphp/markdown-extension
[DEPRECATED] Markdown support for Twig
https://github.com/twigphp/markdown-extension
markdown php twig twig-extension
Last synced: 3 months ago
JSON representation
[DEPRECATED] Markdown support for Twig
- Host: GitHub
- URL: https://github.com/twigphp/markdown-extension
- Owner: twigphp
- License: mit
- Archived: true
- Created: 2019-02-24T19:11:02.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-17T05:35:40.000Z (about 5 years ago)
- Last Synced: 2024-07-20T10:07:39.770Z (4 months ago)
- Topics: markdown, php, twig, twig-extension
- Language: PHP
- Homepage:
- Size: 18.6 KB
- Stars: 102
- Watchers: 6
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Twig Markdown Extension
=======================**WARNINIG**: This package is deprecate; migrate to `twig/markdown-extra` instead.
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:```php
use Twig\Markdown\MarkdownExtension;
use Twig\Environment;$twig = new Environment(...);
$twig->addExtension(new MarkdownExtension());
```You must also register the extension runtime (skip this step if you are using
Symfony or a framework with a Twig integration):```php
use Twig\Markdown\DefaultMarkdown;
use Twig\Markdown\MarkdownRuntime;
use Twig\RuntimeLoader\RuntimeLoaderInterface;$twig->addRuntimeLoader(new class implements RuntimeLoaderInterface {
public function load($class) {
if (MarkdownRuntime::class === $class) {
return new MarkdownRuntime(new DefaultMarkdown());
}
}
});
```Use the `markdown` and `html_to_markdown` filters from a Twig template:
```twig
{% filter markdown %}
Title
======Hello!
{% endfilter %}{% filter html_to_markdown %}
Hello!
{% endfilter %}
```Note that you can indent the Markdown content as leading whitespaces will be
removed consistently before conversion:```twig
{% filter markdown %}
Title
======Hello!
{% endfilter %}
```You can also add some options by passing them as an argument to the filter:
```twig
{% filter html_to_markdown({hard_break: false}) %}
Hello!
{% endfilter %}
```You can also use the filters on an included file:
```twig
{{ include('some_template.html.twig')|html_to_markdown }}{{ include('some_template.markdown.twig')|markdown }}
```