MCPcopy Create free account
hub / github.com/executablebooks/markdown-it-py / getLines

Method getLines

markdown_it/rules_block/state_block.py:214–255  ·  view source on GitHub ↗

Cut lines range from source.

(self, begin: int, end: int, indent: int, keepLastLF: bool)

Source from the content-addressed store, hash-verified

212 return pos
213
214 def getLines(self, begin: int, end: int, indent: int, keepLastLF: bool) -> str:
215 """Cut lines range from source."""
216 line = begin
217 if begin >= end:
218 return ""
219
220 queue = [""] * (end - begin)
221
222 i = 1
223 while line < end:
224 lineIndent = 0
225 lineStart = first = self.bMarks[line]
226 last = (
227 self.eMarks[line] + 1
228 if line + 1 < end or keepLastLF
229 else self.eMarks[line]
230 )
231
232 while (first < last) and (lineIndent < indent):
233 ch = self.src[first]
234 if isStrSpace(ch):
235 if ch == "\t":
236 lineIndent += 4 - (lineIndent + self.bsCount[line]) % 4
237 else:
238 lineIndent += 1
239 elif first - lineStart < self.tShift[line]:
240 lineIndent += 1
241 else:
242 break
243 first += 1
244
245 if lineIndent > indent:
246 # partially expanding tabs in code blocks, e.g '\t\tfoobar'
247 # with indent=2 becomes ' \tfoobar'
248 queue[i - 1] = (" " * (lineIndent - indent)) + self.src[first:last]
249 else:
250 queue[i - 1] = self.src[first:last]
251
252 line += 1
253 i += 1
254
255 return "".join(queue)
256
257 def is_code_block(self, line: int) -> bool:
258 """Check if line is a code block,

Callers 5

_fence_ruleFunction · 0.80
html_blockFunction · 0.80
codeFunction · 0.80
paragraphFunction · 0.80
lheadingFunction · 0.80

Calls 1

isStrSpaceFunction · 0.85

Tested by

no test coverage detected