Fixed rendering in blog plugin with markdown.extensions.toc

This commit is contained in:
squidfunk 2023-08-22 15:20:10 +02:00
parent fe47f40a06
commit 6ee9df6e1a
No known key found for this signature in database
GPG Key ID: 5ED40BC4F9C436DF
2 changed files with 30 additions and 20 deletions

View File

@ -242,16 +242,21 @@ class Category(View):
def _patch(config: MkDocsConfig):
config = copy(config)
# Copy configuration that needs to be patched
# Copy parts of configuration that needs to be patched
config.validation = copy(config.validation)
config.validation.links = copy(config.validation.links)
config.markdown_extensions = copy(config.markdown_extensions)
config.mdx_configs = copy(config.mdx_configs)
config.mdx_configs["toc"] = copy(config.mdx_configs.get("toc", {}))
# Make sure that the author did not add another instance of the table of
# contents extension to the configuration, as this leads to weird behavior
if "markdown.extensions.toc" in config.markdown_extensions:
config.markdown_extensions.remove("markdown.extensions.toc")
# In order to render excerpts for posts, we need to make sure that the
# table of contents extension is appropriately configured
config.mdx_configs["toc"] = {
**config.mdx_configs["toc"],
**config.mdx_configs.get("toc", {}),
**{
"anchorlink": True, # Render headline as clickable
"baselevel": 2, # Render h1 as h2 and so forth

View File

@ -242,16 +242,21 @@ class Category(View):
def _patch(config: MkDocsConfig):
config = copy(config)
# Copy configuration that needs to be patched
# Copy parts of configuration that needs to be patched
config.validation = copy(config.validation)
config.validation.links = copy(config.validation.links)
config.markdown_extensions = copy(config.markdown_extensions)
config.mdx_configs = copy(config.mdx_configs)
config.mdx_configs["toc"] = copy(config.mdx_configs.get("toc", {}))
# Make sure that the author did not add another instance of the table of
# contents extension to the configuration, as this leads to weird behavior
if "markdown.extensions.toc" in config.markdown_extensions:
config.markdown_extensions.remove("markdown.extensions.toc")
# In order to render excerpts for posts, we need to make sure that the
# table of contents extension is appropriately configured
config.mdx_configs["toc"] = {
**config.mdx_configs["toc"],
**config.mdx_configs.get("toc", {}),
**{
"anchorlink": True, # Render headline as clickable
"baselevel": 2, # Render h1 as h2 and so forth