8.77 KB
<h1>Markdown</h1>
<p>This module provides Markdown integration for Drupal.</p>
<p>The Markdown syntax is designed to co-exist with HTML, so you can set up input
formats with both HTML and Markdown support. It is also meant to be as
human-readable as possible when left as &quot;source&quot;.</p>
<p>There is current an issue open to make CommonMark the &quot;official&quot; <a href="https://www.drupal.org/project/coding_standards/issues/2952616">Drupal Coding
Standard</a>.</p>
<p>While there are several types of PHP Markdown parsing libraries out there, this
module requires <a href="https://github.com/thephpleague/commonmark">thephpleague/commonmark</a> as the default/fallback parser in a
preemptive acceptance of the <a href="https://www.drupal.org/project/coding_standards/issues/2952616">Drupal Coding Standard</a>.</p>
<p>This module also supports additional PHP Markdown parsers for backwards
compatibility reasons and in an effort to open up other options, should you
desire a different solution:</p>
<ul>
<li><a href="https://github.com/erusev/parsedown">erusev/parsedown</a></li>
<li><a href="https://github.com/michelf/php-markdown">michelf/php-markdown</a></li>
</ul>
<h2>Try out a demonstration!</h2>
<p><a href="https://markdown.unicorn.fail">https://markdown.unicorn.fail</a></p>
<p>To see a full list of &quot;long tips&quot; provided by this filter, visit:</p>
<p><a href="https://markdown.unicorn.fail/filter/tips">https://markdown.unicorn.fail/filter/tips</a></p>
<h2>Requirements</h2>
<ul>
<li><strong>PHP &gt;= 5.6.5</strong> - This is a hard requirement due to <a href="https://github.com/thephpleague/commonmark">thephpleague/commonmark</a>.</li>
</ul>
<h2>Installation</h2>
<blockquote>
<p>@todo Update this section.</p>
</blockquote>
<p>If you are comfortable with composer that is the best way to install both PHP
Markdown and CommonMark. They will then be autoloaded just like other parts of
Drupal 8.</p>
<p>The old way of installation in the libraries directory is only supported for PHP
Markdown. The libraries module is then needed to load the library.</p>
<ol>
<li>Download and install the <a href="https://www.drupal.org/project/libraries">Libraries</a></li>
<li>Download the PHP Markdown library from
https://github.com/michelf/php-markdown/archive/lib.zip, unpack it and place
it in the <code>libraries</code> directory in Drupal root folder, if it doesn't exist
you need to create it.</li>
</ol>
<p>Make sure the path becomes
<code>/libraries/php-markdown/Michelf/MarkdownExtra.inc.php</code>.</p>
<h2>Editor.md</h2>
<p>If you are interested in a Markdown editor please check out the <a href="https://drupal.org/project/editor_md">Editor.md</a>
module for Drupal. The demonstration site for this module also uses it if
you want to take a peek!</p>
<h2>CommonMark Extensions</h2>
<blockquote>
<p>@todo Update this section.</p>
</blockquote>
<ul>
<li><strong>Enhanced Links</strong> - <em>Built in, enabled by default</em>
Extends CommonMark to provide additional enhancements when rendering links.</li>
<li><strong>@ Autolinker</strong> - <em>Built in, disabled by default</em>
Automatically link commonly used references that come after an at character
(@) without having to use the link syntax.</li>
<li><strong># Autolinker</strong> - <em>Built in, disabled by default</em>
Automatically link commonly used references that come after a hash character
(#) without having to use the link syntax.</li>
<li><strong><a href="https://github.com/webuni/commonmark-attributes-extension">CommonMark Attributes Extension</a></strong>
Adds syntax to define attributes on various HTML elements inside a CommonMark
markdown document. To install, enable the <code>commonmark_attributes</code> sub-module.</li>
<li><strong><a href="https://github.com/webuni/commonmark-table-extension">CommonMark Table Extension</a></strong>
Adds syntax to create tables in a CommonMark markdown document.  To install,
enable the <code>commonmark_table</code> sub-module.</li>
</ul>
<h2>Programmatic Conversion</h2>
<p>In some cases you may need to programmatically convert CommonMark Markdown to
HTML. This is especially true with support legacy procedural/hook-based
functions. An example of how to accomplish this can be found in right here
in this module:</p>
<pre><code class="language-php">&lt;?php

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\markdown\Markdown;

/**
 * Implements hook_help().
 *
 * {@inheritdoc}
 */
function markdown_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.markdown':
      return Markdown::loadPath('markdown:README.md', __DIR__ . '/README.md');
  }
}
</code></pre>
<p>If you need to parse Markdown in other services, inject it as a dependency:</p>
<pre><code class="language-php">&lt;?php

use \Drupal\markdown\MarkdownInterface;

class MyService {

  /**
   * A MarkdownParser instance.
   *
   * @var \Drupal\markdown\Plugin\Markdown\MarkdownParserInterface
   */
  protected $markdownParser;

  /**
   * MyService constructor.
   */
  public function __construct(MarkdownInterface $markdown) {
    $this-&gt;markdownParser = $markdown-&gt;getParser();
  }

  /**
   * MyService renderer.
   */
  public function render(array $items) {
    $build = ['#theme' =&gt; 'item_list', '#items' =&gt; []];
    foreach ($items as $markdown) {
      $build['#items'][] = $this-&gt;markdownParser-&gt;parse($markdown);
    }
    return $build;
  }
}
</code></pre>
<p>Or if using it in classes where modifying the constructor may prove difficult,
use the <code>MarkdownTrait</code>:</p>
<pre><code class="language-php">&lt;?php

use \Drupal\markdown\Traits\MarkdownTrait;

class MyController {

  use MarkdownTrait;

  /**
   * MyService renderer.
   */
  public function render(array $items) {
    $build = ['#theme' =&gt; 'item_list', '#items' =&gt; []];
    foreach ($items as $markdown) {
      $build['#items'][] = $this-&gt;parseMarkdown($markdown);
    }
    return $build;
  }

}
</code></pre>
<h2>Twig Extensions</h2>
<p>This module also provides the following Twig extensions for use in templates:</p>
<h3>Filter/Function</h3>
<p>For simple strings or variables, you can use the <code>markdown</code> filter or function:</p>
<p>Filter:</p>
<pre><code class="language-twig">{{ &quot;# Some Markdown&quot;|markdown }}
{{ variableContiningMarkdown|markdown }}
</code></pre>
<p>Function:</p>
<pre><code class="language-twig">{{ markdown(&quot;# Some Markdown&quot;) }}
{{ markdown(variableContiningMarkdown) }}
</code></pre>
<h3>Tag</h3>
<p>If you have more than a single line of Markdown, use the <code>markdown</code> tag:</p>
<pre><code class="language-twig">{% markdown %}
  # Some Markdown

  &gt; This is some _simple_ **markdown** content.
{% endmarkdown %}
</code></pre>
<h3>Global</h3>
<p>For more advanced use cases, you can use the <code>markdown</code> global for direct
access to the <code>MarkdownInterface</code> instance.</p>
<p>Generally speaking, it is not recommended that you use this. Doing so will
bypass any existing permissions the current user may have in regards to
filters.</p>
<p>However, this is particularly useful if you want to specify a specific parser
to use (if you have multiple installed):</p>
<pre><code class="language-twig">{{ markdown.getParser('parsedown').parse(&quot;# Some Markdown&quot;) }}
{{ markdown.getParser('parsedown').parse(variableContiningMarkdown) }}
</code></pre>
<h2>Notes</h2>
<blockquote>
<p>@todo Update this section.</p>
</blockquote>
<p>Markdown may conflict with other input filters, depending on the order
in which filters are configured to apply. If using Markdown produces
unexpected markup when configured with other filters, experimenting with
the order of those filters will likely resolve the issue.</p>
<p>Filters that should be run before Markdown filter includes:</p>
<ul>
<li>Code Filter</li>
<li>GeSHI filter for code syntax highlighting</li>
</ul>
<p>Filters that should be run after Markdown filter includes:</p>
<ul>
<li>Typogrify</li>
</ul>
<p>The &quot;Limit allowed HTML tags&quot; filter is a special case:</p>
<p>For best security, ensure that it is run after the Markdown filter and
that only markup you would like to allow via HTML and/or Markdown is
configured to be allowed.</p>
<p>If you on the other hand want to make sure that all converted Markdown
text is preserved, run it before the Markdown filter. Note that blockquoting
with Markdown doesn't work in this case since &quot;Limit allowed HTML tags&quot; filter
converts the &quot;&gt;&quot; in to &quot;&gt;&quot;.</p>
<h2>Smartypants Support</h2>
<blockquote>
<p>@todo Update this section.</p>
</blockquote>
<p>This module is a continuation of the Markdown with Smartypants module.
It only includes Markdown support and it is now suggested that you use
Typogrify module if you are interested in Smartypants support.</p>
<p><a href="https://drupal.org/project/typogrify">https://drupal.org/project/typogrify</a></p>

Markdown

This module provides Markdown integration for Drupal.

The Markdown syntax is designed to co-exist with HTML, so you can set up input formats with both HTML and Markdown support. It is also meant to be as human-readable as possible when left as "source".

There is current an issue open to make CommonMark the "official" Drupal Coding Standard.

While there are several types of PHP Markdown parsing libraries out there, this module requires thephpleague/commonmark as the default/fallback parser in a preemptive acceptance of the Drupal Coding Standard.

This module also supports additional PHP Markdown parsers for backwards compatibility reasons and in an effort to open up other options, should you desire a different solution:

Try out a demonstration!

https://markdown.unicorn.fail

To see a full list of "long tips" provided by this filter, visit:

https://markdown.unicorn.fail/filter/tips

Requirements

Installation

@todo Update this section.

If you are comfortable with composer that is the best way to install both PHP Markdown and CommonMark. They will then be autoloaded just like other parts of Drupal 8.

The old way of installation in the libraries directory is only supported for PHP Markdown. The libraries module is then needed to load the library.

  1. Download and install the Libraries
  2. Download the PHP Markdown library from https://github.com/michelf/php-markdown/archive/lib.zip, unpack it and place it in the libraries directory in Drupal root folder, if it doesn't exist you need to create it.

Make sure the path becomes /libraries/php-markdown/Michelf/MarkdownExtra.inc.php.

Editor.md

If you are interested in a Markdown editor please check out the Editor.md module for Drupal. The demonstration site for this module also uses it if you want to take a peek!

CommonMark Extensions

@todo Update this section.

  • Enhanced Links - Built in, enabled by default Extends CommonMark to provide additional enhancements when rendering links.
  • @ Autolinker - Built in, disabled by default Automatically link commonly used references that come after an at character (@) without having to use the link syntax.
  • # Autolinker - Built in, disabled by default Automatically link commonly used references that come after a hash character (#) without having to use the link syntax.
  • CommonMark Attributes Extension Adds syntax to define attributes on various HTML elements inside a CommonMark markdown document. To install, enable the commonmark_attributes sub-module.
  • CommonMark Table Extension Adds syntax to create tables in a CommonMark markdown document. To install, enable the commonmark_table sub-module.

Programmatic Conversion

In some cases you may need to programmatically convert CommonMark Markdown to HTML. This is especially true with support legacy procedural/hook-based functions. An example of how to accomplish this can be found in right here in this module:

<?php

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\markdown\Markdown;

/**
 * Implements hook_help().
 *
 * {@inheritdoc}
 */
function markdown_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.markdown':
      return Markdown::loadPath('markdown:README.md', __DIR__ . '/README.md');
  }
}

If you need to parse Markdown in other services, inject it as a dependency:

<?php

use \Drupal\markdown\MarkdownInterface;

class MyService {

  /**
   * A MarkdownParser instance.
   *
   * @var \Drupal\markdown\Plugin\Markdown\MarkdownParserInterface
   */
  protected $markdownParser;

  /**
   * MyService constructor.
   */
  public function __construct(MarkdownInterface $markdown) {
    $this->markdownParser = $markdown->getParser();
  }

  /**
   * MyService renderer.
   */
  public function render(array $items) {
    $build = ['#theme' => 'item_list', '#items' => []];
    foreach ($items as $markdown) {
      $build['#items'][] = $this->markdownParser->parse($markdown);
    }
    return $build;
  }
}

Or if using it in classes where modifying the constructor may prove difficult, use the MarkdownTrait:

<?php

use \Drupal\markdown\Traits\MarkdownTrait;

class MyController {

  use MarkdownTrait;

  /**
   * MyService renderer.
   */
  public function render(array $items) {
    $build = ['#theme' => 'item_list', '#items' => []];
    foreach ($items as $markdown) {
      $build['#items'][] = $this->parseMarkdown($markdown);
    }
    return $build;
  }

}

Twig Extensions

This module also provides the following Twig extensions for use in templates:

Filter/Function

For simple strings or variables, you can use the markdown filter or function:

Filter:

{{ "# Some Markdown"|markdown }}
{{ variableContiningMarkdown|markdown }}

Function:

{{ markdown("# Some Markdown") }}
{{ markdown(variableContiningMarkdown) }}

Tag

If you have more than a single line of Markdown, use the markdown tag:

{% markdown %}
  # Some Markdown

  > This is some _simple_ **markdown** content.
{% endmarkdown %}

Global

For more advanced use cases, you can use the markdown global for direct access to the MarkdownInterface instance.

Generally speaking, it is not recommended that you use this. Doing so will bypass any existing permissions the current user may have in regards to filters.

However, this is particularly useful if you want to specify a specific parser to use (if you have multiple installed):

{{ markdown.getParser('parsedown').parse("# Some Markdown") }}
{{ markdown.getParser('parsedown').parse(variableContiningMarkdown) }}

Notes

@todo Update this section.

Markdown may conflict with other input filters, depending on the order in which filters are configured to apply. If using Markdown produces unexpected markup when configured with other filters, experimenting with the order of those filters will likely resolve the issue.

Filters that should be run before Markdown filter includes:

  • Code Filter
  • GeSHI filter for code syntax highlighting

Filters that should be run after Markdown filter includes:

  • Typogrify

The "Limit allowed HTML tags" filter is a special case:

For best security, ensure that it is run after the Markdown filter and that only markup you would like to allow via HTML and/or Markdown is configured to be allowed.

If you on the other hand want to make sure that all converted Markdown text is preserved, run it before the Markdown filter. Note that blockquoting with Markdown doesn't work in this case since "Limit allowed HTML tags" filter converts the ">" in to ">".

Smartypants Support

@todo Update this section.

This module is a continuation of the Markdown with Smartypants module. It only includes Markdown support and it is now suggested that you use Typogrify module if you are interested in Smartypants support.

https://drupal.org/project/typogrify

<h1>Markdown</h1>
<p>This module provides Markdown integration for Drupal.</p>
<p>The Markdown syntax is designed to co-exist with HTML, so you can set up input
formats with both HTML and Markdown support. It is also meant to be as
human-readable as possible when left as &quot;source&quot;.</p>
<p>There is current an issue open to make CommonMark the &quot;official&quot; <a href="https://www.drupal.org/project/coding_standards/issues/2952616">Drupal Coding
Standard</a>.</p>
<p>While there are several types of PHP Markdown parsing libraries out there, this
module requires <a href="https://github.com/thephpleague/commonmark">thephpleague/commonmark</a> as the default/fallback parser in a
preemptive acceptance of the <a href="https://www.drupal.org/project/coding_standards/issues/2952616">Drupal Coding Standard</a>.</p>
<p>This module also supports additional PHP Markdown parsers for backwards
compatibility reasons and in an effort to open up other options, should you
desire a different solution:</p>
<ul>
<li>
<a href="https://github.com/erusev/parsedown">erusev/parsedown</a>
</li>
<li>
<a href="https://github.com/michelf/php-markdown">michelf/php-markdown</a>
</li>
</ul>
<h2>Try out a demonstration!</h2>
<p><a href="https://markdown.unicorn.fail">https://markdown.unicorn.fail</a></p>
<p>To see a full list of &quot;long tips&quot; provided by this filter, visit:</p>
<p><a href="https://markdown.unicorn.fail/filter/tips">https://markdown.unicorn.fail/filter/tips</a></p>
<h2>Requirements</h2>
<ul>
<li>
<strong>PHP &gt;= 5.6.5</strong> - This is a hard requirement due to <a href="https://github.com/thephpleague/commonmark">thephpleague/commonmark</a>.</li>
</ul>
<h2>Installation</h2>
<blockquote>
<p>@todo Update this section.</p>
</blockquote>
<p>If you are comfortable with composer that is the best way to install both PHP
Markdown and CommonMark. They will then be autoloaded just like other parts of
Drupal 8.</p>
<p>The old way of installation in the libraries directory is only supported for PHP
Markdown. The libraries module is then needed to load the library.</p>
<ol>
<li>Download and install the <a href="https://www.drupal.org/project/libraries">Libraries</a>
</li>
<li>Download the PHP Markdown library from
https://github.com/michelf/php-markdown/archive/lib.zip, unpack it and place
it in the <code>libraries</code> directory in Drupal root folder, if it doesn't exist
you need to create it.</li>
</ol>
<p>Make sure the path becomes
<code>/libraries/php-markdown/Michelf/MarkdownExtra.inc.php</code>.</p>
<h2>Editor.md</h2>
<p>If you are interested in a Markdown editor please check out the <a href="https://drupal.org/project/editor_md">Editor.md</a>
module for Drupal. The demonstration site for this module also uses it if
you want to take a peek!</p>
<h2>CommonMark Extensions</h2>
<blockquote>
<p>@todo Update this section.</p>
</blockquote>
<ul>
<li>
<strong>Enhanced Links</strong> - <em>Built in, enabled by default</em>
Extends CommonMark to provide additional enhancements when rendering links.</li>
<li>
<strong>@ Autolinker</strong> - <em>Built in, disabled by default</em>
Automatically link commonly used references that come after an at character
(@) without having to use the link syntax.</li>
<li>
<strong># Autolinker</strong> - <em>Built in, disabled by default</em>
Automatically link commonly used references that come after a hash character
(#) without having to use the link syntax.</li>
<li>
<strong><a href="https://github.com/webuni/commonmark-attributes-extension">CommonMark Attributes Extension</a></strong>
Adds syntax to define attributes on various HTML elements inside a CommonMark
markdown document. To install, enable the <code>commonmark_attributes</code> sub-module.</li>
<li>
<strong><a href="https://github.com/webuni/commonmark-table-extension">CommonMark Table Extension</a></strong>
Adds syntax to create tables in a CommonMark markdown document.  To install,
enable the <code>commonmark_table</code> sub-module.</li>
</ul>
<h2>Programmatic Conversion</h2>
<p>In some cases you may need to programmatically convert CommonMark Markdown to
HTML. This is especially true with support legacy procedural/hook-based
functions. An example of how to accomplish this can be found in right here
in this module:</p>
<pre><code class="language-php">&lt;?php

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\markdown\Markdown;

/**
 * Implements hook_help().
 *
 * {@inheritdoc}
 */
function markdown_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.markdown':
      return Markdown::loadPath('markdown:README.md', __DIR__ . '/README.md');
  }
}
</code></pre>
<p>If you need to parse Markdown in other services, inject it as a dependency:</p>
<pre><code class="language-php">&lt;?php

use \Drupal\markdown\MarkdownInterface;

class MyService {

  /**
   * A MarkdownParser instance.
   *
   * @var \Drupal\markdown\Plugin\Markdown\MarkdownParserInterface
   */
  protected $markdownParser;

  /**
   * MyService constructor.
   */
  public function __construct(MarkdownInterface $markdown) {
    $this-&gt;markdownParser = $markdown-&gt;getParser();
  }

  /**
   * MyService renderer.
   */
  public function render(array $items) {
    $build = ['#theme' =&gt; 'item_list', '#items' =&gt; []];
    foreach ($items as $markdown) {
      $build['#items'][] = $this-&gt;markdownParser-&gt;parse($markdown);
    }
    return $build;
  }
}
</code></pre>
<p>Or if using it in classes where modifying the constructor may prove difficult,
use the <code>MarkdownTrait</code>:</p>
<pre><code class="language-php">&lt;?php

use \Drupal\markdown\Traits\MarkdownTrait;

class MyController {

  use MarkdownTrait;

  /**
   * MyService renderer.
   */
  public function render(array $items) {
    $build = ['#theme' =&gt; 'item_list', '#items' =&gt; []];
    foreach ($items as $markdown) {
      $build['#items'][] = $this-&gt;parseMarkdown($markdown);
    }
    return $build;
  }

}
</code></pre>
<h2>Twig Extensions</h2>
<p>This module also provides the following Twig extensions for use in templates:</p>
<h3>Filter/Function</h3>
<p>For simple strings or variables, you can use the <code>markdown</code> filter or function:</p>
<p>Filter:</p>
<pre><code class="language-twig">{{ &quot;# Some Markdown&quot;|markdown }}
{{ variableContiningMarkdown|markdown }}
</code></pre>
<p>Function:</p>
<pre><code class="language-twig">{{ markdown(&quot;# Some Markdown&quot;) }}
{{ markdown(variableContiningMarkdown) }}
</code></pre>
<h3>Tag</h3>
<p>If you have more than a single line of Markdown, use the <code>markdown</code> tag:</p>
<pre><code class="language-twig">{% markdown %}
  # Some Markdown

  &gt; This is some _simple_ **markdown** content.
{% endmarkdown %}
</code></pre>
<h3>Global</h3>
<p>For more advanced use cases, you can use the <code>markdown</code> global for direct
access to the <code>MarkdownInterface</code> instance.</p>
<p>Generally speaking, it is not recommended that you use this. Doing so will
bypass any existing permissions the current user may have in regards to
filters.</p>
<p>However, this is particularly useful if you want to specify a specific parser
to use (if you have multiple installed):</p>
<pre><code class="language-twig">{{ markdown.getParser('parsedown').parse(&quot;# Some Markdown&quot;) }}
{{ markdown.getParser('parsedown').parse(variableContiningMarkdown) }}
</code></pre>
<h2>Notes</h2>
<blockquote>
<p>@todo Update this section.</p>
</blockquote>
<p>Markdown may conflict with other input filters, depending on the order
in which filters are configured to apply. If using Markdown produces
unexpected markup when configured with other filters, experimenting with
the order of those filters will likely resolve the issue.</p>
<p>Filters that should be run before Markdown filter includes:</p>
<ul>
<li>Code Filter</li>
<li>GeSHI filter for code syntax highlighting</li>
</ul>
<p>Filters that should be run after Markdown filter includes:</p>
<ul>
<li>Typogrify</li>
</ul>
<p>The &quot;Limit allowed HTML tags&quot; filter is a special case:</p>
<p>For best security, ensure that it is run after the Markdown filter and
that only markup you would like to allow via HTML and/or Markdown is
configured to be allowed.</p>
<p>If you on the other hand want to make sure that all converted Markdown
text is preserved, run it before the Markdown filter. Note that blockquoting
with Markdown doesn't work in this case since &quot;Limit allowed HTML tags&quot; filter
converts the &quot;&gt;&quot; in to &quot;&gt;&quot;.</p>
<h2>Smartypants Support</h2>
<blockquote>
<p>@todo Update this section.</p>
</blockquote>
<p>This module is a continuation of the Markdown with Smartypants module.
It only includes Markdown support and it is now suggested that you use
Typogrify module if you are interested in Smartypants support.</p>
<p><a href="https://drupal.org/project/typogrify">https://drupal.org/project/typogrify</a></p>

Markdown

This module provides Markdown integration for Drupal.

The Markdown syntax is designed to co-exist with HTML, so you can set up input formats with both HTML and Markdown support. It is also meant to be as human-readable as possible when left as "source".

There is current an issue open to make CommonMark the "official" Drupal Coding Standard.

While there are several types of PHP Markdown parsing libraries out there, this module requires thephpleague/commonmark as the default/fallback parser in a preemptive acceptance of the Drupal Coding Standard.

This module also supports additional PHP Markdown parsers for backwards compatibility reasons and in an effort to open up other options, should you desire a different solution:

Try out a demonstration!

https://markdown.unicorn.fail

To see a full list of "long tips" provided by this filter, visit:

https://markdown.unicorn.fail/filter/tips

Requirements

Installation

@todo Update this section.

If you are comfortable with composer that is the best way to install both PHP Markdown and CommonMark. They will then be autoloaded just like other parts of Drupal 8.

The old way of installation in the libraries directory is only supported for PHP Markdown. The libraries module is then needed to load the library.

  1. Download and install the Libraries
  2. Download the PHP Markdown library from https://github.com/michelf/php-markdown/archive/lib.zip, unpack it and place it in the libraries directory in Drupal root folder, if it doesn't exist you need to create it.

Make sure the path becomes /libraries/php-markdown/Michelf/MarkdownExtra.inc.php.

Editor.md

If you are interested in a Markdown editor please check out the Editor.md module for Drupal. The demonstration site for this module also uses it if you want to take a peek!

CommonMark Extensions

@todo Update this section.

  • Enhanced Links - Built in, enabled by default Extends CommonMark to provide additional enhancements when rendering links.
  • @ Autolinker - Built in, disabled by default Automatically link commonly used references that come after an at character (@) without having to use the link syntax.
  • # Autolinker - Built in, disabled by default Automatically link commonly used references that come after a hash character (#) without having to use the link syntax.
  • CommonMark Attributes Extension Adds syntax to define attributes on various HTML elements inside a CommonMark markdown document. To install, enable the commonmark_attributes sub-module.
  • CommonMark Table Extension Adds syntax to create tables in a CommonMark markdown document. To install, enable the commonmark_table sub-module.

Programmatic Conversion

In some cases you may need to programmatically convert CommonMark Markdown to HTML. This is especially true with support legacy procedural/hook-based functions. An example of how to accomplish this can be found in right here in this module:

<?php

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\markdown\Markdown;

/**
 * Implements hook_help().
 *
 * {@inheritdoc}
 */
function markdown_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.markdown':
      return Markdown::loadPath('markdown:README.md', __DIR__ . '/README.md');
  }
}

If you need to parse Markdown in other services, inject it as a dependency:

<?php

use \Drupal\markdown\MarkdownInterface;

class MyService {

  /**
   * A MarkdownParser instance.
   *
   * @var \Drupal\markdown\Plugin\Markdown\MarkdownParserInterface
   */
  protected $markdownParser;

  /**
   * MyService constructor.
   */
  public function __construct(MarkdownInterface $markdown) {
    $this->markdownParser = $markdown->getParser();
  }

  /**
   * MyService renderer.
   */
  public function render(array $items) {
    $build = ['#theme' => 'item_list', '#items' => []];
    foreach ($items as $markdown) {
      $build['#items'][] = $this->markdownParser->parse($markdown);
    }
    return $build;
  }
}

Or if using it in classes where modifying the constructor may prove difficult, use the MarkdownTrait:

<?php

use \Drupal\markdown\Traits\MarkdownTrait;

class MyController {

  use MarkdownTrait;

  /**
   * MyService renderer.
   */
  public function render(array $items) {
    $build = ['#theme' => 'item_list', '#items' => []];
    foreach ($items as $markdown) {
      $build['#items'][] = $this->parseMarkdown($markdown);
    }
    return $build;
  }

}

Twig Extensions

This module also provides the following Twig extensions for use in templates:

Filter/Function

For simple strings or variables, you can use the markdown filter or function:

Filter:

{{ "# Some Markdown"|markdown }}
{{ variableContiningMarkdown|markdown }}

Function:

{{ markdown("# Some Markdown") }}
{{ markdown(variableContiningMarkdown) }}

Tag

If you have more than a single line of Markdown, use the markdown tag:

{% markdown %}
  # Some Markdown

  > This is some _simple_ **markdown** content.
{% endmarkdown %}

Global

For more advanced use cases, you can use the markdown global for direct access to the MarkdownInterface instance.

Generally speaking, it is not recommended that you use this. Doing so will bypass any existing permissions the current user may have in regards to filters.

However, this is particularly useful if you want to specify a specific parser to use (if you have multiple installed):

{{ markdown.getParser('parsedown').parse("# Some Markdown") }}
{{ markdown.getParser('parsedown').parse(variableContiningMarkdown) }}

Notes

@todo Update this section.

Markdown may conflict with other input filters, depending on the order in which filters are configured to apply. If using Markdown produces unexpected markup when configured with other filters, experimenting with the order of those filters will likely resolve the issue.

Filters that should be run before Markdown filter includes:

  • Code Filter
  • GeSHI filter for code syntax highlighting

Filters that should be run after Markdown filter includes:

  • Typogrify

The "Limit allowed HTML tags" filter is a special case:

For best security, ensure that it is run after the Markdown filter and that only markup you would like to allow via HTML and/or Markdown is configured to be allowed.

If you on the other hand want to make sure that all converted Markdown text is preserved, run it before the Markdown filter. Note that blockquoting with Markdown doesn't work in this case since "Limit allowed HTML tags" filter converts the ">" in to ">".

Smartypants Support

@todo Update this section.

This module is a continuation of the Markdown with Smartypants module. It only includes Markdown support and it is now suggested that you use Typogrify module if you are interested in Smartypants support.

https://drupal.org/project/typogrify

<h1>Markdown</h1>
<p>This module provides Markdown integration for Drupal.</p>
<p>The Markdown syntax is designed to co-exist with HTML, so you can set up input
formats with both HTML and Markdown support. It is also meant to be as
human-readable as possible when left as &quot;source&quot;.</p>
<p>There is current an issue open to make CommonMark the &quot;official&quot; [Drupal Coding
Standard].</p>
<p>While there are several types of PHP Markdown parsing libraries out there, this
module requires <a href="https://github.com/thephpleague/commonmark">thephpleague/commonmark</a> as the default/fallback parser in a
preemptive acceptance of the <a href="https://www.drupal.org/project/coding_standards/issues/2952616">Drupal Coding Standard</a>.</p>
<p>This module also supports additional PHP Markdown parsers for backwards
compatibility reasons and in an effort to open up other options, should you
desire a different solution:</p>
<ul>
<li><a href="https://github.com/erusev/parsedown">erusev/parsedown</a></li>
<li><a href="https://github.com/michelf/php-markdown">michelf/php-markdown</a></li>
</ul>
<h2>Try out a demonstration!</h2>
<p><a href="https://markdown.unicorn.fail">https://markdown.unicorn.fail</a></p>
<p>To see a full list of &quot;long tips&quot; provided by this filter, visit:</p>
<p><a href="https://markdown.unicorn.fail/filter/tips">https://markdown.unicorn.fail/filter/tips</a></p>
<h2>Requirements</h2>
<ul>
<li><strong>PHP &gt;= 5.6.5</strong> - This is a hard requirement due to <a href="https://github.com/thephpleague/commonmark">thephpleague/commonmark</a>.</li>
</ul>
<h2>Installation</h2>
<blockquote>
<p>@todo Update this section.</p>
</blockquote>
<p>If you are comfortable with composer that is the best way to install both PHP
Markdown and CommonMark. They will then be autoloaded just like other parts of
Drupal 8.</p>
<p>The old way of installation in the libraries directory is only supported for PHP
Markdown. The libraries module is then needed to load the library.</p>
<ol>
<li>Download and install the <a href="https://www.drupal.org/project/libraries">Libraries</a></li>
<li>Download the PHP Markdown library from
<a href="https://github.com/michelf/php-markdown/archive/lib.zip">https://github.com/michelf/php-markdown/archive/lib.zip</a>, unpack it and place
it in the <code>libraries</code> directory in Drupal root folder, if it doesn't exist
you need to create it.</li>
</ol>
<p>Make sure the path becomes
<code>/libraries/php-markdown/Michelf/MarkdownExtra.inc.php</code>.</p>
<h2>Editor.md</h2>
<p>If you are interested in a Markdown editor please check out the <a href="https://drupal.org/project/editor_md">Editor.md</a>
module for Drupal. The demonstration site for this module also uses it if
you want to take a peek!</p>
<h2>CommonMark Extensions</h2>
<blockquote>
<p>@todo Update this section.</p>
</blockquote>
<ul>
<li><strong>Enhanced Links</strong> - <em>Built in, enabled by default</em>
Extends CommonMark to provide additional enhancements when rendering links.</li>
<li><strong>@ Autolinker</strong> - <em>Built in, disabled by default</em>
Automatically link commonly used references that come after an at character
(@) without having to use the link syntax.</li>
<li><strong># Autolinker</strong> - <em>Built in, disabled by default</em>
Automatically link commonly used references that come after a hash character
(#) without having to use the link syntax.</li>
<li><strong><a href="https://github.com/webuni/commonmark-attributes-extension">CommonMark Attributes Extension</a></strong>
Adds syntax to define attributes on various HTML elements inside a CommonMark
markdown document. To install, enable the <code>commonmark_attributes</code> sub-module.</li>
<li><strong><a href="https://github.com/webuni/commonmark-table-extension">CommonMark Table Extension</a></strong>
Adds syntax to create tables in a CommonMark markdown document.  To install,
enable the <code>commonmark_table</code> sub-module.</li>
</ul>
<h2>Programmatic Conversion</h2>
<p>In some cases you may need to programmatically convert CommonMark Markdown to
HTML. This is especially true with support legacy procedural/hook-based
functions. An example of how to accomplish this can be found in right here
in this module:</p>
<pre><code class="language-php">&lt;?php

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\markdown\Markdown;

/**
 * Implements hook_help().
 *
 * {@inheritdoc}
 */
function markdown_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.markdown':
      return Markdown::loadPath('markdown:README.md', __DIR__ . '/README.md');
  }
}</code></pre>
<p>If you need to parse Markdown in other services, inject it as a dependency:</p>
<pre><code class="language-php">&lt;?php

use \Drupal\markdown\MarkdownInterface;

class MyService {

  /**
   * A MarkdownParser instance.
   *
   * @var \Drupal\markdown\Plugin\Markdown\MarkdownParserInterface
   */
  protected $markdownParser;

  /**
   * MyService constructor.
   */
  public function __construct(MarkdownInterface $markdown) {
    $this-&gt;markdownParser = $markdown-&gt;getParser();
  }

  /**
   * MyService renderer.
   */
  public function render(array $items) {
    $build = ['#theme' =&gt; 'item_list', '#items' =&gt; []];
    foreach ($items as $markdown) {
      $build['#items'][] = $this-&gt;markdownParser-&gt;parse($markdown);
    }
    return $build;
  }
}</code></pre>
<p>Or if using it in classes where modifying the constructor may prove difficult,
use the <code>MarkdownTrait</code>:</p>
<pre><code class="language-php">&lt;?php

use \Drupal\markdown\Traits\MarkdownTrait;

class MyController {

  use MarkdownTrait;

  /**
   * MyService renderer.
   */
  public function render(array $items) {
    $build = ['#theme' =&gt; 'item_list', '#items' =&gt; []];
    foreach ($items as $markdown) {
      $build['#items'][] = $this-&gt;parseMarkdown($markdown);
    }
    return $build;
  }

}</code></pre>
<h2>Twig Extensions</h2>
<p>This module also provides the following Twig extensions for use in templates:</p>
<h3>Filter/Function</h3>
<p>For simple strings or variables, you can use the <code>markdown</code> filter or function:</p>
<p>Filter:</p>
<pre><code class="language-twig">{{ "# Some Markdown"|markdown }}
{{ variableContiningMarkdown|markdown }}</code></pre>
<p>Function:</p>
<pre><code class="language-twig">{{ markdown("# Some Markdown") }}
{{ markdown(variableContiningMarkdown) }}</code></pre>
<h3>Tag</h3>
<p>If you have more than a single line of Markdown, use the <code>markdown</code> tag:</p>
<pre><code class="language-twig">{% markdown %}
  # Some Markdown

  &gt; This is some _simple_ **markdown** content.
{% endmarkdown %}</code></pre>
<h3>Global</h3>
<p>For more advanced use cases, you can use the <code>markdown</code> global for direct
access to the <code>MarkdownInterface</code> instance.</p>
<p>Generally speaking, it is not recommended that you use this. Doing so will
bypass any existing permissions the current user may have in regards to
filters.</p>
<p>However, this is particularly useful if you want to specify a specific parser
to use (if you have multiple installed):</p>
<pre><code class="language-twig">{{ markdown.getParser('parsedown').parse("# Some Markdown") }}
{{ markdown.getParser('parsedown').parse(variableContiningMarkdown) }}</code></pre>
<h2>Notes</h2>
<blockquote>
<p>@todo Update this section.</p>
</blockquote>
<p>Markdown may conflict with other input filters, depending on the order
in which filters are configured to apply. If using Markdown produces
unexpected markup when configured with other filters, experimenting with
the order of those filters will likely resolve the issue.</p>
<p>Filters that should be run before Markdown filter includes:</p>
<ul>
<li>Code Filter</li>
<li>GeSHI filter for code syntax highlighting</li>
</ul>
<p>Filters that should be run after Markdown filter includes:</p>
<ul>
<li>Typogrify</li>
</ul>
<p>The &quot;Limit allowed HTML tags&quot; filter is a special case:</p>
<p>For best security, ensure that it is run after the Markdown filter and
that only markup you would like to allow via HTML and/or Markdown is
configured to be allowed.</p>
<p>If you on the other hand want to make sure that all converted Markdown
text is preserved, run it before the Markdown filter. Note that blockquoting
with Markdown doesn't work in this case since &quot;Limit allowed HTML tags&quot; filter
converts the &quot;&gt;&quot; in to &quot;&gt;&quot;.</p>
<h2>Smartypants Support</h2>
<blockquote>
<p>@todo Update this section.</p>
</blockquote>
<p>This module is a continuation of the Markdown with Smartypants module.
It only includes Markdown support and it is now suggested that you use
Typogrify module if you are interested in Smartypants support.</p>
<p><a href="https://drupal.org/project/typogrify">https://drupal.org/project/typogrify</a></p>

Markdown

This module provides Markdown integration for Drupal.

The Markdown syntax is designed to co-exist with HTML, so you can set up input formats with both HTML and Markdown support. It is also meant to be as human-readable as possible when left as "source".

There is current an issue open to make CommonMark the "official" [Drupal Coding Standard].

While there are several types of PHP Markdown parsing libraries out there, this module requires thephpleague/commonmark as the default/fallback parser in a preemptive acceptance of the Drupal Coding Standard.

This module also supports additional PHP Markdown parsers for backwards compatibility reasons and in an effort to open up other options, should you desire a different solution:

Try out a demonstration!

https://markdown.unicorn.fail

To see a full list of "long tips" provided by this filter, visit:

https://markdown.unicorn.fail/filter/tips

Requirements

Installation

@todo Update this section.

If you are comfortable with composer that is the best way to install both PHP Markdown and CommonMark. They will then be autoloaded just like other parts of Drupal 8.

The old way of installation in the libraries directory is only supported for PHP Markdown. The libraries module is then needed to load the library.

  1. Download and install the Libraries
  2. Download the PHP Markdown library from https://github.com/michelf/php-markdown/archive/lib.zip, unpack it and place it in the libraries directory in Drupal root folder, if it doesn't exist you need to create it.

Make sure the path becomes /libraries/php-markdown/Michelf/MarkdownExtra.inc.php.

Editor.md

If you are interested in a Markdown editor please check out the Editor.md module for Drupal. The demonstration site for this module also uses it if you want to take a peek!

CommonMark Extensions

@todo Update this section.

  • Enhanced Links - Built in, enabled by default Extends CommonMark to provide additional enhancements when rendering links.
  • @ Autolinker - Built in, disabled by default Automatically link commonly used references that come after an at character (@) without having to use the link syntax.
  • # Autolinker - Built in, disabled by default Automatically link commonly used references that come after a hash character (#) without having to use the link syntax.
  • CommonMark Attributes Extension Adds syntax to define attributes on various HTML elements inside a CommonMark markdown document. To install, enable the commonmark_attributes sub-module.
  • CommonMark Table Extension Adds syntax to create tables in a CommonMark markdown document. To install, enable the commonmark_table sub-module.

Programmatic Conversion

In some cases you may need to programmatically convert CommonMark Markdown to HTML. This is especially true with support legacy procedural/hook-based functions. An example of how to accomplish this can be found in right here in this module:

<?php

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\markdown\Markdown;

/**
 * Implements hook_help().
 *
 * {@inheritdoc}
 */
function markdown_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.markdown':
      return Markdown::loadPath('markdown:README.md', __DIR__ . '/README.md');
  }
}

If you need to parse Markdown in other services, inject it as a dependency:

<?php

use \Drupal\markdown\MarkdownInterface;

class MyService {

  /**
   * A MarkdownParser instance.
   *
   * @var \Drupal\markdown\Plugin\Markdown\MarkdownParserInterface
   */
  protected $markdownParser;

  /**
   * MyService constructor.
   */
  public function __construct(MarkdownInterface $markdown) {
    $this->markdownParser = $markdown->getParser();
  }

  /**
   * MyService renderer.
   */
  public function render(array $items) {
    $build = ['#theme' => 'item_list', '#items' => []];
    foreach ($items as $markdown) {
      $build['#items'][] = $this->markdownParser->parse($markdown);
    }
    return $build;
  }
}

Or if using it in classes where modifying the constructor may prove difficult, use the MarkdownTrait:

<?php

use \Drupal\markdown\Traits\MarkdownTrait;

class MyController {

  use MarkdownTrait;

  /**
   * MyService renderer.
   */
  public function render(array $items) {
    $build = ['#theme' => 'item_list', '#items' => []];
    foreach ($items as $markdown) {
      $build['#items'][] = $this->parseMarkdown($markdown);
    }
    return $build;
  }

}

Twig Extensions

This module also provides the following Twig extensions for use in templates:

Filter/Function

For simple strings or variables, you can use the markdown filter or function:

Filter:

{{ "# Some Markdown"|markdown }}
{{ variableContiningMarkdown|markdown }}

Function:

{{ markdown("# Some Markdown") }}
{{ markdown(variableContiningMarkdown) }}

Tag

If you have more than a single line of Markdown, use the markdown tag:

{% markdown %}
  # Some Markdown

  > This is some _simple_ **markdown** content.
{% endmarkdown %}

Global

For more advanced use cases, you can use the markdown global for direct access to the MarkdownInterface instance.

Generally speaking, it is not recommended that you use this. Doing so will bypass any existing permissions the current user may have in regards to filters.

However, this is particularly useful if you want to specify a specific parser to use (if you have multiple installed):

{{ markdown.getParser('parsedown').parse("# Some Markdown") }}
{{ markdown.getParser('parsedown').parse(variableContiningMarkdown) }}

Notes

@todo Update this section.

Markdown may conflict with other input filters, depending on the order in which filters are configured to apply. If using Markdown produces unexpected markup when configured with other filters, experimenting with the order of those filters will likely resolve the issue.

Filters that should be run before Markdown filter includes:

  • Code Filter
  • GeSHI filter for code syntax highlighting

Filters that should be run after Markdown filter includes:

  • Typogrify

The "Limit allowed HTML tags" filter is a special case:

For best security, ensure that it is run after the Markdown filter and that only markup you would like to allow via HTML and/or Markdown is configured to be allowed.

If you on the other hand want to make sure that all converted Markdown text is preserved, run it before the Markdown filter. Note that blockquoting with Markdown doesn't work in this case since "Limit allowed HTML tags" filter converts the ">" in to ">".

Smartypants Support

@todo Update this section.

This module is a continuation of the Markdown with Smartypants module. It only includes Markdown support and it is now suggested that you use Typogrify module if you are interested in Smartypants support.

https://drupal.org/project/typogrify

<h1>Markdown</h1>

<p>This module provides Markdown integration for Drupal.</p>

<p>The Markdown syntax is designed to co-exist with HTML, so you can set up input
formats with both HTML and Markdown support. It is also meant to be as
human-readable as possible when left as "source".</p>

<p>There is current an issue open to make CommonMark the "official" <a href="https://www.drupal.org/project/coding_standards/issues/2952616">Drupal Coding
Standard</a>.</p>

<p>While there are several types of PHP Markdown parsing libraries out there, this
module requires <a href="https://github.com/thephpleague/commonmark">thephpleague/commonmark</a> as the default/fallback parser in a
preemptive acceptance of the <a href="https://www.drupal.org/project/coding_standards/issues/2952616">Drupal Coding Standard</a>.</p>

<p>This module also supports additional PHP Markdown parsers for backwards
compatibility reasons and in an effort to open up other options, should you
desire a different solution:</p>

<ul>
<li><a href="https://github.com/erusev/parsedown">erusev/parsedown</a></li>
<li><a href="https://github.com/michelf/php-markdown">michelf/php-markdown</a></li>
</ul>

<h2>Try out a demonstration!</h2>

<p><a href="https://markdown.unicorn.fail">https://markdown.unicorn.fail</a></p>

<p>To see a full list of "long tips" provided by this filter, visit:</p>

<p><a href="https://markdown.unicorn.fail/filter/tips">https://markdown.unicorn.fail/filter/tips</a></p>

<h2>Requirements</h2>

<ul>
<li><strong>PHP &gt;= 5.6.5</strong> - This is a hard requirement due to <a href="https://github.com/thephpleague/commonmark">thephpleague/commonmark</a>.</li>
</ul>

<h2>Installation</h2>

<blockquote>
  <p>@todo Update this section.</p>
</blockquote>

<p>If you are comfortable with composer that is the best way to install both PHP
Markdown and CommonMark. They will then be autoloaded just like other parts of
Drupal 8.</p>

<p>The old way of installation in the libraries directory is only supported for PHP
Markdown. The libraries module is then needed to load the library.</p>

<ol>
<li>Download and install the <a href="https://www.drupal.org/project/libraries">Libraries</a></li>
<li>Download the PHP Markdown library from
https://github.com/michelf/php-markdown/archive/lib.zip, unpack it and place
it in the <code>libraries</code> directory in Drupal root folder, if it doesn't exist
you need to create it.</li>
</ol>

<p>Make sure the path becomes
<code>/libraries/php-markdown/Michelf/MarkdownExtra.inc.php</code>.</p>

<h2>Editor.md</h2>

<p>If you are interested in a Markdown editor please check out the <a href="https://drupal.org/project/editor_md">Editor.md</a>
module for Drupal. The demonstration site for this module also uses it if
you want to take a peek!</p>

<h2>CommonMark Extensions</h2>

<blockquote>
  <p>@todo Update this section.</p>
</blockquote>

<ul>
<li><strong>Enhanced Links</strong> - <em>Built in, enabled by default</em>
Extends CommonMark to provide additional enhancements when rendering links.</li>
<li><strong>@ Autolinker</strong> - <em>Built in, disabled by default</em>
Automatically link commonly used references that come after an at character
(@) without having to use the link syntax.</li>
<li><strong># Autolinker</strong> - <em>Built in, disabled by default</em>
Automatically link commonly used references that come after a hash character
(#) without having to use the link syntax.</li>
<li><strong><a href="https://github.com/webuni/commonmark-attributes-extension">CommonMark Attributes Extension</a></strong>
Adds syntax to define attributes on various HTML elements inside a CommonMark
markdown document. To install, enable the <code>commonmark_attributes</code> sub-module.</li>
<li><strong><a href="https://github.com/webuni/commonmark-table-extension">CommonMark Table Extension</a></strong>
Adds syntax to create tables in a CommonMark markdown document.  To install,
enable the <code>commonmark_table</code> sub-module.</li>
</ul>

<h2>Programmatic Conversion</h2>

<p>In some cases you may need to programmatically convert CommonMark Markdown to
HTML. This is especially true with support legacy procedural/hook-based
functions. An example of how to accomplish this can be found in right here
in this module:</p>

<pre><code class="php">&lt;?php

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\markdown\Markdown;

/**
 * Implements hook_help().
 *
 * {@inheritdoc}
 */
function markdown_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.markdown':
      return Markdown::loadPath('markdown:README.md', __DIR__ . '/README.md');
  }
}
</code></pre>

<p>If you need to parse Markdown in other services, inject it as a dependency:</p>

<pre><code class="php">&lt;?php

use \Drupal\markdown\MarkdownInterface;

class MyService {

  /**
   * A MarkdownParser instance.
   *
   * @var \Drupal\markdown\Plugin\Markdown\MarkdownParserInterface
   */
  protected $markdownParser;

  /**
   * MyService constructor.
   */
  public function __construct(MarkdownInterface $markdown) {
    $this-&gt;markdownParser = $markdown-&gt;getParser();
  }

  /**
   * MyService renderer.
   */
  public function render(array $items) {
    $build = ['#theme' =&gt; 'item_list', '#items' =&gt; []];
    foreach ($items as $markdown) {
      $build['#items'][] = $this-&gt;markdownParser-&gt;parse($markdown);
    }
    return $build;
  }
}
</code></pre>

<p>Or if using it in classes where modifying the constructor may prove difficult,
use the <code>MarkdownTrait</code>:</p>

<pre><code class="php">&lt;?php

use \Drupal\markdown\Traits\MarkdownTrait;

class MyController {

  use MarkdownTrait;

  /**
   * MyService renderer.
   */
  public function render(array $items) {
    $build = ['#theme' =&gt; 'item_list', '#items' =&gt; []];
    foreach ($items as $markdown) {
      $build['#items'][] = $this-&gt;parseMarkdown($markdown);
    }
    return $build;
  }

}
</code></pre>

<h2>Twig Extensions</h2>

<p>This module also provides the following Twig extensions for use in templates:</p>

<h3>Filter/Function</h3>

<p>For simple strings or variables, you can use the <code>markdown</code> filter or function:</p>

<p>Filter:</p>

<pre><code class="twig">{{ "# Some Markdown"|markdown }}
{{ variableContiningMarkdown|markdown }}
</code></pre>

<p>Function:</p>

<pre><code class="twig">{{ markdown("# Some Markdown") }}
{{ markdown(variableContiningMarkdown) }}
</code></pre>

<h3>Tag</h3>

<p>If you have more than a single line of Markdown, use the <code>markdown</code> tag:</p>

<pre><code class="twig">{% markdown %}
  # Some Markdown

  &gt; This is some _simple_ **markdown** content.
{% endmarkdown %}
</code></pre>

<h3>Global</h3>

<p>For more advanced use cases, you can use the <code>markdown</code> global for direct
access to the <code>MarkdownInterface</code> instance.</p>

<p>Generally speaking, it is not recommended that you use this. Doing so will
bypass any existing permissions the current user may have in regards to
filters.</p>

<p>However, this is particularly useful if you want to specify a specific parser
to use (if you have multiple installed):</p>

<pre><code class="twig">{{ markdown.getParser('parsedown').parse("# Some Markdown") }}
{{ markdown.getParser('parsedown').parse(variableContiningMarkdown) }}
</code></pre>

<h2>Notes</h2>

<blockquote>
  <p>@todo Update this section.</p>
</blockquote>

<p>Markdown may conflict with other input filters, depending on the order
in which filters are configured to apply. If using Markdown produces
unexpected markup when configured with other filters, experimenting with
the order of those filters will likely resolve the issue.</p>

<p>Filters that should be run before Markdown filter includes:</p>

<ul>
<li>Code Filter</li>
<li>GeSHI filter for code syntax highlighting</li>
</ul>

<p>Filters that should be run after Markdown filter includes:</p>

<ul>
<li>Typogrify</li>
</ul>

<p>The "Limit allowed HTML tags" filter is a special case:</p>

<p>For best security, ensure that it is run after the Markdown filter and
that only markup you would like to allow via HTML and/or Markdown is
configured to be allowed.</p>

<p>If you on the other hand want to make sure that all converted Markdown
text is preserved, run it before the Markdown filter. Note that blockquoting
with Markdown doesn't work in this case since "Limit allowed HTML tags" filter
converts the "&gt;" in to "&gt;".</p>

<h2>Smartypants Support</h2>

<blockquote>
  <p>@todo Update this section.</p>
</blockquote>

<p>This module is a continuation of the Markdown with Smartypants module.
It only includes Markdown support and it is now suggested that you use
Typogrify module if you are interested in Smartypants support.</p>

<p><a href="https://drupal.org/project/typogrify">https://drupal.org/project/typogrify</a></p>

Markdown

This module provides Markdown integration for Drupal.

The Markdown syntax is designed to co-exist with HTML, so you can set up input formats with both HTML and Markdown support. It is also meant to be as human-readable as possible when left as "source".

There is current an issue open to make CommonMark the "official" Drupal Coding Standard.

While there are several types of PHP Markdown parsing libraries out there, this module requires thephpleague/commonmark as the default/fallback parser in a preemptive acceptance of the Drupal Coding Standard.

This module also supports additional PHP Markdown parsers for backwards compatibility reasons and in an effort to open up other options, should you desire a different solution:

Try out a demonstration!

https://markdown.unicorn.fail

To see a full list of "long tips" provided by this filter, visit:

https://markdown.unicorn.fail/filter/tips

Requirements

Installation

@todo Update this section.

If you are comfortable with composer that is the best way to install both PHP Markdown and CommonMark. They will then be autoloaded just like other parts of Drupal 8.

The old way of installation in the libraries directory is only supported for PHP Markdown. The libraries module is then needed to load the library.

  1. Download and install the Libraries
  2. Download the PHP Markdown library from https://github.com/michelf/php-markdown/archive/lib.zip, unpack it and place it in the libraries directory in Drupal root folder, if it doesn't exist you need to create it.

Make sure the path becomes /libraries/php-markdown/Michelf/MarkdownExtra.inc.php.

Editor.md

If you are interested in a Markdown editor please check out the Editor.md module for Drupal. The demonstration site for this module also uses it if you want to take a peek!

CommonMark Extensions

@todo Update this section.

  • Enhanced Links - Built in, enabled by default Extends CommonMark to provide additional enhancements when rendering links.
  • @ Autolinker - Built in, disabled by default Automatically link commonly used references that come after an at character (@) without having to use the link syntax.
  • # Autolinker - Built in, disabled by default Automatically link commonly used references that come after a hash character (#) without having to use the link syntax.
  • CommonMark Attributes Extension Adds syntax to define attributes on various HTML elements inside a CommonMark markdown document. To install, enable the commonmark_attributes sub-module.
  • CommonMark Table Extension Adds syntax to create tables in a CommonMark markdown document. To install, enable the commonmark_table sub-module.

Programmatic Conversion

In some cases you may need to programmatically convert CommonMark Markdown to HTML. This is especially true with support legacy procedural/hook-based functions. An example of how to accomplish this can be found in right here in this module:

<?php

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\markdown\Markdown;

/**
 * Implements hook_help().
 *
 * {@inheritdoc}
 */
function markdown_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.markdown':
      return Markdown::loadPath('markdown:README.md', __DIR__ . '/README.md');
  }
}

If you need to parse Markdown in other services, inject it as a dependency:

<?php

use \Drupal\markdown\MarkdownInterface;

class MyService {

  /**
   * A MarkdownParser instance.
   *
   * @var \Drupal\markdown\Plugin\Markdown\MarkdownParserInterface
   */
  protected $markdownParser;

  /**
   * MyService constructor.
   */
  public function __construct(MarkdownInterface $markdown) {
    $this->markdownParser = $markdown->getParser();
  }

  /**
   * MyService renderer.
   */
  public function render(array $items) {
    $build = ['#theme' => 'item_list', '#items' => []];
    foreach ($items as $markdown) {
      $build['#items'][] = $this->markdownParser->parse($markdown);
    }
    return $build;
  }
}

Or if using it in classes where modifying the constructor may prove difficult, use the MarkdownTrait:

<?php

use \Drupal\markdown\Traits\MarkdownTrait;

class MyController {

  use MarkdownTrait;

  /**
   * MyService renderer.
   */
  public function render(array $items) {
    $build = ['#theme' => 'item_list', '#items' => []];
    foreach ($items as $markdown) {
      $build['#items'][] = $this->parseMarkdown($markdown);
    }
    return $build;
  }

}

Twig Extensions

This module also provides the following Twig extensions for use in templates:

Filter/Function

For simple strings or variables, you can use the markdown filter or function:

Filter:

{{ "# Some Markdown"|markdown }}
{{ variableContiningMarkdown|markdown }}

Function:

{{ markdown("# Some Markdown") }}
{{ markdown(variableContiningMarkdown) }}

Tag

If you have more than a single line of Markdown, use the markdown tag:

{% markdown %}
  # Some Markdown

  > This is some _simple_ **markdown** content.
{% endmarkdown %}

Global

For more advanced use cases, you can use the markdown global for direct access to the MarkdownInterface instance.

Generally speaking, it is not recommended that you use this. Doing so will bypass any existing permissions the current user may have in regards to filters.

However, this is particularly useful if you want to specify a specific parser to use (if you have multiple installed):

{{ markdown.getParser('parsedown').parse("# Some Markdown") }}
{{ markdown.getParser('parsedown').parse(variableContiningMarkdown) }}

Notes

@todo Update this section.

Markdown may conflict with other input filters, depending on the order in which filters are configured to apply. If using Markdown produces unexpected markup when configured with other filters, experimenting with the order of those filters will likely resolve the issue.

Filters that should be run before Markdown filter includes:

  • Code Filter
  • GeSHI filter for code syntax highlighting

Filters that should be run after Markdown filter includes:

  • Typogrify

The "Limit allowed HTML tags" filter is a special case:

For best security, ensure that it is run after the Markdown filter and that only markup you would like to allow via HTML and/or Markdown is configured to be allowed.

If you on the other hand want to make sure that all converted Markdown text is preserved, run it before the Markdown filter. Note that blockquoting with Markdown doesn't work in this case since "Limit allowed HTML tags" filter converts the ">" in to ">".

Smartypants Support

@todo Update this section.

This module is a continuation of the Markdown with Smartypants module. It only includes Markdown support and it is now suggested that you use Typogrify module if you are interested in Smartypants support.

https://drupal.org/project/typogrify