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
l = 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):
p = self.mobi_html.rfind('<', 0, end + 1)
if p > -1 and self.mobi_html[p + 1] != '/':
anchor = ' filepos-id="filepos%d"'
end = r
anchor = ' filepos-id="filepos%d"' % oend
elif p > pos:
end = p
anchor = ' filepos-id="filepos%d"' % oend
else:
anchor = '<a id="filepos%d"></a>' % oend
self.processed_html += self.mobi_html[pos:end] + anchor
end = r + 1
self.processed_html += self.mobi_html[pos:end] + (anchor % oend)
pos = end
self.processed_html += self.mobi_html[pos:]