Extensions

Python Markdown Extensions Rundown»

Table of Contents

Installation»

This is a collected list of packages to install:

pip install --user --upgrade PyYAML
pip install --user --upgrade Markdown
pip install --user --upgrade pymdown-extensions
pip install --user --upgrade python-markdown-pretty
pip install --user --upgrade pyembed-markdown
pip install --user --upgrade markdown-include
pip install --user --upgrade mdx_sections
pip install --user --upgrade git+https://github.com/twardoch/markdown-steroids.git/@master#egg=mdx_steroids-0.4.0

Usage»

Python»

md = markdown.Markdown(
  extensions=[
  'markdown_include.include',  'markdown_include.include',

  'path/to/my_ext.py',
  ],
  extension_configs={
  'markdown_include.include': {
  base_path: './srcdocs'
  }
  }
)
html = md.convert(markdown_string)

Command-line»

  1. Create a config.yml file that describes the extension_configs dictionary using YAML:
markdown_include.include:
    base_path: './srcdocs'
  1. Run:
$ python -m markdown \
    -x path/to/my_ext.py \
    -x markdown_include.include \
    -c config.yml \
    -o 'html5' -f output.html input.md

tables»

The tables extension adds the ability to create tables in Markdown documents.

Installation»

preinstalled

Example»


First Header Second Header
Content Cell Content Cell
Content Cell Content Cell

Input Markdown»

First Header  | Second Header
------------- | -------------
Content Cell  | Content Cell
Content Cell  | Content Cell

Output HTML»

<table>
  <thead>
    <tr>
      <th>First Header</th>
      <th>Second Header</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Content Cell</td>
      <td>Content Cell</td>
    </tr>
    <tr>
      <td>Content Cell</td>
      <td>Content Cell</td>
    </tr>
  </tbody>
</table>

abbr»

The abbr extension adds the ability to define abbreviations, which are then wrapped in an <abbr> tag.

Installation»

preinstalled

Example»


The WOFF specification is maintained by the W3C.


Input Markdown»

The WOFF specification is maintained by the W3C.

*[WOFF]: Web Open Font Format
*[W3C]:  World Wide Web Consortium

Output HTML»

<p>The <abbr title="Hyper Text Markup Language">HTML</abbr> specification
is maintained by the <abbr title="World Wide Web Consortium">W3C</abbr>.</p>

attr_list»

The attr_list extension adds a syntax to define attributes on the various HTML elements in markdown’s output.

Installation»

preinstalled

Example»


Header 3»

link

This is a paragraph.


Input Markdown»

### Header 3 {: #header_3 }

[link](http://example.com){: class="foo bar" title="Some title!" }

This is a paragraph.
{: #an_id .class_1 .class_2 title="explain" }

Output HTML»

<h3 id="header_3">Header 3</h3>
<p><a href="http://example.com" class="foo bar" title="Some title!">link</a></p>
<p id="an_id" class="class_1 class_2" title="explain">This is a paragraph.</p>

markdown_attr_plus»

The markdown_attr_plus extension modifies the default Attribute List extension to include {^ ... }, {o ... }, and {> ... } syntax, which specifically only modify lists, list items, and blockquotes respectively.

Installation»

pip install --user --upgrade markdown-attr-plus

admonition»

The admonition extension adds rST-style admonitions to Markdown documents.

Installation»

preinstalled

Docs»

Common admonition types are: attention, caution, danger, error, hint, important, note, tip, warning

Example»


Word of warning

This is a admonition box.


Input Markdown»

!!! important "Word of warning"
This is a admonition box.

Output HTML»

<div class="admonition important">
    <p class="admonition-title">Word of warning</p>
    <p>This is a admonition box.</p>
</div>

codehilite»

The codehilite extension adds code/syntax highlighting to standard Python-Markdown code blocks using Pygments.

Installation»

preinstalled

Options»

  codehilite:
    css_class      : 'code'
    linenums       : null
    guess_lang     : true
    use_pygments   : true
    pygments_style : 'default'  

def_list»

The def_list extension adds the ability to create definition lists in Markdown documents.

Installation»

preinstalled

Example»


Apple
Pomaceous fruit of plants of the genus Malus in
the family Rosaceae.
Orange
The fruit of an evergreen tree of the genus Citrus.

Input Markdown»

Apple
:   Pomaceous fruit of plants of the genus Malus in
    the family Rosaceae.

Orange
:   The fruit of an evergreen tree of the genus Citrus.

Output HTML»

<dl>
    <dt>Apple</dt>
    <dd>Pomaceous fruit of plants of the genus Malus in the family Rosaceae.</dd>
    <dt>Orange</dt>
    <dd>The fruit of an evergreen tree of the genus Citrus.</dd>
</dl>

footnotes»

The footnotes extension adds syntax for defining footnotes in Markdown documents.

Installation»

preinstalled

Options»

  footnotes:
    PLACE_MARKER   : '///Footnotes Go Here///' 
    # if the place marker text is not found in the document, 
    # the footnote definitions are placed at the end of the resulting HTML document
    UNIQUE_IDS     : false
    BACKLINK_TEXT  : '&#8617;'  

Example»


Footnotes1 have a label2 and the footnote’s content.


  1. This is a footnote content. 

  2. A footnote on the label: “@#$%”. 


Input Markdown»

Footnotes[^1] have a label[^@#$%] and the footnote's content.

[^1]: This is a footnote content.
[^@#$%]: A footnote on the label: "@#$%".

///Footnotes Go Here///

Output HTML»

<p>Footnotes<a href="#fn:1" id="fnref:1" title="see footnote" class="footnote">[1]</a> have a label<a href="#fn:2" id="fnref:2" title="see footnote" class="footnote">[2]</a> and the footnote’s content.</p>

<div class="footnotes">
    <hr>
    <ol>
        <li id="fn:1">
            <p>This is a footnote content. <a href="#fnref:1" title="return to article" class="reversefootnote">&nbsp;</a></p>
        </li>
        <li id="fn:2">
            <p>A footnote on the label: “@#$%”. <a href="#fnref:2" title="return to article" class="reversefootnote">&nbsp;</a></p>
        </li>
    </ol>
</div>

meta»

The meta extension adds a syntax for defining meta-data about a document.

Installation»

preinstalled

Example»

Input Markdown»

Title:   My Document
Summary: A brief description of my document.
Authors: Waylan Limberg
         John Doe
Date:    October 2, 2007
blank-value:
base_url: http://example.com

This is the first paragraph of the document.

nl2br»

The nl2br extension will cause newlines to be treated as hard breaks.

Installation»

preinstalled

Example»


Line 1
Line 2


Input Markdown»

Line 1
Line 2

Output HTML»

<p>Line 1<br />
Line 2</p>

smarty»

The smarty extension converts ASCII dashes, quotes and ellipses to their HTML entity equivalents.

Installation»

preinstalled

Options»

  smarty:
    smart_dashes           : true  # convert dashes
    smart_quotes           : true  # convert straight quotes
    smart_angled_quotes    : false # whether to convert angled quotes
    smart_ellipses         : true  # whether to convert ellipses
    substitutions:                 # overwrite default substitutions
        left-single-quote  : '‘'   # '
        right-single-quote : '’'   # '
        left-double-quote  : '“'   # "
        right-double-quote : '”'   # "
        left-angle-quote   : '«'   # <<
        right-angle-quote  : '»'   # >>
        ellipsis           : '…'   # ...
        ndash              : '–'   # --
        mdash              : '—'   # ---

Example»


The “quick brown” fox’s tail — voila…


Input Markdown»

The "quick brown" fox's tail --- voila...

Output HTML»

<p>The “quick brown” fox’s tail — voila…</p>

toc»

The toc extension

Installation»

preinstalled

Options»

  toc:
    permalink      : '❡'
    marker         : '[TOC]'
    title          : 'Table of Contents'
    anchorlink     : true
    baselevel      : 1
    separator      : '-'
    slugify        : headerid.slugify

Example»

Input Markdown»

[TOC]

# Header 1

## Header 2 {: #Header 2 }

Output HTML»

<div class="toc">
  <ul>
    <li><a href="#header-1">Header 1</a></li>
      <ul>
        <li><a href="#header-2">Header 2</a></li>
      </ul>
  </ul>
</div>
<h1 id="header-1">Header 1</h1>
<h1 id="header-2">Header 2</h1>

pymdownx.betterem»

The pymdownx.betterem extension improves emphasis (bold and italic) handling.

Installation»

pip install --user --upgrade pymdown-extensions

Options»

  pymdownx.betterem:
    smart_enable   : 'all'                # 'all' | 'asterisk' | 'underscore' | 'none'

Example»


Usage is the same as usual. Just keep in mind the differences.


Input Markdown»

Usage is the __same__ as usual. Just keep in mind the _differences_. 

Output HTML»

<p>Usage is the <strong>same</strong> as usual. Just keep in mind the <em>differences</em>. </p>

pymdownx.mark»

The pymdownx.mark extension

Installation»

pip install --user --upgrade pymdown-extensions

Options»

  pymdownx.mark:
    smart_mark     : true                 # Allows for ==mark==me== 

Example»


Choose File > Open… and pick the file.


Input Markdown»

Choose ==File > Open...== and pick the file. 

Output HTML»

<p>Choose <mark>File &gt; Open…</mark> and pick the file. </p>

pymdownx.superfences»

The pymdownx.superfences extension adds flexible ways to define code blocks, and replaces the fenced_code extension.

Installation»

pip install --user --upgrade pymdown-extensions

Options»

  pymdownx.superfences:
    disable_indented_code_blocks : false
    nested         : true
    uml_flow       : false
    uml_sequence   : false

Example»


```python
class MyClass(object):
def init(self):
return pass

print(“Done”)
```


Input Markdown»

> ```python
class MyClass(object):
  def __init__(self):
    return pass

> print("Done")
```

Output HTML»

<blockquote>
<pre class=" language-python"><code class=" language-python"><span class="token keyword">class</span> <span class="token class-name">MyClass</span><span class="token punctuation">(</span>object<span class="token punctuation">)</span><span class="token punctuation">:</span>
  <span class="token keyword">def</span> <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
    <span class="token keyword">return</span> <span class="token keyword">pass</span>

<span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"Done"</span><span class="token punctuation">)</span>
</code></pre>
</blockquote>

pyembed.markdown»

The pyembed.markdown extension allows you to embed content in your Markdown websites and documents from a wide range of producers using OEmbed.

Installation»

pip install --user --upgrade pyembed-markdown

Example»

Input Markdown»

[!embed](http://www.youtube.com/watch?v=9bZkp7q19f0)

Output HTML»

<iframe width="480" height="270" src="http://www.youtube.com/embed/9bZkp7q19f0?feature=oembed" frameborder="0" allowfullscreen></iframe>

markdown_include.include»

The markdown_include.include extension replaces the Welcome to the markdown-rundown wiki! statement with the contents of Home.md. It works recursively, prior to any other Markdown processing.

Installation»

pip install --user --upgrade markdown-include

Options»

  markdown_include.include:
    base_path      : './srcdocs/'
    encoding       : 'utf-8'

Example»


Welcome to the markdown-rundown wiki!


Input Markdown»


Welcome to the markdown-rundown wiki!

sections»

The sections extension adds a small amount of structure to Markdown documents.

Installation»

pip install --user --upgrade mdx_sections

outline»

The outline extension uses the h1-h6 headings to create HTML section elements with the sectionN class, where N is the header level being wrapped. Also, the header attributes get moved to the wrapper.

Installation»

pip install --user --upgrade mdx_outline

Example»

Input Markdown»

# Introduction {: foo=bar }

This is a paragraph. 

Output HTML»

<section class="section1" foo="bar">
    <h1>Introduction</h1>
    <p>This is a paragraph.</p>
</section>

cite»

The cite extension wraps the inline content surrounded by three double quotes into cite tags.

Installation»

pip install --user --upgrade mdx_cite

Example»


In the Loop is the last movie I watched.


Input Markdown»

"""In the Loop""" is the last movie I watched.

Output HTML»

<p><cite>In the Loop</cite> is the last movie I watched.</p>

collapse»

The collapse extension defines collapsible areas.

The collapse extension makes problems

Installation»

pip install --user --upgrade mdx_collapse

Example»


<<< “Collapsible stuff”
* Stuff 1
* Stuff 2
* Stuff 3
* Stuff 4


Input Markdown»

<<< "Collapsible stuff"
    * Stuff 1
    * Stuff 2
    * Stuff 3
    * Stuff 4

Output HTML»

<div class="panel panel-default panel-collapsible">
    <div class="panel-heading">
        <a data-toggle="collapse" data-target="#collapse1" />
    </div>
    <div id="collapse1" class="panel-body collapse in">
        <ul>
            <li>Stuff 1</li>
            <li>Stuff 2</li>
            <li>Stuff 3</li>
            <li>Stuff 4</li>
        </ul>
    </div>
</div>

custom_span_class»

The custom_span_class allows adding span elements with custom class.

Installation»

pip install --user --upgrade mdx_customspanclass

Example»


I love spam


Input Markdown»

I love !!text-alert|spam!!

Output HTML»

<p>I love <span class="text-alert">spam</span></p>

figcap»

The figcap extension converts a Markdown image into a HTML <figure> element.

Installation»

pip install --user --upgrade git+https://github.com/mkszk/mdx_figcap.git

Example»


This is an alt text
This is a caption with Markdown


Input Markdown»

![This is an alt text](test.jpg "This is a **caption** with Markdown")

Output HTML»

<figure><img alt="This is an alt text" src="../test.jpg" 
  title="This is a **caption** with Markdown">
    <figcaption>This is a <strong>caption</strong> with Markdown</figcaption>
</figure>

fontawesome-markdown»

The fontawesome-markdown looks for things like ``` and replaces them with the Font Awesome icon markup.

Installation»

pip install --user --upgrade fontawesome-markdown

Example»


We ♥


Input Markdown»

We ♥ :fa-coffee:

Output HTML»

<p>We ♥ <i class="fa fa-coffee"></i></p>

steroids.kbd»

The steroids.kbd extension converts syntax for user keyboard entry: ||Cmd+K|| into <kbd>Cmd+K</kbd>.

Installation»

pip install --user --upgrade git+https://github.com/twardoch/markdown-steroids.git

Options»

  steroids.kbd:
    repl_mac       : false                # Replace macOS symbols
    html_class     : 'kbd'                # CSS hook. Leave blank for none

Example»


⌘ K


Input Markdown»

||Cmd+K||

Output HTML»

<kbd class="kbd">Cmd+K</kbd>

steroids.replimgsrc»

The steroids.replimgsrc extension finds and replaces portions of an image URL.

Installation»

pip install --user --upgrade git+https://github.com/twardoch/markdown-steroids.git

Options»

  steroids.replimgsrc: 
    find           : 'https://github.com/repo/blob/master/images/'
    replace        : '../img/'

Example»



Input Markdown»


Output HTML»


steroids.absimgsrc»

The steroids.absimgsrc replaces relative image URLs with absolute ones.

Installation»

pip install --user --upgrade git+https://github.com/twardoch/markdown-steroids.git

Options»

  steroids.absimgsrc: 
    base_url       : 'https://github.com/repo/blob/master/images/' 
    # Base URL to which the relative paths will be appended

Example»



Input Markdown»


Output HTML»


Deprecated»

pymdownx.headeranchor»

  • Use toc with permalinks instead!

fenced_code»

smart_strong»

smartypants»

The smartypants extension converts ASCII dashes, quotes and ellipses to their HTML entity equivalents.

Installation»

pip install --user --upgrade hg+https://bitbucket.org/chriskrycho/mdx_smartypants

Options»

  smartypants:
    smarten        : 'default'

Example»


The “quick brown” fox’s tail — voila…


Input Markdown»

The "quick brown" fox's tail --- voila...

Output HTML»

<p>The “quick brown” fox’s tail — voila…</p>