(self, doc: Element)
| 101 | r'\:\-\.0-9\u00b7\u0300-\u036f\u203f-\u2040]+') |
| 102 | |
| 103 | def run(self, doc: Element) -> None: |
| 104 | for elem in doc.iter(): |
| 105 | if self.md.is_block_level(elem.tag): |
| 106 | # Block level: check for `attrs` on last line of text |
| 107 | RE = self.BLOCK_RE |
| 108 | if isheader(elem) or elem.tag in ['dt', 'td', 'th']: |
| 109 | # header, def-term, or table cell: check for attributes at end of element |
| 110 | RE = self.HEADER_RE |
| 111 | if len(elem) and elem.tag == 'li': |
| 112 | # special case list items. children may include a `ul` or `ol`. |
| 113 | pos = None |
| 114 | # find the `ul` or `ol` position |
| 115 | for i, child in enumerate(elem): |
| 116 | if child.tag in ['ul', 'ol']: |
| 117 | pos = i |
| 118 | break |
| 119 | if pos is None and elem[-1].tail: |
| 120 | # use tail of last child. no `ul` or `ol`. |
| 121 | m = RE.search(elem[-1].tail) |
| 122 | if m: |
| 123 | if not self.assign_attrs(elem, m.group(1), strict=True): |
| 124 | elem[-1].tail = elem[-1].tail[:m.start()] |
| 125 | elif pos is not None and pos > 0 and elem[pos-1].tail: |
| 126 | # use tail of last child before `ul` or `ol` |
| 127 | m = RE.search(elem[pos-1].tail) |
| 128 | if m: |
| 129 | if not self.assign_attrs(elem, m.group(1), strict=True): |
| 130 | elem[pos-1].tail = elem[pos-1].tail[:m.start()] |
| 131 | elif elem.text: |
| 132 | # use text. `ul` is first child. |
| 133 | m = RE.search(elem.text) |
| 134 | if m: |
| 135 | if not self.assign_attrs(elem, m.group(1), strict=True): |
| 136 | elem.text = elem.text[:m.start()] |
| 137 | elif len(elem) and elem[-1].tail: |
| 138 | # has children. Get from tail of last child |
| 139 | m = RE.search(elem[-1].tail) |
| 140 | if m: |
| 141 | if not self.assign_attrs(elem, m.group(1), strict=True): |
| 142 | elem[-1].tail = elem[-1].tail[:m.start()] |
| 143 | if isheader(elem): |
| 144 | # clean up trailing #s |
| 145 | elem[-1].tail = elem[-1].tail.rstrip('#').rstrip() |
| 146 | elif elem.text: |
| 147 | # no children. Get from text. |
| 148 | m = RE.search(elem.text) |
| 149 | if m: |
| 150 | if not self.assign_attrs(elem, m.group(1), strict=True): |
| 151 | elem.text = elem.text[:m.start()] |
| 152 | if isheader(elem): |
| 153 | # clean up trailing #s |
| 154 | elem.text = elem.text.rstrip('#').rstrip() |
| 155 | else: |
| 156 | # inline: check for `attrs` at start of tail |
| 157 | if elem.tail: |
| 158 | m = self.INLINE_RE.match(elem.tail) |
| 159 | if m: |
| 160 | remainder = self.assign_attrs(elem, m.group(1)) |
nothing calls this directly
no test coverage detected