Return content from `Categories` through `Projects`, excluding later sections.
(markdown: str)
| 317 | |
| 318 | |
| 319 | def extract_categories_body(markdown: str) -> str: |
| 320 | """Return content from `Categories` through `Projects`, excluding later sections.""" |
| 321 | lines = markdown.splitlines(keepends=True) |
| 322 | start_idx = None |
| 323 | end_idx = len(lines) |
| 324 | for i, line in enumerate(lines): |
| 325 | heading = top_level_heading_text(line) |
| 326 | if heading is None: |
| 327 | continue |
| 328 | if start_idx is None and heading.lower() == "categories": |
| 329 | start_idx = i + 1 |
| 330 | while start_idx < len(lines) and lines[start_idx].strip() == "": |
| 331 | start_idx += 1 |
| 332 | elif start_idx is not None and heading.lower() in ("resources", "contributing"): |
| 333 | end_idx = i |
| 334 | break |
| 335 | if start_idx is None: |
| 336 | return "" |
| 337 | return "".join(lines[start_idx:end_idx]).rstrip() + "\n" |
| 338 | |
| 339 | |
| 340 | def github_markdown_anchor(text: str) -> str: |
no test coverage detected