Static Site Generator

How-to: How to write content in Markdown?

How to write content in Markdown?

Step 1

Install Markdown and PyMdown packages. PyMdown is a collection of additional extensions for Python Markdown.

Unix

pip3 install Markdown pymdown-extensions

Windows

From start menu, search for cmd in the search bar and select Windows Terminal. Then enter the command:

pip install Markdown pymdown-extensions

Step 2

In the Stapy site plugins directory, add a new Python file:

plugins
+------ markdown.py
import markdown


def file_content_opened(content: str, args: dict) -> str:
    if args['path'].endswith('.md'):
        return markdown.markdown(content)
    return content

If the file has the md extension, the content will be converted from Markdown to HTML.

Step 3

In your page Json configuration, set a Markdown file for the page content:

{
  "content": "content/my-markdown-content.md"
}

Markdown extensions

You can add extensions to enrich the default Markdown syntax. We use Officially Supported Extensions and PyMdown.

Example:

import markdown


def file_content_opened(content: str, args: dict) -> str:
    if args['path'].endswith('.md'):
        extensions = ['fenced_code', 'tables', 'attr_list', 'md_in_html', 'nl2br', 'pymdownx.tilde']
        return markdown.markdown(content, extensions=extensions)
    return content

Next