Further improve logic for inserting Mobi filepos anchors.

This commit is contained in:
Marshall T. Vandegrift 2009-02-03 22:58:55 -05:00
parent 88ba45cbaa
commit 7f97d458db

View File

@ -434,16 +434,15 @@ class MobiReader(object):
oend = end oend = end
l = self.mobi_html.find('<', end) l = self.mobi_html.find('<', end)
r = self.mobi_html.find('>', end) r = self.mobi_html.find('>', end)
p = self.mobi_html.rfind('>', end) anchor = '<a id="filepos%d"></a>'
if r > -1 and (r < l or l == end or l == -1): if r > -1 and (r < l or l == end or l == -1):
end = r p = self.mobi_html.rfind('<', 0, end + 1)
anchor = ' filepos-id="filepos%d"' % oend if p > -1 and self.mobi_html[p + 1] != '/':
elif p > pos: anchor = ' filepos-id="filepos%d"'
end = p end = r
anchor = ' filepos-id="filepos%d"' % oend else:
else: end = r + 1
anchor = '<a id="filepos%d"></a>' % oend self.processed_html += self.mobi_html[pos:end] + (anchor % oend)
self.processed_html += self.mobi_html[pos:end] + anchor
pos = end pos = end
self.processed_html += self.mobi_html[pos:] self.processed_html += self.mobi_html[pos:]