Skip to content

Mkdocs Material

Official doc

Plugins

⭐ mkdocs/catalog is a list of awesome MkDocs projects and plugins.

Selected

Deployment

Tips and Tricks

Code blocks

I have discovered that enabling code block title and line numbers globally (in mkdocs.yml) is bad idea:

mkdocs.yml
markdown_extensions:
- pymdownx.highlight: # (1)!
    auto_title: true
    linenums: true
  1. Code annotations PyMdown Extensions - Highlight options

that’s why I will switch on title and line numbers on demand (see more here):

Code block with title
``` py title="bubble_sort.py"
def bubble_sort(items):
    for i in range(len(items)):
        for j in range(len(items) - 1 - i):
            if items[j] > items[j + 1]:
                items[j], items[j + 1] = items[j + 1], items[j]
```
bubble_sort.py
def bubble_sort(items):
    for i in range(len(items)):
        for j in range(len(items) - 1 - i):
            if items[j] > items[j + 1]:
                items[j], items[j + 1] = items[j + 1], items[j]
Code block with line numbers
``` py linenums="1"
def bubble_sort(items):
    for i in range(len(items)):
        for j in range(len(items) - 1 - i):
            if items[j] > items[j + 1]:
                items[j], items[j + 1] = items[j + 1], items[j]
```
1
2
3
4
5
def bubble_sort(items):
    for i in range(len(items)):
        for j in range(len(items) - 1 - i):
            if items[j] > items[j + 1]:
                items[j], items[j + 1] = items[j + 1], items[j]

Render Markdown in <details /> tag

Use md_in_html to render collapsible blocks, which are implemented with <details /> elements (see issue Formatting lost in <details> tag):

markdown_extensions:
  - md_in_html
<details markdown>
  <summary>Title</summary>
  Content
</details>