import re
from bs4 import BeautifulSoup


def parseBookmarksHtml(bookmarks):
    """
    Return BeautifulSoup object, having wrapped each bookmark in a DIV tag.
    """
    # Some bookmarks have descriptions (dd) and some don't.
    pattern = r'(<dt>.+?<\/dt>(.?<dd>.+?<\/dd>)?)'
    bookmarks = re.findall(pattern, bookmarks, re.DOTALL)
    data = []
    wrapper = '<div class="bookmark">%s</div>'
    for aBookmark in bookmarks:
        # The regular expression we've relied on gives us a tuple.
        data.append(wrapper % (aBookmark[0].replace('\n', '')))
    return BeautifulSoup(''.join(data), 'html.parser')