MCPcopy Index your code
hub / github.com/vinta/awesome-python / _parse_list_entries

Function _parse_list_entries

website/readme_parser.py:186–256  ·  view source on GitHub ↗

Extract entries from a bullet_list AST node. Handles three patterns: - Text-only list_item -> subcategory label -> recurse into nested list - Link list_item with nested link-only items -> entry with also_see - Link list_item without nesting -> simple entry

(
    bullet_list: SyntaxTreeNode,
    *,
    subcategory: str = "",
)

Source from the content-addressed store, hash-verified

184
185
186def _parse_list_entries(
187 bullet_list: SyntaxTreeNode,
188 *,
189 subcategory: str = "",
190) -> list[ParsedEntry]:
191 """Extract entries from a bullet_list AST node.
192
193 Handles three patterns:
194 - Text-only list_item -> subcategory label -> recurse into nested list
195 - Link list_item with nested link-only items -> entry with also_see
196 - Link list_item without nesting -> simple entry
197 """
198 entries: list[ParsedEntry] = []
199
200 for list_item in bullet_list.children:
201 if list_item.type != "list_item":
202 continue
203
204 inline = _find_inline(list_item)
205 if inline is None:
206 continue
207
208 first_link = _find_child(inline, "link")
209
210 if first_link is None or inline.children[0] is not first_link:
211 # Subcategory label: take text before the first link, strip trailing separators
212 pre_link = []
213 for child in inline.children:
214 if child.type == "link":
215 break
216 pre_link.append(child)
217 label = _SUBCAT_TRAILING_RE.sub("", render_inline_text(pre_link)) if pre_link else render_inline_text(inline.children)
218 nested = _find_child(list_item, "bullet_list")
219 if nested:
220 entries.extend(_parse_list_entries(nested, subcategory=label))
221 continue
222
223 # Entry with a link
224 name = render_inline_text(first_link.children)
225 url = _href(first_link)
226 desc_html = _extract_description_html(inline, first_link)
227
228 # Collect also_see from nested bullet_list
229 also_see: list[AlsoSee] = []
230 nested = _find_child(list_item, "bullet_list")
231 if nested:
232 for sub_item in nested.children:
233 if sub_item.type != "list_item":
234 continue
235 sub_inline = _find_inline(sub_item)
236 if sub_inline:
237 sub_link = _find_child(sub_inline, "link")
238 if sub_link:
239 also_see.append(
240 AlsoSee(
241 name=render_inline_text(sub_link.children),
242 url=_href(sub_link),
243 )

Callers 1

_parse_section_entriesFunction · 0.85

Calls 7

_find_inlineFunction · 0.85
_find_childFunction · 0.85
render_inline_textFunction · 0.85
_hrefFunction · 0.85
AlsoSeeClass · 0.85
ParsedEntryClass · 0.85

Tested by

no test coverage detected