Twig Markdown

Component ID

2507905

Component name

Twig Markdown

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Component created

Component changed

Component body

The Twig Markdown module Integrates the aptoma/twig-markdown library with Drupal which will add support for markdown in your twig files.

It is hard wired to use the thephpleague/commonmark library for markdown processing.

Installation

This module uses dependent services to load the aptoma twig extension. The aptoma twig markdown extension is a library that needs required via composer.
I suggest using composer manager to install the required php libraries.

# Download composer manager with drush.
drush dl composer_manager
# Enable composer manager.
drush en -y composer_manager
# Override drupal's composer.json file to include contrib modules' composer requirements.
drush composer-manager-init
# Enable the Twig Markdown module.
drush en -y twig_markdown
# The following commands should be run from the /core folder.
cd core
composer drupal-update league/commonmark
composer drupal-update aptoma/twig-markdown

Usage

  • Filter support `{{ "# Heading Level 1"|markdown }}`
  • Tag support `{% markdown %}{% endmarkdown %}`

When used as a tag, the indentation level of the first line sets the default indentation level for the rest of the tag content.
From this indentation level, all same indentation or outdented levels text will be transformed as regular text.

This feature allows you to write your Markdown content at any indentation level without caring of Markdown internal transformation:

<div>
    <h1 class="someClass">{{ title }}</h1>

    {% markdown %}
    This is a list that is indented to match the context around the markdown tag:

    * List item 1
    * List item 2
        * Sub List Item
            * Sub Sub List Item

    The following block will be transformed as code, as it is indented more than the
    surrounding content:

        $code = "good";

    {% endmarkdown %}

</div>

Theming

There isn't any css in this module. Styling of the rendered HTML must be supplied by the theme.