|
33 | 33 | ) |
34 | 34 |
|
35 | 35 | _RE_TYPED_ARGSTART = re.compile(r"^([\w\[\]_]{1,}?)[ ]*?\((.*?)\):[ ]+(.{2,})", re.IGNORECASE) |
36 | | -_RE_ARGSTART = re.compile(r"^(.+):[ ]+(.{2,})$", re.IGNORECASE) |
| 36 | +# Restrict to valid Python identifier-like patterns to avoid matching URLs |
| 37 | +_RE_ARGSTART = re.compile(r"^([\w\[\]_]+):[ ]+(.{2,})$", re.IGNORECASE) |
37 | 38 |
|
38 | 39 | _RE_CODE_TEXT = re.compile(r"^```[\w\-\.]*[ ]*$", re.IGNORECASE) |
39 | 40 |
|
@@ -583,11 +584,41 @@ def _lines_isvalid(lines: list, start_index: int, blockindent: int, |
583 | 584 | argindent = indent |
584 | 585 | elif arg_list and not literal_block and _RE_ARGSTART.match(line): |
585 | 586 | # start of an exception-type block |
586 | | - out.append( |
587 | | - "- " |
588 | | - + _RE_ARGSTART.sub(r"<b>`\1`</b>: \2", line) |
| 587 | + # Check if this looks like a URL being incorrectly parsed |
| 588 | + match = _RE_ARGSTART.match(line) |
| 589 | + # Check if the part before the colon contains URL indicators or |
| 590 | + # is likely descriptive text rather than an argument name |
| 591 | + before_colon = match.group(1) if match else "" |
| 592 | + after_colon = match.group(2) if match else "" |
| 593 | + |
| 594 | + # Heuristics to detect non-argument lines: |
| 595 | + # 1. The text before colon contains "http" (part of a URL) |
| 596 | + # 2. The line contains "://" (URL protocol) |
| 597 | + # 3. The text before colon is too long to be an argument name (>40 chars) |
| 598 | + # 4. The text before colon contains common English words that aren't argument names |
| 599 | + is_not_argument = ( |
| 600 | + "http" in before_colon.lower() or |
| 601 | + "://" in line or |
| 602 | + len(before_colon) > 40 or |
| 603 | + # Check for common descriptive phrases (without trailing space) |
| 604 | + any(word in before_colon.lower() for word in ["see", "to find", "refer", "documentation", "available"]) |
589 | 605 | ) |
590 | | - argindent = indent |
| 606 | + |
| 607 | + if match and is_not_argument: |
| 608 | + # This is likely descriptive text with a colon, not an argument |
| 609 | + # Treat it as regular text continuation |
| 610 | + if argindent > 0: |
| 611 | + padding = max(indent - argindent + offset, 0) |
| 612 | + out.append(" " * padding + line.replace("\n", "\n" + " " * padding)) |
| 613 | + else: |
| 614 | + out.append(line) |
| 615 | + else: |
| 616 | + # This is a real argument |
| 617 | + out.append( |
| 618 | + "- " |
| 619 | + + _RE_ARGSTART.sub(r"<b>`\1`</b>: \2", line) |
| 620 | + ) |
| 621 | + argindent = indent |
591 | 622 | elif indent > argindent: |
592 | 623 | # attach docs text of argument |
593 | 624 | # * (blockindent + 2) |
|
0 commit comments