'Massage comments to somewhat consistent format.
Convert random comment text to normalized, xml-legal block of <p>s
\'plain text\' returns as
<p>plain text</p>
\'plain text with <i>minimal</i> <b>markup</b>\' returns as
<p>plain text with <i>minimal</i> <b>markup</b></p>
\'<p>pre-formatted text</p> returns untouched
\'A line of text
Followed by a line of text\' returns as
<p>A line of text</p>
<p>Followed by a line of text</p>
\'A line of text.
A second line of text.A third line of text\' returns as
<p>A line of text.<br />A second line of text.<br />A third line of text.</p>
\'...end of a paragraph.Somehow the break was lost...\' returns as
<p>...end of a paragraph.</p>
<p>Somehow the break was lost...</p>
Deprecated HTML returns as HTML via BeautifulSoup()
Args:
comments (str): comments from metadata, possibly HTML
Return:
result (BeautifulSoup): massaged comments in HTML form'

def massage_comments(self, comments):

    for lost_cr in re.finditer('([a-z])([\\.\\?!])([A-Z])', comments):
        comments = comments.replace(lost_cr.group(), ('%s%s\n\n%s' % (lost_cr.group(1), lost_cr.group(2), lost_cr.group(3))))
    if (not isinstance(comments, unicode)):
        comments = comments.decode('utf-8', 'replace')
    soup = BeautifulSoup(comments)
    elems = soup.findAll('div')
    for elem in elems:
        elem.extract()
    comments = soup.renderContents(None)
    if re.search('\n\n', comments):
        soup = BeautifulSoup()
        split_ps = comments.split(u'\n\n')
        tsc = 0
        for p in split_ps:
            pTag = Tag(soup, 'p')
            pTag.insert(0, p)
            soup.insert(tsc, pTag)
            tsc += 1
        comments = soup.renderContents(None)
    comments = re.sub('[\r\n]', '<br    />', comments)
    comments = re.sub('--', '&mdash;', comments)
    soup = BeautifulSoup(comments)
    result = BeautifulSoup()
    rtc = 0
    open_pTag = False
    all_tokens = list(soup.contents)
    for token in all_tokens:
        if (type(token) is NavigableString):
            if (not open_pTag):
                pTag = Tag(result, 'p')
                open_pTag = True
                ptc = 0
            pTag.insert(ptc, prepare_string_for_xml(token))
            ptc += 1
        elif (token.name in ['br', 'b', 'i', 'em']):
            if (not open_pTag):
                pTag = Tag(result, 'p')
                open_pTag = True
                ptc = 0
            pTag.insert(ptc, token)
            ptc += 1
        else:
            if open_pTag:
                result.insert(rtc, pTag)
                rtc += 1
                open_pTag = False
                ptc = 0
            sub_tokens = list(token.contents)
            for sub_token in sub_tokens:
                if (type(sub_token) is NavigableString):
                    sub_token.replaceWith(prepare_string_for_xml(sub_token))
            result.insert(rtc, token)
            rtc += 1
    if open_pTag:
        result.insert(rtc, pTag)
        rtc += 1
    paras = result.findAll('p')
    for p in paras:
        p['class'] = 'description'
    for elem in elems:
        result.insert(rtc, elem)
        rtc += 1
    return result.renderContents(encoding=None)
