def on_config(self, config: Config): oldPython = sys.version_info < (3, 8) if oldPython: log.warning( "Python versions lower than 3.8 (current: %s) do not support default namespace! ", str(sys.version_info.major) + "." + str(sys.version_info.minor)) log.warning( "None results while referencing POM_* variables in templates are likely because of that." ) env_vars = {} for name, plugin in config.get('plugins').items(): if name == 'mkdocs-pom-parser-plugin': plugin_config = plugin.__getattribute__("config") if plugin_config.get("debug"): log.setLevel(logging.DEBUG) else: log.setLevel(logging.INFO) path = plugin_config.get('path') if path is not None: log.debug("Configured pom file: %s", path) path = Path(path).resolve() log.info("Resolved pom file: %s", path) if path.exists(): additional = plugin_config.get('additional', {}) env_vars = copy.copy(self.DEFAULT_ENV_VARS) if additional is not None: log.debug("Additional pom variables detected: %s", additional) for key, value in additional.items(): env_vars["POM_" + key.upper()] = value parser = PomParser(path.__str__()) for key, xpath in env_vars.items(): value = parser.findTextByXpath(xpath) env_vars[key] = value else: log.warning( "File %s does not exist or is not readable/accessible!", path) config.update({"pom_env_vars": env_vars}) if env_vars.__sizeof__() > 0: log.info("Exposed pom values as environment variables") log.debug("on_config[POM_ENV_VARS: %s]", config.get("pom_env_vars")) return config
def on_files(self, files: Files, config: Config) -> Files: # noqa: WPS210 """ Files event handler. It's called when MkDocs discovers all files. Here we filter all default pages and pages for translation. :param files: discovered files. :param config: mkdocs global config. :return: files for default language. """ default_language = self.config.get("default_language") all_languages = set([default_language] + list(self.config["languages"])) # Idk we we need to process main_files separate from # translations, but it doesn't work without it. main_files = Files([]) # Aux files, such as js or css. for aux_file in files: if aux_file not in files.documentation_pages(): main_files.append(aux_file) for language in all_languages: self.i18pages[language].append(aux_file) for page in files.documentation_pages(): page_lang = self._get_lang(page) if page_lang == default_language: main_files.append(page) self.i18pages[page_lang].append( self.translate_page(page, Path(config.get("site_dir"))), ) self._sort_translated_files() return main_files
def on_files(self: "FeaturesNotifier", files: Files, config: Config) -> Files: """Overriding the on_files method.""" current_pages = [] docs_dir = config.get("docs_dir") features_file = self.config.get("features_file") config_file = self.config.get("config_file") for file in files: if file.src_path.endswith("md"): current_pages.append(file.src_path) if file.src_path == features_file: features_file = f"{docs_dir}/{file.src_path}" initial_pages, write_mode = get_config(docs_dir=docs_dir, config_file=config_file, current_pages=current_pages) new_pages = [ f"{docs_dir}/{page}" for page in current_pages if page not in initial_pages ] if new_pages and not write_mode: append_config(docs_dir=docs_dir, config_file=config_file, current_pages=current_pages) update_features_file(docs_dir=docs_dir, features_file=features_file, new_pages=new_pages) return files
def on_config(self, config: Config, **kw: Any) -> Config: md_ext = config.get("markdown_extensions", []) if "attr_list" not in md_ext: md_ext.append("attr_list") if "meta" not in md_ext: md_ext.append("meta") config["markdown_extantions"] = md_ext return config
def on_page_content(self, html, page: Page, config: Config, files: Files): repo_url = config.get("repo_url", None) edit_uri = config.get("edit_uri", None) if page.file.src_path in self._edit_paths: path = self._edit_paths.pop(page.file.src_path) if repo_url and edit_uri: page.edit_url = path and urllib.parse.urljoin( urllib.parse.urljoin(repo_url, edit_uri), path) return html
def on_config(self, config: Config, **kwargs) -> Config: enable_on_env = self.config["enable_on_env"] self.enabled = self.config["enabled"] or ( enable_on_env and distutils.util.strtobool(os.getenv(enable_on_env, "0"))) a = config.setdefault("mdx_configs", {}) b = a.setdefault("pymdownx.superfences", {}) c = b.setdefault("custom_fences", []) for ident, ident_config in self.config["identifiers"].items(): fence = { "name": ident, "class": ident, "validator": self.validator, "format": functools.partial(self.formatter, ident_config), } c.append(fence) return config
and some text after """ BLOCKS_MARKDOWN_EXAMPLE = """ # hello world some text before <!--codeinclude--> [blocks](Blocks.java) inside_block:main <!--/codeinclude--> and some text after """ c = Config(schema=DEFAULT_SCHEMA) c["site_url"] = "http://example.org/" PAGE_EXAMPLE = Page( "", File(os.path.abspath("./fixture/text.md"), "/src", "/dest", False), c) class PluginTextCase(unittest.TestCase): def test_simple_case(self): plugin = CodeIncludePlugin() result = plugin.on_page_markdown(MARKDOWN_EXAMPLE, PAGE_EXAMPLE, dict()) print(result) self.assertEqual( textwrap.dedent("""