Find and remove all abbreviation references from the text. Each reference is added to the abbreviation collection.
(self, parent: etree.Element, blocks: list[str])
| 151 | return True |
| 152 | |
| 153 | def run(self, parent: etree.Element, blocks: list[str]) -> bool: |
| 154 | """ |
| 155 | Find and remove all abbreviation references from the text. |
| 156 | Each reference is added to the abbreviation collection. |
| 157 | |
| 158 | """ |
| 159 | block = blocks.pop(0) |
| 160 | m = self.RE.search(block) |
| 161 | if m: |
| 162 | abbr = m.group('abbr').strip() |
| 163 | title = m.group('title').strip() |
| 164 | if title and abbr: |
| 165 | if title == "''" or title == '""': |
| 166 | self.abbrs.pop(abbr, None) |
| 167 | else: |
| 168 | self.abbrs[abbr] = title |
| 169 | if block[m.end():].strip(): |
| 170 | # Add any content after match back to blocks as separate block |
| 171 | blocks.insert(0, block[m.end():].lstrip('\n')) |
| 172 | if block[:m.start()].strip(): |
| 173 | # Add any content before match back to blocks as separate block |
| 174 | blocks.insert(0, block[:m.start()].rstrip('\n')) |
| 175 | return True |
| 176 | # No match. Restore block. |
| 177 | blocks.insert(0, block) |
| 178 | return False |
| 179 | |
| 180 | |
| 181 | AbbrPreprocessor = deprecated("This class has been renamed to `AbbrBlockprocessor`.")(AbbrBlockprocessor) |