Skip to content

Python Markdown Extensions

The Python Markdown Extensions package is an excellent collection of additional extensions perfectly suited for advanced technical writing. Zensical lists this package as an explicit dependency, so it's automatically installed with a supported version.

Supported extensions

In general, all extensions that are part of Python Markdown Extensions should work with Zensical. The following list includes all extensions that are natively supported, meaning they work without any further adjustments.

Arithmatex

The Arithmatex extension allows for rendering of block and inline block equations and integrates seamlessly with MathJax1 – a library for mathematical typesetting. Enable it via:

[project.markdown_extensions.pymdownx.arithmatex]
generic = true
markdown_extensions:
  - pymdownx.arithmatex:
      generic: true

Besides enabling the extension in your configuration, a MathJax configuration and the JavaScript runtime need to be included, which can be done with a few lines of additional JavaScript:

window.MathJax = {
  tex: {
    inlineMath: [["\\(", "\\)"]],
    displayMath: [["\\[", "\\]"]],
    processEscapes: true,
    processEnvironments: true
  },
  options: {
    ignoreHtmlClass: ".*|",
    processHtmlClass: "arithmatex"
  }
};

document$.subscribe(() => { // (1)!
  MathJax.startup.output.clearCache()
  MathJax.typesetClear()
  MathJax.texReset()
  MathJax.typesetPromise()
})
  1. This integrates MathJax with instant navigation
[project]
extra_javascript = [
    "javascripts/mathjax.js",
    "https://unpkg.com/mathjax@3/es5/tex-mml-chtml.j"
]
extra_javascript:
  - javascripts/mathjax.js
  - https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js

The other configuration options of this extension are not officially supported by Zensical, which is why they may yield unexpected results. Use them at your own risk.

See these authoring guides for usage:

Caption

The Caption extension adds the ability to add captions to any Markdown block, including images, tables, and code blocks. Enable it via:

[project.markdown_extensions.pymdownx.blocks.caption]
markdown_extensions:
  - pymdownx.blocks.caption

The configuration options of this extension are not specific to Zensical as they only impact the Markdown parsing stage. See the Caption documentation for more information.

Caret, Mark & Tilde

The Caret, Mark and Tilde extensions add the ability to highlight text and define sub- and superscript using a simple syntax. Enable them together via:

[project.markdown_extensions.pymdownx.caret]
[project.markdown_extensions.pymdownx.mark]
[project.markdown_extensions.pymdownx.tilde]
markdown_extensions:
  - pymdownx.caret
  - pymdownx.mark
  - pymdownx.tilde

The configuration options of this extension are not specific to Zensical as they only impact the Markdown parsing stage. See the Caret, Mark and Tilde documentation for guidance.

See these authoring guides for usage:

Details

The Details extension supercharges the Admonition extension, making the resulting call-outs collapsible, allowing them to be opened and closed by the user. Enable it via:

[project.markdown_extensions.pymdownx.details]
markdown_extensions:
  - pymdownx.details

No configuration options are available. See this authoring guide for usage:

Emoji

The Emoji extension automatically inlines bundled and custom icons and emojis in *.svg file format into the resulting HTML page. Enable it via:

[project.markdown_extensions.pymdownx.emoji]
emoji_index = "zensical.extensions.emoji.twemoji" # (1)!
emoji_generator = "zensical.extensions.emoji.to_svg"
  1. Python Markdown Extensions uses the pymdownx namespace, but in order to support the inlining of icons, the zensical namespace must be used, as it extends the functionality of pymdownx.
markdown_extensions:
  - pymdownx.emoji:
      emoji_index: !!python/name:zensical.extensions.emoji.twemoji # (1)!
      emoji_generator: !!python/name:zensical.extensions.emoji.to_svg
  1. Python Markdown Extensions uses the pymdownx namespace, but in order to support the inlining of icons, the zensical namespace must be used, as it extends the functionality of pymdownx.

The following configuration options are supported:

emoji_index

This option defines which set of emojis is used for rendering. Note that the use of emojione is not recommended due to restrictions in licensing:

[project.markdown_extensions.pymdownx.emoji]
emoji_index = "zensical.extensions.emoji.twemoji"
markdown_extensions:
  - pymdownx.emoji:
      emoji_index: !!python/name:zensical.extensions.emoji.twemoji

emoji_generator

This option defines how the resolved emoji or icon shortcode is render. Note that icons can only be used together with the to_svg configuration:

[project.markdown_extensions.pymdownx.emoji]
emoji_generator = "zensical.extensions.emoji.to_svg"
markdown_extensions:
  - pymdownx.emoji:
      emoji_generator: !!python/name:zensical.extensions.emoji.to_svg

custom_icons

This option allows to list folders with additional icon sets to be used in Markdown or the configuration, which is explained in more detail in the icon customization guide:

[project.markdown_extensions.pymdownx.emoji]
emoji_index: !!python/name:zensical.extensions.emoji.twemoji
emoji_generator = "zensical.extensions.emoji.to_svg"
options = { custom_icons = "overrides/.icons }
markdown_extensions:
  - pymdownx.emoji:
      emoji_index: !!python/name:material.extensions.emoji.twemoji
      emoji_generator: !!python/name:material.extensions.emoji.to_svg
      options:
        custom_icons:
          - overrides/.icons

The other configuration options of this extension are not officially supported by Zensical, which is why they may yield unexpected results. Use them at your own risk.

See usage:

Highlight

The Highlight extension adds support for syntax highlighting of code blocks (with the help of SuperFences) and inline code blocks (with the help of InlineHilite). Enable it via:

[project.markdown_extensions.highlight]
anchor_linenums = true
[project.markdown_extensions.pymdownx.superfences]
  1. Highlight is used by the SuperFences extension to perform syntax highlighting on code blocks, not the other way round, which is why this extension also needs to be enabled.
markdown_extensions:
  - pymdownx.highlight:
      anchor_linenums: true
  - pymdownx.superfences # (1)!
  1. Highlight is used by the SuperFences extension to perform syntax highlighting on code blocks, not the other way round, which is why this extension also needs to be enabled.

The following configuration options are supported:

pygments_lang_class

This option instructs Pygments to add a CSS class to identify the language of the code block, which is essential for custom annotation markers to function. Enable via:

[project.markdown_extensions.pymdownx.highlight]
pygments_lang_class = true
markdown_extensions:
  - pymdownx.highlight:
      pygments_lang_class: true

auto_title

This option will automatically add a title to all code blocks that shows the name of the language being used, e.g. Python is printed for a py block:

[project.markdown_extensions.pymdownx.highlight]
auto_title = true
markdown_extensions:
  - pymdownx.highlight:
      auto_title: true

linenums

This option will add line numbers to all code blocks. If you wish to add line numbers to some, but not all code blocks, consult the section on adding line numbers in the code block section, which also contains some tips on working with line numbers:

[project.markdown_extensions.pymdownx.highlight]
linenums = true
markdown_extensions:
  - pymdownx.highlight:
      linenums: true

linenums_style

The Highlight extension provides three ways to add line numbers, two of which are supported by Zensical. While table wraps a code block in a <table> element, pymdownx-inline renders line numbers as part of the line itself:

[project.markdown_extensions.pymdownx.highlight]
linenums_style: pymdownx-inline
markdown_extensions:
  - pymdownx.highlight:
      linenums_style: pymdownx-inline

Avoid including line numbers in copy-and-paste

Note that inline will put line numbers next to the actual code, which means that they will be included when selecting text with the cursor or copying a code block to the clipboard. Thus, the usage of either table or pymdownx-inline is recommended.

anchor_linenums

If a code blocks contains line numbers, enabling this setting will wrap them with anchor links, so they can be hyperlinked and shared more easily:

[project.markdown_extensions.pymdownx.highlight]
anchor_linenums = true
markdown_extensions:
  - pymdownx.highlight:
      anchor_linenums: true

line_spans

When this option is set, each line of a code block is wrapped in a span, which is essential for features like line highlighting to work correctly:

[project.markdown_extensions.pymdownx.highlight]
line_spans = "__span"
markdown_extensions:
  - pymdownx.highlight:
      line_spans: __span

The other configuration options of this extension are not officially supported by Zensical, which is why they may yield unexpected results. Use them at your own risk.

See these authoring guides for usage:

InlineHilite

The InlineHilite extension add support for syntax highlighting of inline code blocks. It's built on top of the Highlight extension, from which it sources its configuration. Enable it via:

[project.markdown_extensions.pymdownx.highlight]
[project.markdown_extensions.pymdownx.inlinehilite]
markdown_extensions:
  - pymdownx.highlight
  - pymdownx.inlinehilite

The configuration options of this extension are not specific to Material for MkDocs, as they only impact the Markdown parsing stage. The only exception is the css_class option, which must not be changed. See the InlineHilite documentation for guidance.

See this authoring guide for usage:

Keys

The Keys extension adds a simple syntax to allow for the rendering of keyboard keys and combinations, e.g. Ctrl+Alt+Del. Enable it via:

[project.markdown_extensions.pymdownx.keys]
markdown_extensions:
  - pymdownx.keys

The configuration options of this extension are not specific to Zensical as they only impact the Markdown parsing stage. The only exception is the class option, which must not be changed. See the Keys documentation for more information.

See this authoring guide for usage:

SmartSymbols

The SmartSymbols extension converts some sequences of characters into their corresponding symbols, e.g. copyright symbols or fractions. Enable it via:

[project.markdown_extensions.pymdownx.smartsymbols]
markdown_extensions:
  - pymdownx.smartsymbols

The configuration options of this extension are not specific to Zensical as they only impact the Markdown parsing stage. See the SmartSymbols documentation for guidance.

Snippets

The Snippets extension adds the ability to embed content from arbitrary files into a document, including other documents or source files, by using a simple syntax. Enable it via:

[project.markdown_extensions.pymdownx.snippets]
markdown_extensions:
  - pymdownx.snippets

The configuration options of this extension are not specific to Zensical as they only impact the Markdown parsing stage. See the Snippets documentation for more information.

See these authoring guides for usage:

SuperFences

The SuperFences extension allows for arbitrary nesting of code and content blocks inside each other, including admonitions, tabs, lists and all other elements. Enable it via:

[project.markdown_extensions.pymdownx.superfences]
markdown_extensions:
  - pymdownx.superfences

The following configuration options are supported:

custom_fences

This option allows to define a handler for custom fences, e.g. to preserve the definitions of Mermaid.js diagrams to be interpreted in the browser:

[project.markdown_extensions.pymdownx.superfences.custom_fences]
name = "mermaid"
class = "mermaid"
format = "pymdownx.superfences.fence_code_format"
markdown_extensions:
  - pymdownx.superfences:
      custom_fences:
        - name: mermaid
          class: mermaid
          format: !!python/name:pymdownx.superfences.fence_code_format

Note that this will primarily prevent syntax highlighting from being applied. See the authoring guide for diagrams to learn how Mermaid.js is integrated with Zensical.

The other configuration options of this extension are not officially supported by Zensical, which is why they may yield unexpected results. Use them at your own risk.

See these authoring guides for usage:

Tabbed

The Tabbed extension allows the usage of content tabs, a simple way to group related content and code blocks under accessible tabs. Enable it via:

[project.markdown_extensions.pymdownx.tabbed]
alternate_style = true
markdown_extensions:
  - pymdownx.tabbed:
      alternate_style: true

The following configuration options are supported:

alternate_style

This option enables the content tabs alternate style, which has better behavior on mobile viewports, and is the only supported style:

[project.markdown_extensions.pymdownx.tabbed]
alternate_style = true
markdown_extensions:
  - pymdownx.tabbed:
      alternate_style: true

combine_header_slug

This option enables the content tabs' combine_header_slug style flag, which prepends the id of the header to the id of the tab:

[project.markdown_extensions.pymdownx.tabbed]
combine_header_slug = true
markdown_extensions:
  - pymdownx.tabbed:
      combine_header_slug: true

slugify

This option allows for customization of the slug function. For some languages, the default may not produce good and readable identifiers – consider using another slug function like for example those from Python Markdown Extensions. To produce all-lowercase slugs:

[project.markdown_extensions.pymdownx.tabbed.slugify]
object = "pymdownx.slugs.slugify"
kwds = { case = "lower" }
markdown_extensions:
  - pymdownx.tabbed:
      slugify: !!python/object/apply:pymdownx.slugs.slugify
        kwds:
          case: lower

In order to retain the case of the input:

[project.markdown_extensions.pymdownx.tabbed.slugify]
object = "pymdownx.slugs.slugify"
markdown_extensions:
  - pymdownx.tabbed:
      slugify: !!python/object/apply:pymdownx.slugs.slugify {}

The other configuration options of this extension are not officially supported by Zensical, which is why they may yield unexpected results. Use them at your own risk.

See these authoring guides for usage:

Tasklist

The Tasklist extension allows for the usage of GitHub Flavored Markdown inspired task lists, following the same syntactical conventions. Enable it via:

[project.markdown_extensions.pymdownx.tasklist]
custom_checkbox = true
markdown_extensions:
  - pymdownx.tasklist:
      custom_checkbox: true

The following configuration options are supported:

checkbox

This option toggles the rendering style of checkboxes, replacing native checkbox styles with beautiful icons, and is therefore recommended:

[project.markdown_extensions.pymdownx.tasklist]
custom_checkbox = true
markdown_extensions:
  - pymdownx.tasklist:
      custom_checkbox: true

clickable_checkbox

This option toggles whether checkboxes are clickable. As the state is not persisted, the use of this option is rather discouraged from a user experience perspective:

[project.markdown_extensions.pymdownx.tasklist]
clickable_checkbox = true
markdown_extensions:
  - pymdownx.tasklist:
      clickable_checkbox: true

The other configuration options of this extension are not officially supported by Zensical, which is why they may yield unexpected results. Use them at your own risk.

See this authoring guide for usage:

Other extensions

Did not find what you are looking for? The Markdown extensions listed above are those that we officially support. You can use other extensions and they should work but we are not advertising their use as we believe there are better alternatives. The critic extension, for example, is quite difficult to use in projects of any significant size and we would advise users to work with Git to track changes instead.


  1. Other libraries like KaTeX are also supported and can be integrated with some additional effort. See the Arithmatex documentation on KaTeX for further guidance, as this is beyond the scope of Zensical.