From 9e0f5fe52766939c7e462f3a5eec6bf162729935 Mon Sep 17 00:00:00 2001 From: "Marshall T. Vandegrift" Date: Tue, 3 Feb 2009 18:56:28 -0500 Subject: [PATCH] Fix #1772. Ensure content in prior to adding anchors. --- src/calibre/ebooks/mobi/mobiml.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/calibre/ebooks/mobi/mobiml.py b/src/calibre/ebooks/mobi/mobiml.py index 50d7b298b9..7ecd127452 100644 --- a/src/calibre/ebooks/mobi/mobiml.py +++ b/src/calibre/ebooks/mobi/mobiml.py @@ -138,7 +138,8 @@ class MobiMLizer(object): return result def mobimlize_content(self, tag, text, bstate, istates): - bstate.content = True + if text or tag != 'br': + bstate.content = True istate = istates[-1] para = bstate.para if tag in SPECIAL_TAGS and not text: @@ -188,11 +189,6 @@ class MobiMLizer(object): vspace -= 1 if istate.halign != 'auto': para.attrib['align'] = istate.halign - if istate.ids: - last = bstate.body[-1] - for id in istate.ids: - last.addprevious(etree.Element(XHTML('a'), attrib={'id': id})) - istate.ids.clear() pstate = bstate.istate if tag in CONTENT_TAGS: bstate.inline = para @@ -200,6 +196,11 @@ class MobiMLizer(object): etree.SubElement(para, XHTML(tag), attrib=istate.attrib) elif tag in TABLE_TAGS: para.attrib['valign'] = 'top' + if istate.ids: + last = bstate.body[-1] + for id in istate.ids: + last.addprevious(etree.Element(XHTML('a'), attrib={'id': id})) + istate.ids.clear() if not text: return if not pstate or istate != pstate: