MCPcopy Index your code
hub / github.com/ronreiter/interactive-tutorials / run

Method run

markdown/blockprocessors.py:271–303  ·  view source on GitHub ↗
(self, parent, blocks)

Source from the content-addressed store, hash-verified

269 return bool(self.RE.match(block))
270
271 def run(self, parent, blocks):
272 # Check fr multiple items in one block.
273 items = self.get_items(blocks.pop(0))
274 sibling = self.lastChild(parent)
275 if sibling and sibling.tag in ['ol', 'ul']:
276 # Previous block was a list item, so set that as parent
277 lst = sibling
278 # make sure previous item is in a p.
279 if len(lst) and lst[-1].text and not len(lst[-1]):
280 p = markdown.etree.SubElement(lst[-1], 'p')
281 p.text = lst[-1].text
282 lst[-1].text = ''
283 # parse first block differently as it gets wrapped in a p.
284 li = markdown.etree.SubElement(lst, 'li')
285 self.parser.state.set('looselist')
286 firstitem = items.pop(0)
287 self.parser.parseBlocks(li, [firstitem])
288 self.parser.state.reset()
289 else:
290 # This is a new list so create parent with appropriate tag.
291 lst = markdown.etree.SubElement(parent, self.TAG)
292 self.parser.state.set('list')
293 # Loop through items in block, recursively parsing each with the
294 # appropriate parent.
295 for item in items:
296 if item.startswith(' '*markdown.TAB_LENGTH):
297 # Item is indented. Parse with last item as parent
298 self.parser.parseBlocks(lst[-1], [item])
299 else:
300 # New item. Create li and parse with it as parent
301 li = markdown.etree.SubElement(lst, 'li')
302 self.parser.parseBlocks(li, [item])
303 self.parser.state.reset()
304
305 def get_items(self, block):
306 """ Break a block into list items. """

Callers

nothing calls this directly

Calls 6

get_itemsMethod · 0.95
lastChildMethod · 0.80
parseBlocksMethod · 0.80
popMethod · 0.45
setMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected