-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Provide a MkDocs plugin for easier setup
- Loading branch information
Showing
4 changed files
with
45 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""This module contains an optional plugin for MkDocs.""" | ||
|
||
from mkdocs.config import Config, config_options | ||
from mkdocs.plugins import BasePlugin | ||
|
||
from markdown_exec import formatter, validator | ||
|
||
|
||
class MarkdownExecPlugin(BasePlugin): | ||
"""MkDocs plugin to easily enable custom fences for code blocks execution.""" | ||
|
||
config_scheme = (("languages", config_options.Type(list, default=["python"])),) | ||
|
||
def on_config(self, config: Config, **kwargs) -> Config: # noqa: D102 | ||
self.languages = self.config["languages"] | ||
|
||
mdx_configs = config.setdefault("mdx_configs", {}) | ||
superfences = mdx_configs.setdefault("pymdownx.superfences", {}) | ||
custom_fences = superfences.setdefault("custom_fences", []) | ||
for language in self.languages: | ||
custom_fences.append( | ||
{ | ||
"name": language, | ||
"class": language, | ||
"validator": validator, | ||
"format": formatter, | ||
} | ||
) | ||
return config |