MkDocs
MkDocs🔗
= ("[Website](" + this.url + ")")
| = ("[Source](" + this.source + ")")
| = ("[Documentation](" + this.docs + ")")
= ("> " + this.desc-short)
Caveats
- use only relative links, not absolute links, for compatibility between different Markdown viewers/editors
- using Markdown extensions such as mkdocs-ezlinked locate files and make it significantly easier to use links
- obsidian: activate shortest possible paths in settings to achieve compatible links.
Getting Started🔗
-
install
mkdocs
package and other requirements (from package repos or viapip
, consider creating a new Python virtual environment)1
pip install -r requirements.txt
or only MkDocs package
1
pip install mkdocs
-
create new project
1
mkdocs new my-project
will create files/folders
1 2 3 4
my-project/ ├── docs/ │   └── index.md └── mkdocs.yml
-
dump our Markdown files in
docs/
, e.g. as Git submodule1
git submodule add URL docs
or in separate subdirectories if you include more sources. Git’s sparse checkout can be helpful if you want to integrate repos containing more than documentation as this lets you chose which files and directories you want to have present.
-
start server for local testing or build (output to
public/
)1 2 3
mkdocs serve # or mkdocs build
CLI🔗
Config🔗
In file mkdocs.yml
.
-
1
site_name: !ENV SITE_NAME
Examples
Themes🔗
Mkdocs-Material🔗
- Getting started
- plugins: search
- plugins: tags: support for tags in page front matter and search function
Caveat: slightly more picky about YAML syntax than Obsidian- create a Tags Index:
[TAGS]
- hide tags on a page: add following to front matter,
hide: [tags]
- create a Tags Index:
- Markdown
- Navigation/sidebar
- Setting up a blog
- versioning using mike
1 2 3 4 5 |
|
Markdown in MkDocs🔗
To ensure compatibility between MkDocs and other Markdown renderers, try to stick to Python-Markdown Specifications.
A number of Markdown extensions and MkDocs plugins is used, see mkdocs.yml
. The script util/markdown.sh
contains a number of functions to edit Markdown files in a batch
md_fix_lists_empty_line
: add empty lines before Markdown lists that wouldn’t render as lists in MkDocs otherwisemd_fix_linestart_obsidian-tag
: add text before Obsidian inline tage that would render as headings in MkDocs otherwisefm_fix_tags_format
: ensure tags in YAML front matter are proper YAML arrays (Obsidian accepts just a space as separator)
Markdown Extensions🔗
Clean
- categorise extensions/plugins
See MkDocs documentation on markdown extensions, list of Python-Markdown extensions and Python-Markdown
- TOC
- Footnotes
- Admonition: not configurable, full compatibility with Obsidian call-outs would require work (open/closed with
> [!info]-
) #todo/contrib - Definition Lists
mdx_truly_sane_lists
:pip install mdx-truly-sane-lists
Extension for Python-Markdown that makes lists truly sane. Custom indents for nested lists and fix for messy linebreaks and paragraphs between lists.
Issues: #16: doesn’t support mixing indentations | [#7: list not rendering without preceding empty line] #todo/tech/markdown/mkdocs
- mdx-breakless-lists: don’t require empty line before lists, uses regex to enter empty line in processing, so one doesn’t have to change the source
mkdocs-material documentation
- Tasklist: to-do/check lists
- Formatting: strikeout, highlight, underline, sub- and super-script, keyboard keys (short-code for HTML tag
<kbd>
) - Table of Contents
- Emoji
- Diagrams: Superfences for Markdown (there is also mkdocs-mermaid2-plugin) ^4d7ac7
- Annotations
- Code blocks: different ways to set up syntax highlighting for code blocks, either during build time using Pygments or during runtime using a JavaScript syntax highlighter
- Snippets: adds the ability to embed content from arbitrary files into a document, including other documents or source files, by using a simple syntax
Example mkdocs.yml
configuration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
Plugins🔗
- mkdocs-ezlinked-plugin: enables easier linking between pages
- mkdocs-autolinks-plugin: Simplified relative linking between chapters.
- tags
- mkdocs-mermaid2-plugin: A Mermaid graphs plugin for mkdocs (difference to Diagrams superfences?) ^9b0fb2
-
exclude: mkdocs plugin that lets you exclude files or trees from your output
1 2 3 4 5 6 7 8
plugins: - exclude: glob: - exclude/this/path/* - "*.tmp" regex: - '.*\.(tmp|bin|tar)$'
- mkdocs-exclude-search: Exclude selected files or sections from the search index.
- [mkdocs-table-reader-plugin](https://github.com/timvink/mkdocs-table-reader-plugin
- mkdocs-redirects: Page redirects for moved/renamed pages
- mkdocs-macros: A plugin for unleashing the power of Mkdocs, by using variables and macros
- mkdocs-gitlab-plugin: MkDocs plugin to transform strings such as #1234, %56, or !789 into links to a GitLab repository.
- mkdocs-ezlinked-plugin: enables easier linking between pages
- Obsidian compatibility: (Wiki-)links, admonitions/callouts, (nested) tags
- mkdocs-obsidian-support-plugin: convert Obsidian call-outs and wiki-link images to mkdocs-material compatible code
Issues:- callouts with open/closed modifiers
[!info]+/-
aren’t handled and the+/-
becomes a list bullet point
- callouts with open/closed modifiers
- mkdocs-obsidian-bridge: currently only handling links (allow partial path, selecting file with shortest match, style dead links)
- mkdocs-obsidian-support-plugin: convert Obsidian call-outs and wiki-link images to mkdocs-material compatible code
- mkdocs-magiclinks-plugin: using PyMarkdown extension MagicLink
Editing🔗
See also Markdown.
MkDocs uses the Python Markdown library to translate Markdown files into HTML
Example
1 2 3 4 5 6 7 8 9 10 |
|
Live-reload running mkdocs serve
This command by default rebuilds every page, without caching. When editing a single page this can be very frustrating as it may take a while until the results are rendered. With certain caveats,3 mkdocs serve --dirty
can be used, to only rebuild pages that were changed.
Features🔗
- embedding external files: pymdown-extension snippets (Obsidian syntax for embedding other notes could be translated to use this, see project MkDocs-Obsidian compatibility #idea/tech/mkdocs #idea/tech/obsidian)
- snippets notation
- can be used to keep a central file of references, e.g. a glossary, that can be included and things like hyperlinks defined therein can be accessed
Integrations🔗
Search🔗
A search plugin is provided by default with MkDocs which uses lunr.js as a search engine.1
Compatibility🔗
Obsidian🔗
As can be expected not all Markdown renders the same as different specifications are used.2 I have been working on a [MkDocs template] with some changes to the default Markdown config and adding some extensions/plugins to achieve as much as possible compatibility. The [list of to-dos] is getting shorter, but some critical features are yet missing.
Then there are some quite helpful plugins in Obsidian, especially Dataview. There have been requests in the forums, but no solution yet.
Maybe one day there will be a MkDocs DataView plugin, or system-independent plugins. For now, export rendered DataView results from Obsidian.
add missing links
References🔗
- catalog: A list of awesome MkDocs projects and plugins.
- Blog: Create a Personal Site