(self, parent: etree.Element, blocks: list[str])
| 128 | return self.parse_content(parent, block)[0] is not None |
| 129 | |
| 130 | def run(self, parent: etree.Element, blocks: list[str]) -> None: |
| 131 | block = blocks.pop(0) |
| 132 | m = self.RE.search(block) |
| 133 | |
| 134 | if m: |
| 135 | if m.start() > 0: |
| 136 | self.parser.parseBlocks(parent, [block[:m.start()]]) |
| 137 | block = block[m.end():] # removes the first line |
| 138 | block, theRest = self.detab(block) |
| 139 | else: |
| 140 | sibling, block, theRest = self.parse_content(parent, block) |
| 141 | |
| 142 | if m: |
| 143 | klass, title = self.get_class_and_title(m) |
| 144 | div = etree.SubElement(parent, 'div') |
| 145 | div.set('class', '{} {}'.format(self.CLASSNAME, klass)) |
| 146 | if title: |
| 147 | p = etree.SubElement(div, 'p') |
| 148 | p.text = title |
| 149 | p.set('class', self.CLASSNAME_TITLE) |
| 150 | else: |
| 151 | # Sibling is a list item, but we need to wrap it's content should be wrapped in <p> |
| 152 | if sibling.tag in ('li', 'dd') and sibling.text: |
| 153 | text = sibling.text |
| 154 | sibling.text = '' |
| 155 | p = etree.SubElement(sibling, 'p') |
| 156 | p.text = text |
| 157 | |
| 158 | div = sibling |
| 159 | |
| 160 | self.parser.parseChunk(div, block) |
| 161 | |
| 162 | if theRest: |
| 163 | # This block contained unindented line(s) after the first indented |
| 164 | # line. Insert these lines as the first block of the master blocks |
| 165 | # list for future processing. |
| 166 | blocks.insert(0, theRest) |
| 167 | |
| 168 | def get_class_and_title(self, match: re.Match[str]) -> tuple[str, str | None]: |
| 169 | klass, title = match.group(1).lower(), match.group(2) |
nothing calls this directly
no test coverage detected