From 0cf3dc05455afaea1eacc3589408b923938541b3 Mon Sep 17 00:00:00 2001 From: Peter Garst Date: Sat, 31 May 2014 15:54:32 -0700 Subject: [PATCH 1/2] Minor index fix, for entries with spaces --- src/calibre/ebooks/docx/fields.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/docx/fields.py b/src/calibre/ebooks/docx/fields.py index d43bc89ce8..adf0b448d6 100644 --- a/src/calibre/ebooks/docx/fields.py +++ b/src/calibre/ebooks/docx/fields.py @@ -26,7 +26,12 @@ class Field(object): if not raw: return if self.name is None: - self.name, raw = raw.strip().partition(' ')[0::2] + # There are cases where partial index entries end with + # a significant space, along the lines of + # <>Summary <> ... <>Hearing<>. + # No known examples of starting with a space yet. + # self.name, raw = raw.strip().partition(' ')[0::2] + self.name, raw = raw.lstrip().partition(' ')[0::2] self.buf.append(raw) def finalize(self): @@ -100,6 +105,7 @@ class Fields(object): def __call__(self, doc, log): all_ids = frozenset(XPath('//*/@w:id')(doc)) + # import pydevd;pydevd.settrace() c = 0 while self.index_bookmark_prefix in all_ids: c += 1 From 834e20d7742ce03327e06511b5cee89906a26833 Mon Sep 17 00:00:00 2001 From: Peter Garst Date: Sat, 31 May 2014 16:05:50 -0700 Subject: [PATCH 2/2] Cleaning up debugging code --- src/calibre/ebooks/docx/fields.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/calibre/ebooks/docx/fields.py b/src/calibre/ebooks/docx/fields.py index adf0b448d6..82e2c206d2 100644 --- a/src/calibre/ebooks/docx/fields.py +++ b/src/calibre/ebooks/docx/fields.py @@ -105,7 +105,6 @@ class Fields(object): def __call__(self, doc, log): all_ids = frozenset(XPath('//*/@w:id')(doc)) - # import pydevd;pydevd.settrace() c = 0 while self.index_bookmark_prefix in all_ids: c += 1