From 486fbf218505669474206d73ada2003100855418 Mon Sep 17 00:00:00 2001 From: Vinta Chen Date: Sun, 19 Apr 2026 21:59:16 +0800 Subject: [PATCH] refactor(readme_parser): replace _find_first_link with _find_child(inline, "link") The private helper duplicated _find_child with a hardcoded type filter. Remove it and call the general helper directly at both call sites. Co-Authored-By: Claude --- website/readme_parser.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/website/readme_parser.py b/website/readme_parser.py index ca650985..0aa5e2da 100644 --- a/website/readme_parser.py +++ b/website/readme_parser.py @@ -161,14 +161,6 @@ def _find_inline(node: SyntaxTreeNode) -> SyntaxTreeNode | None: return _find_child(para, "inline") -def _find_first_link(inline: SyntaxTreeNode) -> SyntaxTreeNode | None: - """Find the first link node among inline children.""" - for child in inline.children: - if child.type == "link": - return child - return None - - def _is_leading_link(inline: SyntaxTreeNode, link: SyntaxTreeNode) -> bool: """Check if the link is the first child of inline (a real entry, not a subcategory label).""" return bool(inline.children) and inline.children[0] is link @@ -212,7 +204,7 @@ def _parse_list_entries( if inline is None: continue - first_link = _find_first_link(inline) + first_link = _find_child(inline, "link") if first_link is None or not _is_leading_link(inline, first_link): # Subcategory label: take text before the first link, strip trailing separators @@ -241,7 +233,7 @@ def _parse_list_entries( continue sub_inline = _find_inline(sub_item) if sub_inline: - sub_link = _find_first_link(sub_inline) + sub_link = _find_child(sub_inline, "link") if sub_link: also_see.append(AlsoSee( name=render_inline_text(sub_link.children),