markdown-include-variants

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. 😅

https://github.com/tiangolo/markdown-include-variants

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.9%) to scientific vocabulary

Keywords from Contributors

spacy-extension network-simulation hacking data-profilers interactive sequences wavelets manifolds mesh uvicorn
Last synced: 7 months ago · JSON representation ·

Repository

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. 😅

Basic Info
  • Host: GitHub
  • Owner: tiangolo
  • License: mit
  • Language: Python
  • Default Branch: main
  • Size: 119 KB
Statistics
  • Stars: 12
  • Watchers: 1
  • Forks: 1
  • Open Issues: 2
  • Releases: 4
Created over 1 year ago · Last pushed 8 months ago
Metadata Files
Readme Funding License Citation

README.md

markdown-include-variants

Test Publish Coverage Package version


🚨 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:

```yaml 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 mdxinclude: markdowninclude_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_src directory, with the minimum Python version supported by the project, and using the old format without Annotated, if that applies, it would be named something like tutorial001.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 like tutorial001_py39.py, tutorial001_py310.py, etc. and tutorial001_an_py39.py, tutorial001_an_py310.py, etc.
  • In the Markdown file, include the preferred version of the file, using this syntax:

markdown {* ./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:

markdown {* ./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:

```python

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:

markdown {* ./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:

markdown {* ./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:

python 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:

markdown {* ./docs_src/first_steps/tutorial001_an_py310.py ln[5:7] hl[6] *}

Could render something like:

```python

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]:

markdown {* ./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.

Owner

  • Name: Sebastián Ramírez
  • Login: tiangolo
  • Kind: user
  • Location: Berlin, Germany

Creator of FastAPI, Typer, SQLModel, Asyncer, etc. 🚀 From 🇨🇴 in 🇩🇪. Open Source, APIs, and tools for data/ML. 🤖 Python, TypeScript, Docker, etc.

Citation (CITATION.cff)

# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: markdown-include-variants
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
authors:
  - given-names: Sebastián
    family-names: Ramírez
    email: tiangolo@gmail.com
identifiers:
repository-code: 'https://github.com/tiangolo/markdown-include-variants'
url: 'https://github.com/tiangolo/markdown-include-variants'
abstract: >-
  markdown-include-variants, expand multiple variants of source examples in Markdown.
keywords:
  - markdown
license: MIT

GitHub Events

Total
  • Release event: 3
  • Watch event: 6
  • Delete event: 13
  • Issue comment event: 2
  • Push event: 20
  • Pull request event: 23
  • Create event: 14
Last Year
  • Release event: 3
  • Watch event: 6
  • Delete event: 13
  • Issue comment event: 2
  • Push event: 20
  • Pull request event: 23
  • Create event: 14

Committers

Last synced: over 1 year ago

All Time
  • Total Commits: 47
  • Total Committers: 3
  • Avg Commits per committer: 15.667
  • Development Distribution Score (DDS): 0.213
Past Year
  • Commits: 47
  • Committers: 3
  • Avg Commits per committer: 15.667
  • Development Distribution Score (DDS): 0.213
Top Committers
Name Email Commits
Sebastián Ramírez t****o@g****m 37
github-actions g****s@g****m 9
dependabot[bot] 4****] 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 0
  • Total pull requests: 23
  • Average time to close issues: N/A
  • Average time to close pull requests: 9 days
  • Total issue authors: 0
  • Total pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 0.13
  • Merged pull requests: 18
  • Bot issues: 0
  • Bot pull requests: 12
Past Year
  • Issues: 0
  • Pull requests: 23
  • Average time to close issues: N/A
  • Average time to close pull requests: 9 days
  • Issue authors: 0
  • Pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 0.13
  • Merged pull requests: 18
  • Bot issues: 0
  • Bot pull requests: 12
Top Authors
Issue Authors
Pull Request Authors
  • tiangolo (20)
  • dependabot[bot] (19)
Top Labels
Issue Labels
Pull Request Labels
internal (24) dependencies (19) github_actions (19) feature (5) docs (4) refactor (1)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 11,888 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 4
  • Total maintainers: 1
pypi.org: markdown-include-variants

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. 😅

  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 11,888 Last month
Rankings
Dependent packages count: 10.2%
Average: 33.9%
Dependent repos count: 57.6%
Maintainers (1)
Last synced: 8 months ago