EPUB Output: Fix splitting of large HTML files removing all child tags from inside <pre> tags. Fixes #1267327 [Private bug](https://bugs.launchpad.net/calibre/+bug/1267327)

This commit is contained in:
Kovid Goyal 2014-01-12 09:25:07 +05:30
parent de49923947
commit 901f54e124

View File

@ -317,13 +317,11 @@ class FlowSplitter(object):
def split_to_size(self, tree): def split_to_size(self, tree):
self.log.debug('\t\tSplitting...') self.log.debug('\t\tSplitting...')
root = tree.getroot() root = tree.getroot()
# Split large <pre> tags # Split large <pre> tags if they contain only text
for pre in list(XPath('//h:pre')(root)): for pre in XPath('//h:pre')(root):
text = u''.join(pre.xpath('descendant::text()')) if len(tuple(pre.iterchildren(etree.Element))) > 0:
pre.text = text continue
for child in list(pre.iterchildren()): if pre.text and len(pre.text) > self.max_flow_size*0.5:
pre.remove(child)
if len(pre.text) > self.max_flow_size*0.5:
self.log.debug('\t\tSplitting large <pre> tag') self.log.debug('\t\tSplitting large <pre> tag')
frags = self.split_text(pre.text, root, int(0.2*self.max_flow_size)) frags = self.split_text(pre.text, root, int(0.2*self.max_flow_size))
new_pres = [] new_pres = []