'Mark every item in the spine if it is the start/end of a
section/article, so that it can be wrapped in divs appropriately.'

def find_blocks(self):

    for item in self.oeb.spine:
        item.is_section_start = item.is_section_end = False
        item.is_article_start = item.is_article_end = False
    def spine_item(tocitem):
        href = urldefrag(tocitem.href)[0]
        for item in self.oeb.spine:
            if (item.href == href):
                return item
    for item in self.oeb.toc.iterdescendants():
        if (item.klass == u'section'):
            articles = list(item)
            if (not articles):
                continue
            spine_item(item).is_section_start = True
            for (i, article) in enumerate(articles):
                si = spine_item(article)
                if (si is not None):
                    si.is_article_start = True
    items = list(self.oeb.spine)
    in_sec = in_art = False
    for (i, item) in enumerate(items):
        try:
            prev_item = items[(i - 1)]
        except:
            prev_item = None
        if (in_art and (item.is_article_start is True)):
            prev_item.is_article_end = True
            in_art = False
        if (in_sec and (item.is_section_start is True)):
            prev_item.is_section_end = True
            in_sec = False
        if item.is_section_start:
            in_sec = True
        if item.is_article_start:
            in_art = True
    item.is_section_end = item.is_article_end = True
