MCPcopy Index your code
hub / github.com/1Panel-dev/MaxKB / mask_code_blocks

Function mask_code_blocks

apps/common/utils/split_model.py:160–173  ·  view source on GitHub ↗

将代码块内容替换为等长空格,防止代码块内的#被识别为标题

(text: str)

Source from the content-addressed store, hash-verified

158
159
160def 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
176def parse_level(text, pattern: str):

Callers 1

parse_levelFunction · 0.85

Calls 2

endMethod · 0.80
startMethod · 0.45

Tested by

no test coverage detected