from bs4 import BeautifulSoup


def markup(predicted, decfxn, data, scrapedhtml):
    """
    Mark up HTML for sentences predicted to be highlighted by the model.

    Args:
    - predicted (array): predicted category for each sentence
    - decfxn (array): confidence score for each sentence
    - data (df): dataframe with feature values for each sentence
    - scrapedhtml (str): full HTML from webpage

    Returns:
    - htmlmarkup (BeautifulSoup): Beautiful Soup object for marked-up HTML
    """

    soup = BeautifulSoup(scrapedhtml, 'lxml')

    predict = list(predicted)
    tmpsoup = str(soup)
    decision = list(decfxn)
    n = 0

    for f in data['sentences']:
        if predict[n] == 1:
            if decision[n] >= 0.1:
                # Mark up HTML to highlight sentence
                newf = '<span style="background-color: #ffff00">'+f+'</span>'
                tmpsoup = tmpsoup.replace(f, newf)

        n += 1

    outsoup = BeautifulSoup(tmpsoup, 'lxml')
    htmlmarkup = outsoup.prettify()

    return htmlmarkup