Skip to content

Commit

Permalink
feat: Add ansi option to mark ANSI extra as required or not
Browse files Browse the repository at this point in the history
This helps decide whether to include the ANSI CSS file into the final site.

Issue #28: #28
Issue #29: #29
  • Loading branch information
pawamoy committed Jan 5, 2024
1 parent e6ff1dd commit 27743c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ markdown_extensions:

plugins:
- search
- markdown-exec
- markdown-exec:
ansi: required
- gen-files:
scripts:
- scripts/gen_ref_nav.py
Expand Down
5 changes: 4 additions & 1 deletion src/markdown_exec/mkdocs_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 27743c2

Please sign in to comment.