MCPcopy Create free account
hub / github.com/Python-Markdown/markdown / run

Method run

markdown/blockprocessors.py:296–318  ·  view source on GitHub ↗
(self, parent: etree.Element, blocks: list[str])

Source from the content-addressed store, hash-verified

294 return bool(self.RE.search(block)) and not util.nearing_recursion_limit()
295
296 def run(self, parent: etree.Element, blocks: list[str]) -> None:
297 block = blocks.pop(0)
298 m = self.RE.search(block)
299 if m:
300 before = block[:m.start()] # Lines before blockquote
301 # Pass lines before blockquote in recursively for parsing first.
302 self.parser.parseBlocks(parent, [before])
303 # Remove `> ` from beginning of each line.
304 block = '\n'.join(
305 [self.clean(line) for line in block[m.start():].split('\n')]
306 )
307 sibling = self.lastChild(parent)
308 if sibling is not None and sibling.tag == "blockquote":
309 # Previous block was a blockquote so set that as this blocks parent
310 quote = sibling
311 else:
312 # This is a new blockquote. Create a new parent element.
313 quote = etree.SubElement(parent, 'blockquote')
314 # Recursively parse block with blockquote as parent.
315 # change parser state so blockquotes embedded in lists use `p` tags
316 self.parser.state.set('blockquote')
317 self.parser.parseChunk(quote, block)
318 self.parser.state.reset()
319
320 def clean(self, line: str) -> str:
321 """ Remove `>` from beginning of a line. """

Callers

nothing calls this directly

Calls 7

cleanMethod · 0.95
searchMethod · 0.80
parseBlocksMethod · 0.80
lastChildMethod · 0.80
setMethod · 0.80
parseChunkMethod · 0.80
resetMethod · 0.45

Tested by

no test coverage detected