MCPcopy Create free account
hub / github.com/internetarchive/openlibrary / run

Method run

openlibrary/core/olmarkdown.py:38–58  ·  view source on GitHub ↗
(self, lines)

Source from the content-addressed store, hash-verified

36 FENCE_RE = re.compile(r"^`{3,}[^`]*$")
37
38 def run(self, lines):
39 processed = []
40 idx = 0
41 line_count = len(lines)
42 while idx < line_count:
43 if self.FENCE_RE.match(lines[idx]):
44 fence_end = idx + 1
45 while fence_end < line_count and not self.FENCE_RE.match(lines[fence_end]):
46 fence_end += 1
47 if fence_end < line_count:
48 if processed and processed[-1].strip():
49 processed.append("")
50 for code_line in lines[idx + 1 : fence_end]:
51 processed.append(" " + code_line)
52 if fence_end + 1 < line_count and lines[fence_end + 1].strip():
53 processed.append("")
54 idx = fence_end + 1
55 continue
56 processed.append(lines[idx])
57 idx += 1
58 return processed
59
60
61FENCED_CODE_PREPROCESSOR = FencedCodePreprocessor()

Callers 1

Calls 1

lenFunction · 0.85

Tested by 1