def add_links(doc, rel_links_text, link_section_name="##### links"):
    """
    Add links to a doc. There is an assumption here
    that the link section will be placed at the
    end of the file.

    doc: str, contains a single document.
    rel_links_text: pre-formatted str with the links.
    """

    link_index = doc.find(link_section_name)
    if link_index >= 0:
        # delete old links section
        doc = doc.replace(doc[link_index:], "")

    # add new links
    return doc + f"\n{link_section_name}:\n" + rel_links_text