def METHOD_NAME(r):
    hdrtags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']
    try:
        i = hdrtags.index(r.name)
        return r.find_previous(hdrtags[:i-1])
    except Exception:
        return r.find_previous(hdrtags)