nixos-render-docs: prepare for plugins

we will soon add plugins to this tool to support nixos markdown features
that aren't readily supported with markdown-it plugins. since we will
have to test these plugin we'll need access to the parser, and since
we'll also want to add functions that require postprocessing of a parsed
token stream we also add the necessary hooks now.
This commit is contained in:
pennae 2023-01-21 23:04:34 +01:00
parent c2e638391e
commit 41a5c3a93d

View File

@ -239,5 +239,14 @@ class Converter(ABC):
self._md.use(myst_role_plugin)
self._md.enable(["smartquotes", "replacements"])
def _post_parse(self, tokens: list[Token]) -> list[Token]:
return tokens
def _parse(self, src: str, env: Optional[MutableMapping[str, Any]] = None) -> list[Token]:
tokens = self._md.parse(src, env if env is not None else {})
return self._post_parse(tokens)
def _render(self, src: str) -> str:
return self._md.render(src) # type: ignore[no-any-return]
env: dict[str, Any] = {}
tokens = self._parse(src, env)
return self._md.renderer.render(tokens, self._md.options, env) # type: ignore[no-any-return]