13
13
from mkdocs .plugins import BasePlugin
14
14
from mkdocs .utils import write_file
15
15
16
- from markdown_exec import formatter , formatters , validator
17
16
from markdown_exec ._internal .logger import patch_loggers
17
+ from markdown_exec ._internal .main import formatter , formatters , validator
18
18
from markdown_exec ._internal .rendering import MarkdownConverter , markdown_config
19
19
20
20
if TYPE_CHECKING :
27
27
try :
28
28
__import__ ("pygments_ansi_color" )
29
29
except ImportError :
30
- ansi_ok = False
30
+ _ansi_ok = False
31
31
else :
32
- ansi_ok = True
32
+ _ansi_ok = True
33
33
34
34
35
35
class _LoggerAdapter (logging .LoggerAdapter ):
@@ -71,7 +71,7 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig | None:
71
71
In this hook, we add custom fences for all the supported languages.
72
72
73
73
We also save the Markdown extensions configuration
74
- into [`markdown_config`][markdown_exec.rendering. markdown_config].
74
+ into [`markdown_config`][markdown_exec.markdown_config].
75
75
76
76
Arguments:
77
77
config: The MkDocs config object.
@@ -82,7 +82,7 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig | None:
82
82
if "pymdownx.superfences" not in config ["markdown_extensions" ]:
83
83
message = "The 'markdown-exec' plugin requires the 'pymdownx.superfences' Markdown extension to work."
84
84
raise PluginError (message )
85
- if self .config .ansi in ("required" , True ) and not ansi_ok :
85
+ if self .config .ansi in ("required" , True ) and not _ansi_ok :
86
86
raise PluginError (
87
87
"The configuration for the 'markdown-exec' plugin requires "
88
88
"that it is installed with the 'ansi' extra. "
@@ -113,14 +113,16 @@ def on_env(
113
113
config : MkDocsConfig ,
114
114
files : Files , # noqa: ARG002
115
115
) -> Environment | None :
116
- if self .config .ansi in ("required" , True ) or (self .config .ansi == "auto" and ansi_ok ):
116
+ """Add assets to the environment."""
117
+ if self .config .ansi in ("required" , True ) or (self .config .ansi == "auto" and _ansi_ok ):
117
118
self ._add_css (config , "ansi.css" )
118
119
if "pyodide" in self .languages :
119
120
self ._add_css (config , "pyodide.css" )
120
121
self ._add_js (config , "pyodide.js" )
121
122
return env
122
123
123
124
def on_post_build (self , * , config : MkDocsConfig ) -> None : # noqa: ARG002
125
+ """Reset the plugin state."""
124
126
MarkdownConverter .counter = 0
125
127
markdown_config .reset ()
126
128
if self .mkdocs_config_dir is None :
@@ -130,7 +132,7 @@ def on_post_build(self, *, config: MkDocsConfig) -> None: # noqa: ARG002
130
132
131
133
def _add_asset (self , config : MkDocsConfig , asset_file : str , asset_type : str ) -> None :
132
134
asset_filename = f"assets/_markdown_exec_{ asset_file } "
133
- asset_content = Path (__file__ ).parent .joinpath ("assets" , asset_file ).read_text ()
135
+ asset_content = Path (__file__ ).parent .parent . joinpath ("assets" , asset_file ).read_text ()
134
136
write_file (asset_content .encode ("utf-8" ), os .path .join (config .site_dir , asset_filename ))
135
137
config [f"extra_{ asset_type } " ].insert (0 , asset_filename )
136
138
0 commit comments