Skip to main content

MkDocs Execute Plugin

Plugin for MkDocs that executes documentation files using jupytext and embeds the output in your documentation.

Installation

Start by install the plugin using pip:

pip install mkdocs-execute-plugin

Basic usage

Configuring mkdocs

After installing it, you can enable the plugin by adding it to the plugin section of your mkdocs.yml:

plugins:
  - execute

Adding executable files

By default, this plugin will execute all code blocks inside markdown files if the file has the execute tag. An example markdown file can be found below.

---
execute: true
---

```python
print('Hello world!')
```

On top of that, the plugin will also execute all python (.py) files by default.

print('Hello world!')

Hiding cell input or output

It is possible to hide the input or output of a cell by applying the hide-input and hide-output tags respectively. It is also possible to hide a cell completely using the hide-cell tag.

```python tags=["hide-input"]
print('Hidden input')
```

```python tags=["hide-output"]
print('Hidden output')
```

```python tags=["hide-cell"]
print('Completely hidden')
```

Configuration

All configuration options can be found below. The given values are the defaults.

# Default configuration
plugins:
  - execute:
      # Specify which files to include for execution. Should be a list of .gitignore style glob patterns.
      # Note that only files with the execute tag set to true will be executed. To override, see `execute_without_tag`.
      include:
        - '*.py'
        - '*.md'
      # Specify which glob patterns to exclude for execution. Same format as `include`.
      exclude: []
      # Specify which files should still be executed if the execute tag is missing. Same format as `include`.
      # If the execute is set to false for a file matching this pattern, it will NOT be executed.
      execute_without_tag:
        - '*.py'
      # Markdown template used to render the executed files.
      markdown_template: 'markdown/index.md.j2'
      # You can modify the names of all tags.
      tags:
        # Tag that marks the file as executable.
        execute: 'execute'
        # Tag that hides a cell completely, both the input and output.
        # Note that the cell will still be executed.
        hide_cell: 'hide-cell'
        # Tag that hides the cell input (code).
        hide_input: 'hide-input'
        # Tag that hides the cell output.
        hide_output: 'hide-output'

Supported formats and languages

This plugin uses jupytext to execute and then convert files to markdown. This means all languages and formats supported by jupytext should work.

Development with Pixi

This repo is configured to use Pixi for fast, reproducible environments and dev tasks.

  1. Install Pixi (one-time)
curl -fsSL https://pixi.sh/install.sh | sh
  1. Install the environment (creates .pixi/ locally)
pixi install
  1. Common tasks
# Run tests
pixi run test

# Build and serve the docs
pixi run docs-build
pixi run docs-serve

You can also open a shell in the environment:

pixi shell

Pre-commit hooks

This repo uses pre-commit to enforce code style and basic checks:

# Install git hooks
pixi run pre-commit install

# Run hooks on all files
pixi run pre-commit-run

CI will also run pre-commit run --all-files to keep the codebase consistent.

Metadata

Release files for mkdocs-execute-plugin 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mkdocs-execute-plugin 0.0.9
File Size Uploaded
mkdocs_execute_plugin-0.0.9.tar.gz 35.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mkdocs-execute-plugin 0.0.9
File Interpreter ABI Platform
mkdocs_execute_plugin-0.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 46.3 kB

Release files / mkdocs_execute_plugin-0.0.9.tar.gz

Download URL mkdocs_execute_plugin-0.0.9.tar.gz
Size 35.0 kB
Tags Source
SHA-256 checksum
How to use checksums
658aeccb5447d7a3ec27dbcc203a6faee28e8c551f2d33d7683fb6101a499f2f
BLAKE2b-256 checksum
How to use checksums
f549a25b0da80729d27171a53c926e0067c8768ac403ea9c612a9346314714c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Release files / mkdocs_execute_plugin-0.0.9-py3-none-any.whl

Download URL mkdocs_execute_plugin-0.0.9-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
99d37e1029ac799fce34b039819f89b5374696db8d693d2d30182288bbf195b0
BLAKE2b-256 checksum
How to use checksums
f0a13bb23af3398452cdac6da5415e19bb4555d82f73ba9ce3cfa39818cf6b68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Release history Release notifications | RSS feed

This release

0.0.9 This release

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page