How can I display existing source code files within MkDocs? I want to include the files directly from another GitHub repository in code blocks without reformatting them so updated files will be shown in the MkDocs document.
sample_code.py
def fn():
pass
Using MkDocs with Snippets extension. Snippets and/or off-line processing require files to be available locally which is explained in the Pro Git book Git Tools Submodules section.
index.md
.
```python
--8<-- "docs/sample_code.py"
```
.
sample_code.py
def fn():
pass
mkdocs.yml
site_name: Demo
markdown_extensions:
- pymdownx.snippets:
nav:
- Demo: index.md
Output
.
def fn():
pass
.