Snippets for MkDocs
Project description
Mkdocs Snippets Plugin
This plugin allows you to include snippets in your mkdocs documentation. It is available as a PyPI package.
Features
- Organize your snippets in a way that makes sense for you:
- Multiple snippets per file thanks to YAML syntax.
- Snippets are loaded from any (nested) directory inside the configured
snippets_dir. - Recursively include snippets in snippets!
- Documentation links in snippets are automatically converted to relative links based on the snippet's location.
- This allows you to link to other documentation pages from your snippets without having to worry about the snippet's location.
- Also works with
mike!
- Snippets preserve the indentation of the snippet call.
- This allows you to use snippets in lists and code blocks without having to worry about indentation.
- Customizable snippet syntax.
Installation
pip install mkdocs-snippets
pip install mkdocs-exclude (recommended)
Consider adding the plugins to a requirements.txt file alongside other Python dependencies for your project.
Setup
Add the plugin to your mkdocs.yml file:
It is recommended to use the mkdocs-exclude plugin to exclude the snippet directory from the documentation build.
This will save you from a lot of warnings about files that are not referenced in the nav configuration.
plugins:
- search
- exclude:
glob:
- snippets/*
- snippets
Usage
The plugin will load snippets from the default directory snippets which must be inside your documentation directory.
It is allowed to have any number of files and subdirectories inside the snippet directory.
These files must be in the YAML format.
mySnippet: |-
This is a snippet.
It can contain multiple lines.
# |- is the YAML Multiline Indicator
myOtherSnippet: |-
This is another snippet.
All top level keys in the snippet file are treated as snippets. Every key is a snippet ID.
Snippet Syntax
The default snippet syntax is @Snippet:snippetFile:snippetID@.
Links in Snippets
Internal documentation links in snippets are automatically converted to relative links based on where the snippet is used. This allows you to use documentation links in your snippets without having to worry that the snippet might be used in a directory in which the link does not work. Therefore, links in the snippet must be written as if they were in the root of the documentation directory.
Example
Consider the following documentation structure (docs/ is the documentation's root directory):
docs/API/Overview.md
docs/API/Client/Cookbook.md
A snippet would look like this:
mySnippet: |-
This is a snippet.
It contains a link to the [API Overview](API/Overview.md).
myOtherSnippet: |-
This is another snippet.
It contains a link to the [Client API Cookbook](API/Client/Cookbook.md).
No leading slashes or relative paths are allowed. The file type (.md) must be specified.
The snippets can now be used in any file without the links breaking.
Configuration
If you want to customize the snippet syntax or directory, you can do so by adding the following configuration:
plugins:
- search
- snippets:
directory: "mySnippetDirectory"
delimiter: "|"
identifier: "snip"
divider_char: ">"
Contributing
This section is for contributors and maintainers.
Setup Dev Environment
pip install -r requirements/dev-requirements.txt
pip install -r requirements/requirements.txt
Releasing
To release a new version of the plugin, follow the steps in the official Python packaging guide.
Dependency Management
To manage dependencies, we use pip-tools to generate requirements.txt/dev-requirements.txt files from requirements.in/dev-requirements.in.
To update your local environment with the latest dependencies, run:
pip-sync requirements/requirements.txt requirements/dev-requirements.txt
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mkdocs_snippets-1.3.2.tar.gz.
File metadata
- Download URL: mkdocs_snippets-1.3.2.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d46d2700dec2dd8dab1d2977a656bed11ad89fdfd4dab30f2008c99d42086c53
|
|
| MD5 |
5b36908cc12d38d41cc508fd7b3d1ebb
|
|
| BLAKE2b-256 |
3e569a5264a78375443f57fe3043a77f11d5b8edb8fcd7f3385aa00edbad1a3a
|
Provenance
The following attestation bundles were made for mkdocs_snippets-1.3.2.tar.gz:
Publisher:
pypi-release.yml on BetonQuest/mkdocs-snippets
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mkdocs_snippets-1.3.2.tar.gz -
Subject digest:
d46d2700dec2dd8dab1d2977a656bed11ad89fdfd4dab30f2008c99d42086c53 - Sigstore transparency entry: 208109456
- Sigstore integration time:
-
Permalink:
BetonQuest/mkdocs-snippets@b21203a7536ddc343fdefff973661b37db318ffc -
Branch / Tag:
refs/tags/v1.3.2 - Owner: https://github.com/BetonQuest
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-release.yml@b21203a7536ddc343fdefff973661b37db318ffc -
Trigger Event:
push
-
Statement type:
File details
Details for the file mkdocs_snippets-1.3.2-py3-none-any.whl.
File metadata
- Download URL: mkdocs_snippets-1.3.2-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a2be9ced4169acb3449d89a2d882f7e0e516a8c9cf3ffb8b9c6565af83a9a61
|
|
| MD5 |
a152d30294c27bb56f6d0a8822f54dfc
|
|
| BLAKE2b-256 |
0ebf8e63de00e57a05e739782dbcccfe6fad033fa886c361622053198a5b638c
|
Provenance
The following attestation bundles were made for mkdocs_snippets-1.3.2-py3-none-any.whl:
Publisher:
pypi-release.yml on BetonQuest/mkdocs-snippets
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mkdocs_snippets-1.3.2-py3-none-any.whl -
Subject digest:
0a2be9ced4169acb3449d89a2d882f7e0e516a8c9cf3ffb8b9c6565af83a9a61 - Sigstore transparency entry: 208109461
- Sigstore integration time:
-
Permalink:
BetonQuest/mkdocs-snippets@b21203a7536ddc343fdefff973661b37db318ffc -
Branch / Tag:
refs/tags/v1.3.2 - Owner: https://github.com/BetonQuest
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-release.yml@b21203a7536ddc343fdefff973661b37db318ffc -
Trigger Event:
push
-
Statement type: