Project documentation with Markdown.
Fix mkdocs serve
sometimes locking up all browser tabs when navigating quickly (#3390)
Add many new supported languages for "search" plugin - update lunr-languages to 1.12.0 (#3334)
Bugfix (regression in 1.5.0): In "readthedocs" theme the styling of "breadcrumb navigation" was broken for nested pages (#3383)
Built-in themes now also support Chinese (Traditional, Taiwan) language (#3370)
Plugins can now set File.page
to their own subclass of Page
. There is also now a warning if File.page
is set to anything other than a strict subclass of Page
. (#3367, #3381)
Note that just instantiating a Page
sets the file automatically, so care needs to be taken not to create an unneeded Page
.
Other small improvements; see commit log.
Bugfix (regression in 1.5.0): Restore functionality of --no-livereload
. (#3320)
Bugfix (regression in 1.5.0): The new page title detection would sometimes be unable to drop anchorlinks - fix that. (#3325)
Partly bring back pre-1.5 API: extra_javascript
items will once again be mostly strings, and only sometimes ExtraStringValue
(when the extra script
functionality is used).
Plugins should be free to append strings to config.extra_javascript
, but when reading the values, they must still make sure to read it as str(value)
in case it is an ExtraScriptValue
item. For querying the attributes such as .type
you need to check isinstance
first. Static type checking will guide you in that. (#3324)
See commit log.
Bugfix (regression in 1.5.0): Make it possible to treat ExtraScriptValue
as a path. This lets some plugins still work despite the breaking change.
Bugfix (regression in 1.5.0): Prevent errors for special setups that have 3 conflicting files, such as index.html
, index.md
and README.md
(#3314)
See commit log.
New: MkDocs now accepts donations. Please consider supporting the current maintainer at my new GitHub sponsorship page.
MkDocs has been a totally free project since the beginning and wasn't accepting funds. MkDocs will remain free of paywalls, but now you can show your support with donations (one-time and/or recurring).
Donate for MkDocs - @oprypin sponsors page
And please also consider these other individuals who have been contributing to the ecosystem for a long time and check out their donations pages:
@facelessuser @pawamoy @Ultrabug
mkdocs get-deps
This command guesses the Python dependencies that a MkDocs site requires in order to build. It simply prints the PyPI packages that need to be installed. In the terminal it can be combined directly with an installation command as follows:
pip install $(mkdocs get-deps)
The idea is that right after running this command, you can directly follow it up with mkdocs build
and it will almost always "just work", without needing to think which dependencies to install.
The way it works is by scanning mkdocs.yml
for themes:
, plugins:
, markdown_extensions:
items and doing a reverse lookup based on a large list of known projects (catalog, see below).
Of course, you're welcome to use a "virtualenv" with such a command. Also note that for environments that require stability (for example CI) directly installing deps in this way is not a very reliable approach as it precludes dependency pinning.
The command allows overriding which config file is used (instead of mkdocs.yml
in the current directory) as well as which catalog of projects is used (instead of downloading it from the default location). See mkdocs get-deps --help
.
Context: #3205
Check out https://github.com/mkdocs/catalog and add all your general-purpose plugins, themes and extensions there, so that they can be looked up through mkdocs get-deps
.
This was renamed from "best-of-mkdocs" and received significant updates. In addition to pip
installation commands, the page now shows the config boilerplate needed to add a plugin.
As you may know, within Markdown, MkDocs really only recognizes relative links that lead to another physical
*.md
document (or media file). This is a good convention to follow because then the source pages are also freely browsable without MkDocs, for example on GitHub. MkDocs knows that in the output it should turn those*.md
links into*.html
as appropriate, and it would also always tell you if such a link doesn't actually lead to an existing file.
However, the checks for links were really loose and had many concessions. For example, links that started with /
("absolute") and links that ended with /
were left as is and no warning was shown, which allowed such very fragile links to sneak into site sources: links that happen to work right now but get no validation and links that confusingly need an extra level of ..
with use_directory_urls
enabled.
Now, in addition to validating relative links, MkDocs will print INFO
messages for unrecognized types of links (including absolute links). They look like this:
INFO - Doc file 'example.md' contains an absolute link '/foo/bar/', it was left as is. Did you mean 'foo/bar.md'?
If you don't want any changes, not even the INFO
messages, and wish to revert to the silence from MkDocs 1.4, add the following configs to mkdocs.yml
(not recommended):
validation:
absolute_links: ignore
unrecognized_links: ignore
If, on the opposite end, you want these to print WARNING
messages and cause mkdocs build --strict
to fail, you are recommended to configure these to warn
instead.
See documentation for actual recommended settings and more details. Context: #3283
Links to documents in the nav
configuration now also have configurable validation, though with no changes to the defaults.
You are welcomed to turn on validation for files that were forgotten and excluded from the nav. Example:
validation:
nav:
omitted_files: warn
absolute_links: warn
This can make the following message appear with the WARNING
level (as opposed to INFO
as the only option previously), thus being caught by mkdocs --strict
:
INFO - The following pages exist in the docs directory, but are not included in the "nav" configuration: ...
See documentation. Context: #3283, #1755
There is a new config not_in_nav
. With it, you can mark particular patterns of files as exempt from the above omitted_files
warning type; no messages will be printed for them anymore. (As a corollary, setting this config to *
is the same as ignoring omitted_files
altogether.)
This is useful if you generally like these warnings about files that were forgotten from the nav, but still have some pages that you knowingly excluded from the nav and just want to build and copy them.
The not_in_nav
config is a set of gitignore-like patterns. See the next section for an explanation of another such config.
See documentation. Context: #3224, #1888
There is a new config exclude_docs
that tells MkDocs to ignore certain files under docs_dir
and not copy them to the built site
as part of the build.
Historically MkDocs would always ignore file names starting with a dot, and that's all. Now this is all configurable: you can un-ignore these and/or ignore more patterns of files.
The exclude_docs
config follows the .gitignore pattern format and is specified as a multiline YAML string. For example:
exclude_docs: |
*.py # Excludes e.g. docs/hooks/foo.py
/drafts # Excludes e.g. docs/drafts/hello.md
/requirements.txt # Excludes docs/requirements.txt
Validation of links (described above) is also affected by exclude_docs
. During mkdocs serve
the messages explain the interaction, whereas during mkdocs build
excluded files are as good as nonexistent.
As an additional related change, if you have a need to have both README.md
and index.md
files in a directory but publish only one of them, you can now use this feature to explicitly ignore one of them and avoid warnings.
See documentation. Context: #3224
The exclude_docs
config has another behavior: all excluded Markdown pages will still be previewable in mkdocs serve
only, just with a "DRAFT" marker on top. Then they will of course be excluded from mkdocs build
or gh-deploy
.
If you don't want mkdocs serve
to have any special behaviors and instead want it to perform completely normal builds, use the new flag mkdocs serve --clean
.
See documentation. Context: #3224
mkdocs serve
no longer exits after build errorsIf there was an error (from the config or a plugin) during a site re-build, mkdocs serve
used to exit after printing a stack trace. Now it will simply freeze the server until the author edits the files to fix the problem, and then will keep reloading.
But errors on the first build still cause mkdocs serve
to exit, as before.
Context: #3255
MkDocs always had the ability to infer the title of a page (if it's not specified in the nav
) based on the first line of the document, if it had a <h1>
heading that had to written starting with the exact character #
. Now any style of Markdown heading is understood (#1886). Due to the previous simplistic parsing, it was also impossible to use attr_list
attributes in that first heading (#3136). Now that is also fixed.
This is aimed at extensions such as pymdownx.snippets
or markdown_include.include
: you can now specify their include paths to be relative to the currently rendered Markdown document, or relative to the docs_dir
. Any other extension can of course also make use of the new !relative
YAML tag.
markdown_extensions:
- pymdownx.snippets:
base_path: !relative
See documentation. Context: #2154, #3258
<script>
tags can specify type="module"
and other attributesIn extra_javascript
, if you use the .mjs
file extension or explicitly specify a type: module
key, the script will be added with the type="module"
attribute. defer: true
and async: true
keys are also available.
See updated documentation for extra_javascript
.
At first this is only supported in built-in themes, other themes need to follow up, see below.
Context: #3237
Using the construct {% for script in extra_javascript %}
is now fully obsolete because it cannot allow customizing the attributes of the <script>
tag. It will keep working but blocks some of MkDocs' features.
Instead, you now need to use config.extra_javascript
(which was already the case for a while) and couple it with the new script_tag
filter:
{%- for script in config.extra_javascript %}
{{ script | script_tag }}
{%- endfor %}
See documentation.
Breaking change: config.extra_javascript
is no longer a plain list of strings, but instead a list of ExtraScriptValue
items. So you can no longer treat the list values as strings. If you want to keep compatibility with old versions, just always reference the items as str(item)
instead. And you can still append plain strings to the list if you wish. See information about <script>
tags above. Context: #3237
File
has a new attribute inclusion
. Its value is calculated from both the exclude_docs
and not_in_nav
configs, and implements their behavior. Plugins can read this value or write to it. New File
instances by default follow whatever the configs say, but plugins can choose to make this decision explicitly, per file.
When creating a File
, one can now set a dest_uri
directly, rather than having to update it (and other dependent attributes) after creation. Context
A new config option was added - DictOfItems
. Similarly to ListOfItems
, it validates a mapping of config options that all have the same type. Keys are arbitrary but always strings. Context: #3242
A new function get_plugin_logger
was added. In order to opt into a standardized way for plugins to log messages, please use the idiom:
log = mkdocs.plugins.get_plugin_logger(__name__)
...
log.info("Hello, world")
Context: #3245
SubConfig
config option can be conveniently subclassed with a particular type of config specified. For example, class ExtraScript(SubConfig[ExtraScriptValue]):
. To see how this is useful, search for this class in code. Context
Bugfix: SubConfig
had a bug where paths (from FilesystemObject
options) were not made relative to the main config file as intended, because config_file_path
was not properly inherited to it. This is now fixed. Context: #3265
Config
members now have a way to avoid clashing with Python's reserved words. This is achieved by stripping a trailing underscore from each member's name.
Example of adding an async
boolean option that can be set by the user as async: true
and read programmatically as config.async_
:
class ExampleConfig(Config):
async_ = Type(bool, default=False)
Previously making a config key with a reserved name was impossible with new-style schemas. Context
Theme
has its attributes properly declared and gained new attributes theme.locale
, theme.custom_dir
.
Some type annotations were made more precise. For example:
context
parameter has gained the type TemplateContext
(TypedDict
). Context
Page
, Section
, Link
now have a common base class StructureItem
. Context
Config
and only accept MkDocsConfig
as was originally intended. Context
config.mdx_configs
got a proper type. Context: #3229Built-in themes mostly stopped relying on <script defer>
. This may affect some usages of extra_javascript
, mainly remove the need for custom handling of "has the page fully loaded yet". Context: #3237
"mkdocs" theme now has a styling for >
blockquotes, previously they were not distinguished at all. Context: #3291
"readthedocs" theme was updated to v1.2.0 according to upstream, with improved styles for <kbd>
and breadcrumb navigation. Context: #3058
Both built-in themes had their version of highlight.js updated to 11.8.0, and jQuery updated to 3.6.0.
Regression in 1.2 - relative paths in the nav could no longer traverse above the site's root and were truncated to the root. Although such traversal is discouraged and produces a warning, this was a documented behavior. The behavior is now restored.
Context: #2752, #3010
This can be used for config overrides on the fly. See updated section at the bottom of Configuration Inheritance.
The command to use this is mkdocs build -f -
. In previous versions doing this led to an error.
mkdocs --no-color build
disables color output and line wrapping. This option is also available through an environment variable NO_COLOR=true
. Context: #3282mkdocs build --no-strict
overrides the strict
config to false
. Context: #3254mkdocs build -f -
(described directly above).mkdocs serve --clean
(described above).mkdocs serve --dirty
is the new name of mkdocs serve --dirtyreload
.extra_javascript
underwent a change that can break plugins in rare cases, and it requires attention from theme developers. See respective entries above.
Python-Markdown was unpinned from <3.4
. That version is known to remove functionality. If you are affected by those removals, you can still choose to pin the version for yourself: Markdown <3.4
. Context: #3222, #2892
mkdocs.utils.warning_filter
now shows a warning about being deprecated. It does nothing since MkDocs 1.2. Consider get_plugin_logger
or just logging under mkdocs.plugins.*
instead. Context: #3008
Accessing the _vars
attribute of a Theme
is deprecated - just access the keys directly.
Accessing the user_configs
attribute of a Config
is deprecated. Note: instead of config.user_configs[*]['theme']['custom_dir']
, please use the new attribute config.theme.custom_dir
.
Other small improvements; see commit log.
Bugfix: for the hooks
feature, modules no longer fail to load if using some advanced Python features like dataclasses (#3193)
Bugfix: Don't create None
sitemap entries if the page has no populated URL - affects sites that exclude some files from navigation (07a297b
)
"readthedocs" theme:
hljs_style:
config, same as "mkdocs" theme (#3199)Translations:
zh_CN
translation (#3125)tr_TR
translation becomes just tr
- usage should remain unaffected (#3195)See commit log.
Officially support Python 3.11 (#3020)
Note: Simply upgrading to Python 3.11 can cut off 10-15% of your site's build time.
Support multiple instances of the same plugin (#3027)
If a plugin is specified multiple times in the list under the plugins:
config, that will create 2 (or more) instances of the plugin with their own config each.
Previously this case was unforeseen and, as such, bugged.
Now even though this works, by default a warning will appear from MkDocs anyway, unless the plugin adds a class variable supports_multiple_instances = True
.
Bugfix (regression in 1.4.1): Don't error when a plugin puts a plain string into warnings
(#3016)
Bugfix: Relative links will always render with a trailing slash (#3022)
Previously under use_directory_urls
, links from a sub-page to the main index page rendered as e.g. <a href="../..">
even though in all other cases the links look like <a href="../../">
. This caused unwanted behavior on some combinations of Web browsers and servers. Now this special-case bug was removed.
Built-in "mkdocs" theme now also supports Norwegian language (#3024)
Plugin-related warnings look more readable (#3016)
See commit log.
Support theme-namespaced plugin loading (#2998)
Plugins' entry points can be named as 'sometheme/someplugin'. That will have the following outcome:
plugins: [sometheme/someplugin]
.One can also specify plugins: ['/someplugin']
instead of plugins: ['someplugin']
to definitely avoid the theme-namespaced plugin.
Bugfix: mkdocs serve
will work correctly with non-ASCII paths and redirects (#3001)
Windows: 'colorama' is now a dependency of MkDocs, to ensure colorful log output (#2987)
Plugin-related config options have more reliable validation and error reporting (#2997)
Translation sub-commands of setup.py
were completely dropped. See documentation [1] [2] for their new replacements (#2990)
The 'mkdocs' package (wheel and source) is now produced by Hatch build system and pyproject.toml instead of setup.py (#2988)
Other small improvements; see commit log.
The new hooks:
config allows you to add plugin-like event handlers from local Python files, without needing to set up and install an actual plugin.
See documentation.
edit_uri
flexibility (#2927)There is a new edit_uri_template:
config.
It works like edit_uri
but more generally covers ways to construct an edit URL.
See documentation.
Additionally, the edit_uri
functionality will now fully work even if repo_url
is omitted (#2928)
Note: this release has big changes to the implementation of plugins and their configs. But, the intention is to have zero breaking changes in all reasonably common use cases. Or at the very least if a code fix is required, there should always be a way to stay compatible with older MkDocs versions. Please report if this release breaks something.
Plugins can now choose to set a priority value for their event handlers. This can override the old behavior where for each event type, the handlers are called in the order that their plugins appear in the plugins
config.
If this is set, events with higher priority are called first. Events without a chosen priority get a default of 0. Events that have the same priority are ordered as they appear in the config.
Recommended priority values: 100
"first", 50
"early", 0
"default", -50
"late", -100
"last".
As different plugins discover more precise relations to each other, the values should be further tweaked.
See documentation.
mkdocs serve
(#2972)The new events are on_startup
and on_shutdown
. They run at the very beginning and very end of an mkdocs
invocation.
on_startup
also receives information on how mkdocs
was invoked (e.g. serve
--dirtyreload
).
See documentation.
File.src_path
to not deal with backslashes (#2930)The property src_path
uses backslashes on Windows, which doesn't make sense as it's a virtual path.
To not make a breaking change, there's no change to how this property is used, but now you should:
File.src_uri
instead of File.src_path
File.dest_uri
instead of File.dest_path
.These consistently use forward slashes, and are now the definitive source that MkDocs itself uses.
See source code.
As a related tip: you should also stop using os.path.*
or pathlib.Path()
to deal with these paths, and instead use posixpath.*
or pathlib.PurePosixPath()
MkDocs' plugin event methods now have type annotations. You might have been adding annotations to events already, but now they will be validated to match the original.
See source code and documentation.
One big update is that now you should annotate method parameters more specifically as config: defaults.MkDocsConfig
instead of config: base.Config
. This not only makes it clear that it is the main config of MkDocs itself, but also provides type-safe access through attributes of the object (see next section).
See source code and documentation.
When developing a plugin, the settings that it accepts used to be specified in the config_scheme
variable on the plugin class.
This approach is now soft-deprecated, and instead you should specify the config in a sub-class of base.Config
.
Old example:
from mkdocs import plugins
from mkdocs.config import base, config_options
class MyPlugin(plugins.BasePlugin):
config_scheme = (
('foo', config_options.Type(int)),
('bar', config_options.Type(str, default='')),
)
def on_page_markdown(self, markdown: str, *, config: base.Config, **kwargs):
if self.config['foo'] < 5:
if config['site_url'].startswith('http:'):
return markdown + self.config['baz']
This code snippet actually has many mistakes but it will pass all type checks and silently run and even succeed in some cases.
So, on to the new equivalent example, changed to new-style schema and attribute-based access:
(Complaints from "mypy" added inline)
from mkdocs import plugins
from mkdocs.config import base, config_options as c
class MyPluginConfig(base.Config):
foo = c.Optional(c.Type(int))
bar = c.Type(str, default='')
class MyPlugin(plugins.BasePlugin[MyPluginConfig]):
def on_page_markdown(self, markdown: str, *, config: base.MkDocsConfig, **kwargs):
if self.config.foo < 5: # Error, `foo` might be `None`, need to check first.
if config.site_url.startswith('http:'): # Error, MkDocs' `site_url` also might be `None`.
return markdown + self.config.baz # Error, no such attribute `baz`!
This lets you notice the errors from a static type checker before running the code and fix them as such:
class MyPlugin(plugins.BasePlugin[MyPluginConfig]):
def on_page_markdown(self, markdown: str, *, config: base.MkDocsConfig, **kwargs):
if self.config.foo is not None and self.config.foo < 5: # OK, `int < int` is valid.
if (config.site_url or '').startswith('http:'): # OK, `str.startswith(str)` is valid.
return markdown + self.config.bar # OK, `str + str` is valid.
See documentation.
Also notice that we had to explicitly mark the config attribute foo
as Optional
.
The new-style config has all attributes marked as required by default, and specifying required=False
or required=True
is not allowed!
config_options.Optional
(#2962)Wrapping something into Optional
is conceptually similar to "I want the default to be None
" -- and you have to express it like that, because writing default=None
doesn't actually work.
Breaking change: the method BaseConfigOption.is_required()
was removed. Use .required
instead. (#2938)
And even the required
property should be mostly unused now.
For class-based configs, there's a new definition for whether an option is "required":
config_options.Optional
.config_options.ListOfItems
(#2938)Defines a list of items that each must adhere to the same constraint. Kind of like a validated Type(list)
Examples how to express a list of integers (with from mkdocs.config import config_options as c
):
Description | Code entry |
---|---|
Required to specify | foo = c.ListOfItems(c.Type(int)) |
Optional, default is [] | foo = c.ListOfItems(c.Type(int), default=[]) |
Optional, default is None | foo = c.Optional(c.ListOfItems(c.Type(int))) |
See more examples in documentation.
config_options.SubConfig
(#2807)SubConfig
used to silently ignore all validation of its config options. Now you should pass validate=True
to it or just use new class-based configs where this became the default.
So, it can be used to validate a nested sub-dict with all keys pre-defined and value types strictly validated.
See examples in documentation.
URL
's default is now None
instead of ''
. This can still be checked for truthiness in the same way - if config.some_url:
(#2962)
FilesystemObject
is no longer abstract and can be used directly, standing for "file or directory" with optional existence checking (#2938)
Bug fixes:
SubConfig
, ConfigItems
, MarkdownExtensions
to not leak values across different instances (#2916, #2290)SubConfig
raises the correct kind of validation error without a stack trace (#2938)config_options.Deprecated(moved_to)
(#2963)Tweaked logic for handling ConfigOption.default
(#2938)
Deprecated config option classes: ConfigItems
(#2983), OptionallyRequired
(#2962), RepoURL
(#2927)
Styles of admonitions in "MkDocs" theme (#2981):
<details>
tag, to support Markdown extensions that provide it (pymdownx.details, callouts)Built-in themes now also support these languages:
extra_css:
and extra_javascript:
warn if a backslash \
is passed to them. (#2930, #2984)
Show DeprecationWarning
s as INFO messages. (#2907)
If any plugin or extension that you use relies on deprecated functionality of other libraries, it is at risk of breaking in the near future. Plugin developers should address these in a timely manner.
Avoid a dependency on importlib_metadata
starting from Python 3.10 (#2959)
Drop support for Python 3.6 (#2948)
mkdocs.utils
:
create_media_urls
and normalize_url
warn if a backslash \
is passed to them. (#2930)is_markdown_file
stops accepting case-insensitive variants such as .MD
, which is how MkDocs build was already operating. (#2912)modified_time
, reduce_list
, get_html_path
, get_url_path
, is_html_file
, is_template_file
. (#2912)If a plugin adds paths to watch
in LiveReloadServer
, it can now unwatch
them. (#2777)
Bugfix (regression in 1.2): Support listening on an IPv6 address in mkdocs serve
. (#2951)
Other small improvements; see commit log.
Pin Python-Markdown version to <3.4, thus excluding its latest release that breaks too many external extensions (#2893)
When a Markdown extension fails to load, print its name and traceback (#2894)
Bugfix for "readthedocs" theme (regression in 1.3.0): add missing space in breadcrumbs (#2810)
Bugfix: don't complain when a file "readme.md" (lowercase) exists, it's not recognized otherwise (#2852)
Built-in themes now also support these languages:
Other small improvements; see commit log.
ReadTheDocs theme updated from v0.4.1 to v1.0.0 according to upstream (#2585)
The most notable changes:
logo
: Rather than displaying the site_name
in the title, one can specify a path to an image to display instead.anonymize_ip
for Google Analytics.Built-in themes now also support these languages:
Support custom directories to watch when running mkdocs serve
(#2642)
MkDocs by default watches the docs directory and the config file. Now there is a way to add more directories to watch for changes, either via the YAML watch
key or the command line flag --watch
.
Normally MkDocs never reaches into any other directories (so this feature shouldn't be necessary), but some plugins and extensions may do so.
See documentation.
New --no-history
option for gh_deploy
(#2594)
Allows to discard the history of commits when deploying, and instead replace it with one root commit
An XSS vulnerability when using the search function in built-in themes was fixed (#2791)
Setting the edit_uri
option no longer erroneously adds a trailing slash to repo_url
(#2733)
Breaking change: the pages
config option that was deprecated for a very long time now causes an error when used (#2652)
To fix the error, just change from pages
to nav
.
Performance optimization: during startup of MkDocs, code and dependencies of other commands will not be imported (#2714)
The most visible effect of this is that dependencies of mkdocs serve
will not be imported when mkdocs build
is used.
Recursively validate nav
(#2680)
Validation of the nested nav
structure has been reworked to report errors early and reliably. Some edge cases have been declared invalid.
Other small improvements; see commit log.