From e1a88410d3d89e70e5b75c890a1fb8315660b400 Mon Sep 17 00:00:00 2001 From: Vinta Chen Date: Mon, 23 Mar 2026 01:19:05 +0800 Subject: [PATCH] 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 --- website/readme_parser.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/website/readme_parser.py b/website/readme_parser.py index 1068a33..91b0faf 100644 --- a/website/readme_parser.py +++ b/website/readme_parser.py @@ -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))