MCPcopy Create free account
hub / github.com/ronreiter/interactive-tutorials / get_level

Method get_level

markdown/blockprocessors.py:158–183  ·  view source on GitHub ↗

Get level of indent based on list level.

(self, parent, block)

Source from the content-addressed store, hash-verified

156 self.parser.parseBlocks(li, [block])
157
158 def get_level(self, parent, block):
159 """ Get level of indent based on list level. """
160 # Get indent level
161 m = self.INDENT_RE.match(block)
162 if m:
163 indent_level = len(m.group(1))/markdown.TAB_LENGTH
164 else:
165 indent_level = 0
166 if self.parser.state.isstate('list'):
167 # We're in a tightlist - so we already are at correct parent.
168 level = 1
169 else:
170 # We're in a looselist - so we need to find parent.
171 level = 0
172 # Step through children of tree to find matching indent level.
173 while indent_level > level:
174 child = self.lastChild(parent)
175 if child and (child.tag in self.LIST_TYPES or child.tag in self.ITEM_TYPES):
176 if child.tag in self.LIST_TYPES:
177 level += 1
178 parent = child
179 else:
180 # No more child levels. If we're short of indent_level,
181 # we have a code block. So we stop here.
182 break
183 return level, parent
184
185
186class CodeBlockProcessor(BlockProcessor):

Callers 1

runMethod · 0.95

Calls 3

isstateMethod · 0.80
lastChildMethod · 0.80
matchMethod · 0.45

Tested by

no test coverage detected