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
- How to add a new block?
- How to add a new blog post?
- How to build reusable HTML components?
- How to implement a custom plugin?
- How to display a list of items?
- How to display a list of links?
- How to add dynamic data to a page with a plugin?
- How to use Stapy on Windows?
- How to host my static website for free?
- How to auto-deploy my website with GitHub Action?
- ✓ How to write content in Markdown?
- How to add a JSON feed?
- How to use Stapy with Apache HTTP Server?
- How to update Stapy?