import re from mistune.markdown import Markdown DIRECTIVE_PATTERN = r":(?:class|func|meth|attr|exc|mod|data|const|obj|keyword|option|cmdoption|envvar):`(?Psanic\.[^`]+)`" # noqa: E501 def _parse_inline_directive(inline, m: re.Match, state): print("inline_directive.py: _parse_inline_directive", m.group("ref")) state.append_token( { "type": "inline_directive", "attrs": {}, "raw": m.group("ref"), } ) return m.end() def inline_directive(md: Markdown): print("Registering inline_directive") md.inline.register("inline_directive", DIRECTIVE_PATTERN, _parse_inline_directive, before="escape",)