Coder Social home page Coder Social logo

markdown-extension's Introduction

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:

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):

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:

{% 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 }}

markdown-extension's People

Contributors

colinodell avatar fabpot avatar harikt avatar jeremiesamson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.