MCPcopy
hub / github.com/Python-Markdown/markdown / run

Method run

markdown/blockprocessors.py:181–215  ·  view source on GitHub ↗
(self, parent: etree.Element, blocks: list[str])

Source from the content-addressed store, hash-verified

179 (parent[-1].tag in self.LIST_TYPES)))
180
181 def run(self, parent: etree.Element, blocks: list[str]) -> None:
182 block = blocks.pop(0)
183 level, sibling = self.get_level(parent, block)
184 block = self.looseDetab(block, level)
185
186 self.parser.state.set('detabbed')
187 if parent.tag in self.ITEM_TYPES:
188 # It's possible that this parent has a `ul` or `ol` child list
189 # with a member. If that is the case, then that should be the
190 # parent. This is intended to catch the edge case of an indented
191 # list whose first member was parsed previous to this point
192 # see `OListProcessor`
193 if len(parent) and parent[-1].tag in self.LIST_TYPES:
194 self.parser.parseBlocks(parent[-1], [block])
195 else:
196 # The parent is already a `li`. Just parse the child block.
197 self.parser.parseBlocks(parent, [block])
198 elif sibling.tag in self.ITEM_TYPES:
199 # The sibling is a `li`. Use it as parent.
200 self.parser.parseBlocks(sibling, [block])
201 elif len(sibling) and sibling[-1].tag in self.ITEM_TYPES:
202 # The parent is a list (`ol` or `ul`) which has children.
203 # Assume the last child `li` is the parent of this block.
204 if sibling[-1].text:
205 # If the parent `li` has text, that text needs to be moved to a `p`
206 # The `p` must be 'inserted' at beginning of list in the event
207 # that other children already exist i.e.; a nested sub-list.
208 p = etree.Element('p')
209 p.text = sibling[-1].text
210 sibling[-1].text = ''
211 sibling[-1].insert(0, p)
212 self.parser.parseChunk(sibling[-1], block)
213 else:
214 self.create_item(sibling, block)
215 self.parser.state.reset()
216
217 def create_item(self, parent: etree.Element, block: str) -> None:
218 """ Create a new `li` and parse the block with it as the parent. """

Callers

nothing calls this directly

Calls 7

get_levelMethod · 0.95
create_itemMethod · 0.95
looseDetabMethod · 0.80
setMethod · 0.80
parseBlocksMethod · 0.80
parseChunkMethod · 0.80
resetMethod · 0.45

Tested by

no test coverage detected