将代码块内容替换为等长空格,防止代码块内的#被识别为标题
(text: str)
| 158 | |
| 159 | |
| 160 | def mask_code_blocks(text: str) -> str: |
| 161 | """ |
| 162 | 将代码块内容替换为等长空格,防止代码块内的#被识别为标题 |
| 163 | """ |
| 164 | result = list(text) |
| 165 | for match in re.finditer(r'```[^\n]*\n.*?```', text, re.DOTALL): |
| 166 | start = match.start() |
| 167 | end = match.end() |
| 168 | inner_start = text.index('\n', start) + 1 |
| 169 | closing_fence_start = text.rindex('```', start, end) |
| 170 | for i in range(inner_start, closing_fence_start): |
| 171 | if result[i] != '\n': |
| 172 | result[i] = ' ' |
| 173 | return ''.join(result) |
| 174 | |
| 175 | |
| 176 | def parse_level(text, pattern: str): |
no test coverage detected