From 27743c20f56dd00ce730e1d028d362a4f95e48c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 5 Jan 2024 19:26:54 +0100 Subject: [PATCH] feat: Add `ansi` option to mark ANSI extra as required or not This helps decide whether to include the ANSI CSS file into the final site. Issue #28: https://github.com/pawamoy/markdown-exec/issues/28 Issue #29: https://github.com/pawamoy/markdown-exec/issues/29 --- mkdocs.yml | 3 ++- src/markdown_exec/mkdocs_plugin.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mkdocs.yml b/mkdocs.yml index c0d86be..b15eb26 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -120,7 +120,8 @@ markdown_extensions: plugins: - search -- markdown-exec +- markdown-exec: + ansi: required - gen-files: scripts: - scripts/gen_ref_nav.py diff --git a/src/markdown_exec/mkdocs_plugin.py b/src/markdown_exec/mkdocs_plugin.py index fff26fe..3a572c6 100644 --- a/src/markdown_exec/mkdocs_plugin.py +++ b/src/markdown_exec/mkdocs_plugin.py @@ -49,6 +49,8 @@ def _get_logger(name: str) -> _LoggerAdapter: class MarkdownExecPluginConfig(Config): """Configuration of the plugin (for `mkdocs.yml`).""" + ansi: str | bool = config_options.Choice(("auto", "off", "required", True, False), default="auto") + """Whether the `ansi` extra is required when installing the package.""" languages: list[str] = config_options.ListOfItems(config_options.Choice(formatters.keys()), default=list(formatters.keys())) """Which languages to enabled the extension for.""" @@ -96,7 +98,8 @@ def on_env( # noqa: D102 config: MkDocsConfig, files: Files, # noqa: ARG002 ) -> Environment | None: - self._add_css(config, "ansi.css") + if self.config.ansi in ("required", True) or (self.config.ansi == "auto" and ansi_ok): + self._add_css(config, "ansi.css") if "pyodide" in self.languages: self._add_css(config, "pyodide.css") self._add_js(config, "pyodide.js")