DOCX Input: Handle docx files with index fields that have their field names incorrectly lower cased. Fixes #1318670 [Conversion from DOCX, probably indexitem related](https://bugs.launchpad.net/calibre/+bug/1318670)

This commit is contained in:
Kovid Goyal 2014-05-12 20:50:34 +05:30
parent fa9b43f7f1
commit 97b222caca
2 changed files with 12 additions and 4 deletions

View File

@ -126,10 +126,13 @@ class Fields(object):
field_types = ('hyperlink', 'xe', 'index', 'ref', 'noteref')
parsers = {x.upper():getattr(self, 'parse_'+x) for x in field_types}
parsers.update({x:getattr(self, 'parse_'+x) for x in field_types})
field_parsers = {f.upper():globals()['parse_%s' % f] for f in field_types}
field_parsers.update({f:globals()['parse_%s' % f] for f in field_types})
for f in field_types:
setattr(self, '%s_fields' % f, [])
unknown_fields = {'TOC', 'toc', 'PAGEREF', 'pageref'} # The TOC and PAGEREF fields are handled separately
for field in self.fields:
field.finalize()
@ -137,6 +140,9 @@ class Fields(object):
func = parsers.get(field.name, None)
if func is not None:
func(field, field_parsers[field.name], log)
elif field.name not in unknown_fields:
log.warn('Encountered unknown field: %s, ignoring it.' % field.name)
unknown_fields.add(field.name)
def get_runs(self, field):
all_runs = []
@ -200,6 +206,8 @@ class Fields(object):
return
idx = parse_func(field.instructions, log)
hyperlinks, blocks = process_index(field, idx, self.xe_fields, log)
if not blocks:
return
for anchor, run in hyperlinks:
self.hyperlink_fields.append(({'anchor':anchor}, [run]))

View File

@ -91,7 +91,7 @@ def process_index(field, index, xe_fields, log):
xe_fields = get_applicable_xe_fields(index, xe_fields)
if not xe_fields:
return
return [], []
if heading_text is not None:
groups = partition_by_first_letter(xe_fields, key=itemgetter('text'))
items = []