Static Site Generator

How-to: How to write content in Markdown?

How to write content in Markdown?

Note: Since version 1.16.2, a Markdown plugin is included in Stapy. It requires the Python Markdown module to work.

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
+------ mdtohtml.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