def bib_escape(text):
    """Replace special characters to render bibentries in HTML."""
    escape_entities = [
        ('"', '&quot;'),
        ('\\', '&#92;'),
        ('{', '&#123;'),
        ('}', '&#125;'),
        ('~', '&#126;')
    ]
    for search, repl in escape_entities:
        text = text.replace(search, repl)
    return text