MCPcopy Create free account
hub / github.com/OWASP/APTS / masked_fenced_lines

Function masked_fenced_lines

scripts/_ci_utils.py:46–77  ·  view source on GitHub ↗
(text: str)

Source from the content-addressed store, hash-verified

44
45
46def 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
80def strip_fenced_code(text: str) -> str:

Callers 2

validate_markdown_tablesFunction · 0.90
strip_fenced_codeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected