'Serialize all items in the spine of the document. Non linear items are
moved to the end.'

def serialize_body(self):

    buf = self.buf
    def serialize_toc_level(tocref, href=None):
        if (href is not None):
            buf.write(u'<mbp:pagebreak    />')
            self.id_offsets[urlnormalize(href)] = buf.tell()
        if (tocref.klass == u'periodical'):
            buf.write(u'<div>    <div    height="1em"></div>')
        else:
            t = tocref.title
            if isinstance(t, unicode):
                t = t.encode(u'utf-8')
            buf.write(((u'<div></div>    <div>    <h2    height="1em"><font    size="+2"><b>' + t) + u'</b></font></h2>    <div    height="1em"></div>'))
        buf.write(u'<ul>')
        for tocitem in tocref.nodes:
            buf.write(u'<li><a    filepos=')
            itemhref = tocitem.href
            if (tocref.klass == u'periodical'):
                itemhref = re.sub(u'article_\\d+/', u'', itemhref)
            self.href_offsets[itemhref].append(buf.tell())
            buf.write(u'0000000000')
            buf.write(u'    ><font    size="+1"><b><u>')
            t = tocitem.title
            if isinstance(t, unicode):
                t = t.encode(u'utf-8')
            buf.write(t)
            buf.write(u'</u></b></font></a></li>')
        buf.write(u'</ul><div    height="1em"></div></div><mbp:pagebreak    />')
    self.anchor_offset = buf.tell()
    buf.write('<body>')
    self.body_start_offset = buf.tell()
    if self.is_periodical:
        top_toc = self.oeb.toc.nodes[0]
        serialize_toc_level(top_toc)
    spine = [item for item in self.oeb.spine if item.linear]
    spine.extend([item for item in self.oeb.spine if (not item.linear)])
    for item in spine:
        if (self.is_periodical and item.is_section_start):
            for section_toc in top_toc.nodes:
                if (urlnormalize(item.href) == section_toc.href):
                    section_url = re.sub(u'article_\\d+/', u'', section_toc.href)
                    serialize_toc_level(section_toc, section_url)
                    section_toc.href = section_url
                    break
        self.serialize_item(item)
    self.body_end_offset = buf.tell()
    buf.write('</body>')
