def on_config(self, config): c = Config() if self.config["execute"]: default_preprocessors = MarkdownExporter.default_preprocessors.default_args[ 0 ] default_preprocessors[ default_preprocessors.index( "nbconvert.preprocessors.ExecutePreprocessor" ) ] = ExtraArgsExecutePreprocessor c.default_preprocessors = default_preprocessors c.ExecutePreprocessor.timeout = self.config["timeout"] c.ExecutePreprocessor.allow_errors = self.config["allow_errors"] c.ExtraArgsExecutePreprocessor.enabled = True c.ExtractOutputPreprocessor.enabled = True preamble = [os.path.join(here, "pandas_output_formatter.py")] c.file_extension = ".md" if self.config["preamble"]: preamble.append(self.config["preamble"]) c.ExtraArgsExecutePreprocessor.extra_arguments = [ f"--InteractiveShellApp.exec_files={preamble}", ] template_file = os.path.join(here, "templates", "custom_markdown.tpl") built_in_templates = os.path.join( os.path.dirname(nbconvert.__file__), "templates" ) c.NbConvertBase.display_data_priority = [ "application/vnd.jupyter.widget-state+json", "application/vnd.jupyter.widget-view+json", "application/javascript", "text/markdown", "text/html", "image/svg+xml", "text/latex", "image/png", "image/jpeg", "text/plain", ] exporter = HTMLExporter( config=c, template_file=template_file, template_path=[ os.path.join(here, "templates"), built_in_templates, os.path.join(built_in_templates, "html"), os.path.join(built_in_templates, "skeleton"), ], ) exporter.register_filter( "remove_leading_indentation", remove_leading_indentation ) config["notebook_exporter"] = exporter config["extra_css"].append(os.path.join("css", "ansi-colours.css")) return config
def on_config(self, config: MkDocsConfig): exporter_config = Config() if self.config["execute"]: default_preprocessors = MarkdownExporter.default_preprocessors.default_args[ 0] try: default_preprocessors[default_preprocessors.index( "nbconvert.preprocessors.ExecutePreprocessor" )] = ExtraArgsExecutePreprocessor except ValueError: pass exporter_config.default_preprocessors = default_preprocessors exporter_config.ExecutePreprocessor.timeout = self.config[ "timeout"] exporter_config.ExecutePreprocessor.allow_errors = self.config[ "allow_errors"] exporter_config.ExtraArgsExecutePreprocessor.enabled = True exporter_config.ExtractOutputPreprocessor.enabled = True preamble = [os.path.join(here, "pandas_output_formatter.py")] exporter_config.file_extension = ".md" if self.config["preamble"]: preamble.append(self.config["preamble"]) exporter_config.ExtraArgsExecutePreprocessor.extra_arguments = [ f"--InteractiveShellApp.exec_files={preamble_entry}" for preamble_entry in preamble ] template_file = os.path.join(here, "templates", "custom_markdown.tpl") built_in_templates = jupyter_path("nbconvert", "templates") exporter_config.NbConvertBase.display_data_priority = [ "application/vnd.jupyter.widget-state+json", "application/vnd.jupyter.widget-view+json", "application/javascript", "text/markdown", "text/html", "image/svg+xml", "text/latex", "image/png", "image/jpeg", "text/plain", ] for option, setting in self.config.get("tag_remove_configs", {}).items(): setattr(exporter_config.TagRemovePreprocessor, option, set(setting)) exporter_config.RegexRemovePreprocessor.patterns = self.config.get( "regex_remove_patterns", set()) exporter_config.TagRemovePreprocessor.enabled = True exporter = HTMLExporter( config=exporter_config, template_file=template_file, template_path=[ os.path.join(here, "templates"), *[ os.path.join(built_in_template, "base") for built_in_template in built_in_templates ], ], **self.config.get("exporter_kwargs", {}), ) config["notebook_exporter"] = exporter config["extra_css"].append(os.path.join("css", "ansi-colours.css")) if self.config["enable_default_jupyter_cell_styling"]: config["extra_css"].append(os.path.join("css", "jupyter-cells.css")) if self.config["enable_default_pandas_dataframe_styling"]: config["extra_css"].append( os.path.join("css", "pandas-dataframe.css")) return config