Process children of list items. Example * a list item process this part or this part
| 151 | |
| 152 | |
| 153 | class ListIndentProcessor(BlockProcessor): |
| 154 | """ Process children of list items. |
| 155 | |
| 156 | Example |
| 157 | |
| 158 | * a list item |
| 159 | process this part |
| 160 | |
| 161 | or this part |
| 162 | |
| 163 | """ |
| 164 | |
| 165 | ITEM_TYPES = ['li'] |
| 166 | """ List of tags used for list items. """ |
| 167 | LIST_TYPES = ['ul', 'ol'] |
| 168 | """ Types of lists this processor can operate on. """ |
| 169 | |
| 170 | def __init__(self, *args): |
| 171 | super().__init__(*args) |
| 172 | self.INDENT_RE = re.compile(r'^(([ ]{%s})+)' % self.tab_length) |
| 173 | |
| 174 | def test(self, parent: etree.Element, block: str) -> bool: |
| 175 | return block.startswith(' '*self.tab_length) and \ |
| 176 | not self.parser.state.isstate('detabbed') and \ |
| 177 | (parent.tag in self.ITEM_TYPES or |
| 178 | (len(parent) and parent[-1] is not None and |
| 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 = '' |
no outgoing calls
no test coverage detected
searching dependent graphs…