32 """Convert GitHub alert blockquotes into admonitions. Returns count converted."""
35 candidates = list(doctree.traverse(nodes.block_quote))
36 for cont
in doctree.traverse(nodes.container):
37 if "quote" in cont.get(
"classes", []):
38 candidates.append(cont)
42 if id(bq)
in seen
or not bq.children:
46 first_para = next((c
for c
in bq.children
if isinstance(c, nodes.paragraph)),
None)
50 head_text = first_para.astext().strip()
51 m = _ALERT_HEADER.match(head_text)
55 kind_raw = m.group(
"kind")
56 kind = kind_raw.lower()
58 NodeClass = _KIND_MAP.get(kind)
59 admon = nodes.admonition()
if NodeClass
is None else NodeClass()
61 admon += nodes.title(text=kind.title())
64 prefix = f
"[!{kind_raw}]"
65 inline_text = head_text.removeprefix(prefix)
69 admon += nodes.paragraph(text=inline_text)
72 for child
in bq.children[1:]:
73 admon += child.deepcopy()
77 f
"[github_alerts] converted {kind!r} (inline->body: {bool(inline_text)})",
80 bq.replace_self(admon)