def remove_empty_sections(lines):
    """
    Mainly relevant for Wikipedia articles, this removes sections without any actual textual content.
    Notably, we leave in transfer from sections to subsections, subsections to subsubsections, etc.
    """
    new_lines = []

    curr_section_depth = "="
    curr_section_is_empty = True
    curr_section_lines = []

    for line in lines:
        # Encountering start of new section
        if line.startswith("="):
            # Current new section is a subsection, so we don't care if it is empty
            if len(curr_section_depth) < len(line.split(" ")[0]) or not curr_section_is_empty:
                new_lines.extend(curr_section_lines)
            # if it is a section of same depth, and there had not been any content, remove
            elif len(curr_section_depth) >= len(line.split(" ")[0]) and curr_section_is_empty:
                # don't add it to content, and reset for next block
                pass
            else:
                raise ValueError(f"Found uncovered edge case: "
                                 f"{curr_section_is_empty}, {curr_section_depth}, {curr_section_lines}")

            curr_section_is_empty = True
            curr_section_depth = line.split(" ")[0]  # only take the "===" part
            curr_section_lines = []

        curr_section_lines.append(line)
        # Mark relevant lines as textual content
        if line != "" and not line.startswith("="):
            curr_section_is_empty = False

    # Add last section
    if not curr_section_is_empty:
        new_lines.extend(curr_section_lines)

    return new_lines