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

Method run

markdown/extensions/headerid.py:95–122  ·  view source on GitHub ↗
(self, parent, blocks)

Source from the content-addressed store, hash-verified

93 return bool(self.RE.search(block))
94
95 def run(self, parent, blocks):
96 block = blocks.pop(0)
97 m = self.RE.search(block)
98 if m:
99 before = block[:m.start()] # All lines before header
100 after = block[m.end():] # All lines after header
101 if before:
102 # As the header was not the first line of the block and the
103 # lines before the header must be parsed first,
104 # recursively parse this lines as a block.
105 self.parser.parseBlocks(parent, [before])
106 # Create header using named groups from RE
107 start_level, force_id = self._get_meta()
108 level = len(m.group('level')) + start_level
109 if level > 6:
110 level = 6
111 h = markdown.etree.SubElement(parent, 'h%d' % level)
112 h.text = m.group('header').strip()
113 if m.group('id'):
114 h.set('id', self._unique_id(m.group('id')))
115 elif force_id:
116 h.set('id', self._create_id(m.group('header').strip()))
117 if after:
118 # Insert remaining lines as first block for future parsing.
119 blocks.insert(0, after)
120 else:
121 # This should never happen, but just in case...
122 message(CRITICAL, "We've got a problem header!")
123
124 def _get_meta(self):
125 """ Return meta data suported by this ext as a tuple """

Callers

nothing calls this directly

Calls 10

_get_metaMethod · 0.95
_unique_idMethod · 0.95
_create_idMethod · 0.95
messageFunction · 0.85
parseBlocksMethod · 0.80
popMethod · 0.45
startMethod · 0.45
endMethod · 0.45
setMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected