MCPcopy Create free account
hub / github.com/Python-Markdown/markdown / run

Method run

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

Source from the content-addressed store, hash-verified

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