import re


def remove_hypertarget(body:str):
    """
    Remove something like:
    \hypertarget{analysis}{%
    \section{Analysis}\label{analysis}}

    to:
    \section{Analysis}\label{analysis}

    """

    #results = re.findall(r'\\section{[^}]+}\\label{[^}]+}', body)
    #for result in results:
    #    repl = re.sub(r'\\section', r'\\\\section', result)
    #    repl = re.sub(r'\\label', r'\\\\label', repl)
    #            
    #    body = re.sub(r'\\hypertarget{[^}]+}{%\n*' + repl + r'\}', repl=repl, string=body)
    
    #for result in re.finditer(r'\\hypertarget{[^}]+}{%\n*([^}]+})}', body):
    #    body = body.replace(result.group(0), result.group(1))

    for result in re.finditer(r'\\hypertarget{[^}]+}{%\n*([^}]+})}', body):
        body = body.replace(result.group(0), result.group(1))
    
    for result in re.finditer(r'\\hypertarget{[^}]+}{%\n*([^}]+}\\label\{[^}]+})}', body):
        body = body.replace(result.group(0), result.group(1))

    return body