def previous_heading(table):
    """Search upwards to find the heading associated with the given table."""
    tag = table
    while tag.name != "h1" and tag is not None:
        tag = tag.previous_sibling
    return tag