fix(parser): strip trailing separators and links from subcategory labels

Type Checkers heading now reads 'Type Checkers - [awesome-python-typing](...)'
where a link follows the separator. The old code passed all inline children to
render_inline_text, which included the link URL in the label. Now we take only
the text nodes before the first link and strip trailing punctuation/separators
so the rendered subcategory label is clean.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Vinta Chen
2026-03-23 01:19:05 +08:00
parent 1732a3f29e
commit e1a88410d3

View File

@@ -132,6 +132,7 @@ def _extract_description(nodes: list[SyntaxTreeNode]) -> str:
# --- Entry extraction --------------------------------------------------------
_DESC_SEP_RE = re.compile(r"^\s*[-\u2013\u2014]\s*")
_SUBCAT_TRAILING_RE = re.compile(r"[\s,\-\u2013\u2014]+(also\s+see\s*)?$", re.IGNORECASE)
def _find_child(node: SyntaxTreeNode, child_type: str) -> SyntaxTreeNode | None:
@@ -204,8 +205,13 @@ def _parse_list_entries(
first_link = _find_first_link(inline)
if first_link is None or not _is_leading_link(inline, first_link):
# Subcategory label (plain text or text-before-link) — recurse into nested list
label = render_inline_text(inline.children)
# Subcategory label: take text before the first link, strip trailing separators
pre_link = []
for child in inline.children:
if child.type == "link":
break
pre_link.append(child)
label = _SUBCAT_TRAILING_RE.sub("", render_inline_text(pre_link)) if pre_link else render_inline_text(inline.children)
nested = _find_child(list_item, "bullet_list")
if nested:
entries.extend(_parse_list_entries(nested, subcategory=label))