Markdown extension to expand directives to include source example files to also include their variants. Only useful to tiangolo's projets. Don't use it. 😅
Project description
markdown-include-variants
🚨 Warning: Internal Project
This is an internal project, it is mainly useful for the docs in @tiangolo's projects (e.g. all the FastAPI projects).
It is probably not useful to you. You should probably not use it. 😅
There are no guarantees about behavior, it is made to suit the needs of these projects, to simplify writing documentation.
How to Use
If you're still here it's probably because you are getting involved in one of the projects that use it. 🤓
Here's how it works. 🚀
Configure Plugin in MkDocs Material
Make sure mkdocs.yml has a section with at least these configs:
markdown_extensions:
# Python Markdown Extensions
pymdownx.highlight:
pymdownx.superfences:
# pymdownx blocks
pymdownx.blocks.admonition:
types:
- tip
pymdownx.blocks.details:
pymdownx.blocks.tab:
alternate_style: True
# Other extensions
mdx_include:
markdown_include_variants:
The last config is the one specific to this extension, markdown-include-variants.
The other configs are for the extensions that actually render the output, this extension (markdown-include-variants) just generates the content to be rendered by those other extensions.
Workflow
- You add a Python source example to the
docs_srcdirectory, with the minimum Python version supported by the project, and using the old format withoutAnnotated, if that applies, it would be named something liketutorial001.py. - Copy the file and update it to use
Annotated(if that applies), and name the file with a "tag" (a prefix) of_an, like:tutorial001_an.py. - Run the internal script to generate the variants of the files for superior versions of Python, like
3.9,3.10, etc. (this internal script is in the project itself). This would generate files liketutorial001_py39.py,tutorial001_py310.py, etc. andtutorial001_an_py39.py,tutorial001_an_py310.py, etc. - In the Markdown file, include the preferred version of the file, using this syntax:
{* ./docs_src/first_steps/tutorial001_an_py310.py *}
That will be automatically expanded with mdx-include to include the other variants below in a collapsed details box.
Include Lines
To include specific line ranges, use the config ln:
{* ./docs_src/first_steps/tutorial001_an_py310.py ln[3:6,8,10:11] *}
That will include only:
- lines 3 to 6
- line 8
- lines 10 to 11
It will add blocks with comments in the middle like:
# Code here omitted 👈️
If you include specific lines, it will also add another collapsed details box with the "Full file preview".
Highlight Lines
You can highlight specific lines using the config hl:
{* ./docs_src/first_steps/tutorial001_an_py310.py hl[3,5:7,10] *}
That will highlight:
- line 3
- lines 5 to 7
- line 10
Have in mind that the file path points to the simplest version of the file, the one without the _an suffix. But the main file shown will be the highest (recommended) version, and the highlights will apply to that file.
So, when deciding which lines to highlight, do that based on the highest version of the file.
Include Lines and Highlight
You can combine both ln and hl:
{* ./docs_src/first_steps/tutorial001_an_py310.py ln[3:6,8,10:11] hl[3,5:6,10] *}
The highlighted lines refer to the source file (for the highest/recommended version), not the final rendered code block.
This makes it easier to decide which lines to highlight just by opening the source file, without having to calculate the actual lines in the rendered block after included, the extra lines for comments when omitting lines, etc.
Include Lines and Highlight - Example
For example, you could have a source file with:
print("line 1")
print("line 2")
print("line 3")
print("line 4")
print("line 5")
print("line 6") # highlight this
print("line 7")
Using a declaration like this:
{* ./docs_src/first_steps/tutorial001_an_py310.py ln[5:7] hl[6] *}
Could render something like:
# Code above omitted 👈️
print("line 5")
print("line 6") # highlight this
print("line 7")
Notice that the comment above adds 2 extra lines, and only the desired lines are included, the result is that the actual highlighted line is the rendered line 4, but the source line 6, it's all calculated automatically. 🤓
Include Only File Preview
If you only want to generate the "File Preview" collapsed details section, without actually including a tab of source files, you can use ln[0]:
{* ./docs_src/first_steps/tutorial001_an_py310.py ln[0] *}
This is useful for example at the beginning of a new page, in a recap of the last used file in the previous page.
License
This project is licensed under the terms of the MIT license.
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 markdown_include_variants-0.0.6.tar.gz.
File metadata
- Download URL: markdown_include_variants-0.0.6.tar.gz
- Upload date:
- Size: 43.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f1a84554889072341593ca84db5f4097fb3fd0f50ea818f4b31ad9c1cb08e52
|
|
| MD5 |
2eb6760b1511073078de6cbfd6eb814a
|
|
| BLAKE2b-256 |
06dcfde5ee1ae644f9ef6475e35347070d920e0c1830c4919ac92e6d73b56d8f
|
Provenance
The following attestation bundles were made for markdown_include_variants-0.0.6.tar.gz:
Publisher:
publish.yml on tiangolo/markdown-include-variants
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
markdown_include_variants-0.0.6.tar.gz -
Subject digest:
4f1a84554889072341593ca84db5f4097fb3fd0f50ea818f4b31ad9c1cb08e52 - Sigstore transparency entry: 731039720
- Sigstore integration time:
-
Permalink:
tiangolo/markdown-include-variants@5203da3dc65f3c8e2b4b762eee60f3b7bab640ed -
Branch / Tag:
refs/tags/0.0.6 - Owner: https://github.com/tiangolo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5203da3dc65f3c8e2b4b762eee60f3b7bab640ed -
Trigger Event:
release
-
Statement type:
File details
Details for the file markdown_include_variants-0.0.6-py3-none-any.whl.
File metadata
- Download URL: markdown_include_variants-0.0.6-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f67e9f4580d9ebff6f7633347cfc1351a706c24015f709b1ca19fe4ef0bdb5b8
|
|
| MD5 |
0864e595a8d6b540e4327e89d0bcc1d9
|
|
| BLAKE2b-256 |
1b0e996b49cf664ec11b9435394747c7bfc94772e07c1a755bf7c519d349c24a
|
Provenance
The following attestation bundles were made for markdown_include_variants-0.0.6-py3-none-any.whl:
Publisher:
publish.yml on tiangolo/markdown-include-variants
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
markdown_include_variants-0.0.6-py3-none-any.whl -
Subject digest:
f67e9f4580d9ebff6f7633347cfc1351a706c24015f709b1ca19fe4ef0bdb5b8 - Sigstore transparency entry: 731039722
- Sigstore integration time:
-
Permalink:
tiangolo/markdown-include-variants@5203da3dc65f3c8e2b4b762eee60f3b7bab640ed -
Branch / Tag:
refs/tags/0.0.6 - Owner: https://github.com/tiangolo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5203da3dc65f3c8e2b4b762eee60f3b7bab640ed -
Trigger Event:
release
-
Statement type: