Parse the `Sponsors` section of README.md into a list of sponsors. Expects bullets in the form `**[name](url)**: description`. Returns [] if no Sponsors section exists.
(text: str)
| 390 | |
| 391 | |
| 392 | def parse_sponsors(text: str) -> list[ParsedSponsor]: |
| 393 | """Parse the `Sponsors` section of README.md into a list of sponsors. |
| 394 | |
| 395 | Expects bullets in the form `**[name](url)**: description`. |
| 396 | Returns [] if no Sponsors section exists. |
| 397 | """ |
| 398 | md = MarkdownIt("commonmark") |
| 399 | tokens = md.parse(text) |
| 400 | root = SyntaxTreeNode(tokens) |
| 401 | children = root.children |
| 402 | |
| 403 | start_idx = None |
| 404 | end_idx = len(children) |
| 405 | start_level = None |
| 406 | for i, node in enumerate(children): |
| 407 | level = _heading_level(node) |
| 408 | if level is None: |
| 409 | continue |
| 410 | title = _heading_text(node).strip().lower() |
| 411 | if start_idx is None and title == "sponsors": |
| 412 | start_idx = i + 1 |
| 413 | start_level = level |
| 414 | elif start_idx is not None and start_level is not None and level <= start_level: |
| 415 | end_idx = i |
| 416 | break |
| 417 | if start_idx is None: |
| 418 | return [] |
| 419 | |
| 420 | sponsors: list[ParsedSponsor] = [] |
| 421 | for node in children[start_idx:end_idx]: |
| 422 | if node.type != "bullet_list": |
| 423 | continue |
| 424 | for list_item in node.children: |
| 425 | if list_item.type != "list_item": |
| 426 | continue |
| 427 | inline = _find_inline(list_item) |
| 428 | if inline is None: |
| 429 | continue |
| 430 | sponsor = _parse_sponsor_item(inline) |
| 431 | if sponsor: |
| 432 | sponsors.append(sponsor) |
| 433 | return sponsors |
| 434 | |
| 435 | |
| 436 | def parse_readme(text: str) -> list[ParsedGroup]: |
no test coverage detected