sanic/guide/webapp/display/plugins/inline_directive.py

21 lines
677 B
Python
Raw Normal View History

2023-09-10 12:29:49 +01:00
import re
from mistune.markdown import Markdown
DIRECTIVE_PATTERN = r":(?:class|func|meth|attr|exc|mod|data|const|obj|keyword|option|cmdoption|envvar):`(?P<ref>sanic\.[^`]+)`" # 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",)