def METHOD_NAME(match):
    heading_text = match.group(2).strip().lower()
    if heading_text in heading_counts:
        heading_counts[heading_text] += 1
    else:
        heading_counts[heading_text] = 1
    heading_id = generate_id(heading_text, heading_counts[heading_text])
    return f'<h{len(match.group(1))} id="{heading_id}">{match.group(2)}</h{len(match.group(1))}>'