Skip to content

Extract docs with macros

mkdocs.yml

# You can even use this with other plugins, like
# [macros](https://pypi.org/project/mkdocs-macros-plugin/) to achieve advanced
# configurations.
site_name: ok-with-macros
docs_dir: /tmp/mkdocs-simple/ok-with-macros/docs
plugins:
    - search
    - simple:
          include:
              - ".yml"
    - macros:
          include_dir: "."
          verbose: True
extra:
    test: True

Input

ok-with-macros/
├── example.md
├── mkdocs.yml
├── module.py
└── README.md

module.py

"""md

## Python Version

You can put _markdown_ in triple-quoted strings in Python.

You can even use macros to inject other markdown here!

For example, here's the config file:

````yaml
{% if test %}
{% include "mkdocs.yml" %}
{% endif %}
````
"""


def main():
    """Test function which takes no parameters.

    It says "Hello, world!"
    """
    print("Hello, world!")
    return 0

Output

site/
├── example/
│   └── index.html
├── index.html
├── mkdocs-test.yml
├── mkdocs.yml
└── module/
    └── index.html

example

Example

Here's a printout of the plugin's config file, which I've included using a jinja-style macro.


site_name: ok-with-macros
docs_dir: /tmp/mkdocs-simple/ok-with-macros/docs
plugins:
  - search
  - simple:
      include:
        - .yml
  - macros:
      include_dir: .
      verbose: true
edit_uri: ''
extra:
  test: true

module

Python Version

You can put markdown in triple-quoted strings in Python.

You can even use macros to inject other markdown here!

For example, here's the config file:


site_name: ok-with-macros
docs_dir: /tmp/mkdocs-simple/ok-with-macros/docs
plugins:
  - search
  - simple:
      include:
        - .yml
  - macros:
      include_dir: .
      verbose: true
edit_uri: ''
extra:
  test: true