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

Method run

markdown/extensions/def_list.py:34–74  ·  view source on GitHub ↗
(self, parent, blocks)

Source from the content-addressed store, hash-verified

32 return bool(self.RE.search(block))
33
34 def run(self, parent, blocks):
35 block = blocks.pop(0)
36 m = self.RE.search(block)
37 terms = [l.strip() for l in block[:m.start()].split('\n') if l.strip()]
38 d, theRest = self.detab(block[m.end():])
39 if d:
40 d = '%s\n%s' % (m.group(2), d)
41 else:
42 d = m.group(2)
43 #import ipdb; ipdb.set_trace()
44 sibling = self.lastChild(parent)
45 if not terms and sibling.tag == 'p':
46 # The previous paragraph contains the terms
47 state = 'looselist'
48 terms = sibling.text.split('\n')
49 parent.remove(sibling)
50 # Aquire new sibling
51 sibling = self.lastChild(parent)
52 else:
53 state = 'list'
54
55 if sibling and sibling.tag == 'dl':
56 # This is another item on an existing list
57 dl = sibling
58 if len(dl) and dl[-1].tag == 'dd' and len(dl[-1]):
59 state = 'looselist'
60 else:
61 # This is a new list
62 dl = etree.SubElement(parent, 'dl')
63 # Add terms
64 for term in terms:
65 dt = etree.SubElement(dl, 'dt')
66 dt.text = term
67 # Add definition
68 self.parser.state.set(state)
69 dd = etree.SubElement(dl, 'dd')
70 self.parser.parseBlocks(dd, [d])
71 self.parser.state.reset()
72
73 if theRest:
74 blocks.insert(0, theRest)
75
76class DefListIndentProcessor(markdown.blockprocessors.ListIndentProcessor):
77 """ Process indented children of definition list items. """

Callers

nothing calls this directly

Calls 11

lastChildMethod · 0.80
removeMethod · 0.80
parseBlocksMethod · 0.80
popMethod · 0.45
splitMethod · 0.45
startMethod · 0.45
detabMethod · 0.45
endMethod · 0.45
setMethod · 0.45
resetMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected