def METHOD_NAME(self, doc):
    for elem in doc.iter():
        if self.md.is_block_level(elem.tag):
            # Block level: check for `attrs` on last line of text
            RE = self.BLOCK_RE
            if isheader(elem) or elem.tag in ['dt', 'td', 'th']:
                # header, def-term, or table cell: check for attributes at end of element
                RE = self.HEADER_RE
            if len(elem) and elem.tag == 'li':
                # special case list items. children may include a `ul` or `ol`.
                pos = None
                # find the `ul` or `ol` position
                for i, child in enumerate(elem):
                    if child.tag in ['ul', 'ol']:
                        pos = i
                        break
                if pos is None and elem[-1].tail:
                    # use tail of last child. no `ul` or `ol`.
                    m = RE.search(elem[-1].tail)
                    if m:
                        self.assign_attrs(elem, m.group(1))
                        elem[-1].tail = elem[-1].tail[:m.start()]
                elif pos is not None and pos > 0 and elem[pos-1].tail:
                    # use tail of last child before `ul` or `ol`
                    m = RE.search(elem[pos-1].tail)
                    if m:
                        self.assign_attrs(elem, m.group(1))
                        elem[pos-1].tail = elem[pos-1].tail[:m.start()]
                elif elem.text:
                    # use text. `ul` is first child.
                    m = RE.search(elem.text)
                    if m:
                        self.assign_attrs(elem, m.group(1))
                        elem.text = elem.text[:m.start()]
            elif len(elem) and elem[-1].tail:
                # has children. Get from tail of last child
                m = RE.search(elem[-1].tail)
                if m:
                    self.assign_attrs(elem, m.group(1))
                    elem[-1].tail = elem[-1].tail[:m.start()]
                    if isheader(elem):
                        # clean up trailing #s
                        elem[-1].tail = elem[-1].tail.rstrip('#').rstrip()
            elif elem.text:
                # no children. Get from text.
                m = RE.search(elem.text)
                if m:
                    self.assign_attrs(elem, m.group(1))
                    elem.text = elem.text[:m.start()]
                    if isheader(elem):
                        # clean up trailing #s
                        elem.text = elem.text.rstrip('#').rstrip()
        else:
            # inline: check for `attrs` at start of tail
            if elem.tail:
                m = self.INLINE_RE.match(elem.tail)
                if m:
                    self.assign_attrs(elem, m.group(1))
                    elem.tail = elem.tail[m.end():]