import re


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

    #  Remove '<!-- include:' lines at the start of included snippet
    content = re.sub(
        r"\n <!-- include:.*-->\n",
        '', content)

    # simplify the hyperlink, remove superscript tags
    content = re.sub(
        # r"<sup><a href='([^']+)' title='File snippet `[^`]+` was extracted from'>snippet source</a> ",
        r"<sup><a href='([^']+)' title='File snippet was copied from'>snippet source</a></sup>",
        r"(See [snippet source](\1))", content)

    #  Remove '<!-- end include:' lines at the end of included snippet
    content = re.sub(
        r"\n <!-- end include:.*-->",
        '', content)

    return content