| 74 | self.children = [] |
| 75 | |
| 76 | def append(self, element): |
| 77 | if isinstance(element, str): |
| 78 | element = normalize_whitespace(element) |
| 79 | if self.children and isinstance(self.children[-1], str): |
| 80 | self.children[-1] += element |
| 81 | self.children[-1] = normalize_whitespace(self.children[-1]) |
| 82 | return |
| 83 | elif self.children: |
| 84 | # removing last children if it is only whitespace |
| 85 | # this can result in incorrect dom representations since |
| 86 | # whitespace between inline tags like <span> is significant |
| 87 | if isinstance(self.children[-1], str) and self.children[-1].isspace(): |
| 88 | self.children.pop() |
| 89 | if element: |
| 90 | self.children.append(element) |
| 91 | |
| 92 | def finalize(self): |
| 93 | def rstrip_last_element(children): |