(text: str)
| 44 | |
| 45 | |
| 46 | def masked_fenced_lines(text: str) -> list[LineWithNumber]: |
| 47 | lines: list[LineWithNumber] = [] |
| 48 | in_fence = False |
| 49 | fence_char = "" |
| 50 | fence_length = 0 |
| 51 | |
| 52 | for line_number, line in enumerate(text.splitlines(), start=1): |
| 53 | fence_match = FENCE_OPEN_PATTERN.match(line) |
| 54 | |
| 55 | if not in_fence and fence_match: |
| 56 | fence_run = fence_match.group(1) |
| 57 | fence_char = fence_run[0] |
| 58 | fence_length = len(fence_run) |
| 59 | in_fence = True |
| 60 | lines.append((line_number, "")) |
| 61 | continue |
| 62 | |
| 63 | if in_fence: |
| 64 | closing_pattern = ( |
| 65 | rf"^[ \t]{{0,3}}{re.escape(fence_char)}{{{fence_length},}}[ \t]*$" |
| 66 | ) |
| 67 | if re.match(closing_pattern, line): |
| 68 | in_fence = False |
| 69 | fence_char = "" |
| 70 | fence_length = 0 |
| 71 | |
| 72 | lines.append((line_number, "")) |
| 73 | continue |
| 74 | |
| 75 | lines.append((line_number, line)) |
| 76 | |
| 77 | return lines |
| 78 | |
| 79 | |
| 80 | def strip_fenced_code(text: str) -> str: |
no outgoing calls
no test coverage detected