mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-05 08:33:43 +02:00
MOBI Input: Performance improvement when viewing/converting a file with a lot of links
This commit is contained in:
parent
24ff60d36c
commit
dfc1f39af7
1 changed files with 6 additions and 4 deletions
|
|
@ -929,7 +929,7 @@ def add_anchors(self):
|
|||
for match in link_pattern.finditer(self.mobi_html):
|
||||
positions.add(int(match.group(1)))
|
||||
pos = 0
|
||||
self.processed_html = ''
|
||||
processed_html = cStringIO.StringIO()
|
||||
end_tag_re = re.compile(r'<\s*/')
|
||||
for end in sorted(positions):
|
||||
if end == 0:
|
||||
|
|
@ -947,12 +947,14 @@ def add_anchors(self):
|
|||
end = r
|
||||
else:
|
||||
end = r + 1
|
||||
self.processed_html += self.mobi_html[pos:end] + (anchor % oend)
|
||||
processed_html.write(self.mobi_html[pos:end] + (anchor % oend))
|
||||
pos = end
|
||||
self.processed_html += self.mobi_html[pos:]
|
||||
processed_html.write(self.mobi_html[pos:])
|
||||
processed_html = processed_html.getvalue()
|
||||
|
||||
# Remove anchors placed inside entities
|
||||
self.processed_html = re.sub(r'&([^;]*?)(<a id="filepos\d+"></a>)([^;]*);',
|
||||
r'&\1\3;\2', self.processed_html)
|
||||
r'&\1\3;\2', processed_html)
|
||||
|
||||
|
||||
def extract_images(self, processed_records, output_dir):
|
||||
|
|
|
|||
Loading…
Reference in a new issue