Skip to content

Extract a snippet

mkdocs.yml

# This is example shows to to create a snippet from a file.  For example, you 
# can use a snippet to rearrange contents using inclusion or create a new pages 
# per module.
site_name: ok-source-with-snippet
plugins:
  - simple

Input

ok-source-with-snippet/
├── mkdocs.yml
├── module.py
├── README.md

module.py

"""md

## Main file

You can even make snippets as separate files.

"""

# md file=snippet.md
#
# ## Snippet
#
# This is a snippet from module.py.
# /md

"""<md file="snippet2.md">Another one.

## Snippet2

This is another snippet from module.py
"""


def main():
    """Main function which prints "Hello, World!"""
    print("Hello, world!")
    return 0

Output

site/
├── index.html
├── module/
│   └── index.html
├── snippet/
│   └── index.html
└── snippet2/
    └── index.html

module

Main file

You can even make snippets as separate files.

snippet

Snippet

This is a snippet from module.py.

snippet2

Snippet2

This is another snippet from module.py