Build description text from line range [start, end] (1-indexed, inclusive). The first line is treated as the flag line. Remaining lines form the description body. Blockquote prefixes ("> ") are stripped from all lines.
(
original_lines: dict[int, str], start: int, end: int
)
| 93 | |
| 94 | |
| 95 | def extract_text_from_lines( |
| 96 | original_lines: dict[int, str], start: int, end: int |
| 97 | ) -> str: |
| 98 | """Build description text from line range [start, end] (1-indexed, inclusive). |
| 99 | |
| 100 | The first line is treated as the flag line. Remaining lines form the |
| 101 | description body. Blockquote prefixes ("> ") are stripped from all lines. |
| 102 | """ |
| 103 | if start < 1 or end < start: |
| 104 | return "" |
| 105 | selected: list[str] = [] |
| 106 | for i in range(start, end + 1): |
| 107 | line = original_lines.get(i, "") |
| 108 | if line.startswith("> "): |
| 109 | line = line[2:] |
| 110 | selected.append(line) |
| 111 | |
| 112 | if not selected: |
| 113 | return "" |
| 114 | |
| 115 | flag_line = selected[0] |
| 116 | body_lines = selected[1:] |
| 117 | |
| 118 | while body_lines and not body_lines[0].strip(): |
| 119 | body_lines.pop(0) |
| 120 | while body_lines and not body_lines[-1].strip(): |
| 121 | body_lines.pop() |
| 122 | |
| 123 | if body_lines: |
| 124 | return flag_line + "\n\n" + "\n".join(body_lines) |
| 125 | return flag_line |
| 126 | |
| 127 | |
| 128 | def normalize_option_fields(raw: dict) -> dict: |