Add some more ignored tags when getting length of flow

This commit is contained in:
Kovid Goyal 2017-03-21 14:26:29 +05:30
parent 96375439d2
commit 3edb914a7d

View File

@ -133,11 +133,12 @@ def anchor_map(root):
def get_length(root): def get_length(root):
strip_space = re.compile(r'\s+') strip_space = re.compile(r'\s+')
ans = 0 ans = 0
ignore_tags = frozenset('script style title noscript'.split())
def count(elem): def count(elem):
num = 0 num = 0
tname = elem.tag.rpartition('}')[-1].lower() tname = elem.tag.rpartition('}')[-1].lower()
if elem.text and tname not in 'script style': if elem.text and tname not in ignore_tags:
num += len(strip_space.sub('', elem.text)) num += len(strip_space.sub('', elem.text))
if elem.tail: if elem.tail:
num += len(strip_space.sub('', elem.tail)) num += len(strip_space.sub('', elem.tail))
@ -219,7 +220,6 @@ class Container(ContainerBase):
if ans['is_html']: if ans['is_html']:
root = self.parsed(name) root = self.parsed(name)
ans['length'] = l = get_length(root) ans['length'] = l = get_length(root)
print(111111, name, ans['size'], l)
self.book_render_data['total_length'] += l self.book_render_data['total_length'] += l
if name in data['spine']: if name in data['spine']:
self.book_render_data['spine_length'] += l self.book_render_data['spine_length'] += l