def bootstrap_collapse(visible_text, collapsed_text,
                       id, button_text='', icon='pencil'):
    """Generate HTML Bootstrap code for a collapsing/unfolding text."""
    # icon types:
    # https://www.w3schools.com/bootstrap/bootstrap_ref_comp_glyphs.asp
    text = ('\n'
            '<p>\n'
            '<a class="glyphicon glyphicon-%(icon)s showdetails" data-toggle="collapse"\n'
            ' data-target="#%(id)s" style="font-size: 80%%;">%(button_text)s</a>\n'
            '<a href="#%(id)s" data-toggle="collapse">\n'
            '%(visible_text)s\n'
            '</a>\n'
            '<div class="collapse-group">\n'
            '<p><div class="collapse" id="%(id)s">\n'
            '%(collapsed_text)s\n'
            '</div></p>\n'
            '</div>\n'
            '</p>\n') % vars()
    return text