def add_attrib(attrib, ptext):
    """
    Insert an attribute into some html text

    Input:
        attrib -- text of the attribute to be added.
        ptext -- snippet of html code in which to insert the attribute.

    Returns the text with the attribute added.
    """
    bloc = ptext.find('>')
    if bloc <= 0:
        return ptext
    fpart = ptext[0:bloc]
    spart = ptext[bloc:]
    return fpart + ' ' + attrib + spart