MCPcopy Index your code
hub / github.com/Python-Markdown/markdown / BlockQuoteProcessor

Class BlockQuoteProcessor

markdown/blockprocessors.py:284–324  ·  view source on GitHub ↗

Process blockquotes.

Source from the content-addressed store, hash-verified

282
283
284class BlockQuoteProcessor(BlockProcessor):
285 """ Process blockquotes. """
286
287 RE = re.compile(r'(^|\n)[ ]{0,3}>[ ]?(.*)')
288
289 def test(self, parent: etree.Element, block: str) -> bool:
290 return bool(self.RE.search(block)) and not util.nearing_recursion_limit()
291
292 def run(self, parent: etree.Element, blocks: list[str]) -> None:
293 block = blocks.pop(0)
294 m = self.RE.search(block)
295 if m:
296 before = block[:m.start()] # Lines before blockquote
297 # Pass lines before blockquote in recursively for parsing first.
298 self.parser.parseBlocks(parent, [before])
299 # Remove `> ` from beginning of each line.
300 block = '\n'.join(
301 [self.clean(line) for line in block[m.start():].split('\n')]
302 )
303 sibling = self.lastChild(parent)
304 if sibling is not None and sibling.tag == "blockquote":
305 # Previous block was a blockquote so set that as this blocks parent
306 quote = sibling
307 else:
308 # This is a new blockquote. Create a new parent element.
309 quote = etree.SubElement(parent, 'blockquote')
310 # Recursively parse block with blockquote as parent.
311 # change parser state so blockquotes embedded in lists use `p` tags
312 self.parser.state.set('blockquote')
313 self.parser.parseChunk(quote, block)
314 self.parser.state.reset()
315
316 def clean(self, line: str) -> str:
317 """ Remove `>` from beginning of a line. """
318 m = self.RE.match(line)
319 if line.strip() == ">":
320 return ""
321 elif m:
322 return m.group(2)
323 else:
324 return line
325
326
327class OListProcessor(BlockProcessor):

Callers 1

build_block_parserFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…