Source🔗
- https://squidfunk.github.io/mkdocs-material/reference/code-blocks/
- https://facelessuser.github.io/pymdown-extensions/extensions/highlight/
Setup🔗
theme:
features:
- content.code.annotate # (1)!
- content.code.copy # (2)!
markdown_extensions:
- pymdownx.highlight:
anchor_linenums: true
line_spans: __span
pygments_lang_class: true
- pymdownx.inlinehilite
- pymdownx.snippets
- pymdownx.superfences
- Important for code annotations
- Enable code copy button
Examples🔗
Code with highlighting:
With title:
With line numbers and line highlight:
Highlighting inline code is done with the #!
characters, e.g.,
print(f'param = {param}')
.
Using snippets:
The filename is under the directory base_path
configured in
mkdocs.yaml
:
The directory should be outside of docs/
.
More examples can be found in the documentation.
Using annotations:
For each code annotation a link can be set (example).
Available Languages/Lexer🔗
See: https://pygments.org/docs/lexers/
bash / sh🔗
console / shell-session🔗
python🔗
pycon🔗
>>> name = 'dreknix'
>>> print(name)
dreknix
>>> div = 1 / 0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero