import re


def fixup_generated_snippets(content):
    """
    Adjust the expanded code snippets that were generated
    by mdsnippets, to improve rendering by Sphinx
    """

    # Remove lines like: <!-- snippet: verify_exception_message_example -->
    content = re.sub(
        r"<!-- snippet: .* -->\n",
        r"", content)

    # Remove lines like: <a id='snippet-verify_exception_message_example'/></a>
    content = re.sub(
        r"<a id='snippet-.*'/></a>\n",
        r"", content)

    # Remove 'snippet source' links from all code snippets
    content = re.sub(
        r"<sup><a href='([^']+)' title='Snippet source file'>snippet source</a> ",
        r"(See [snippet source](\1))", content)

    # Remove 'anchor' links from all code snippets
    content = re.sub(
        r"\| <a href='#snippet-[^']+' title='Start of snippet'>anchor</a></sup>",
        '', content)

    content = content.replace('<!-- endsnippet -->\n', '')

    return content