mirror of
git://github.com/kovidgoyal/calibre.git
synced 2025-12-19 19:14:57 +01:00
DOCX Input: Fix cross-references using the "fldSimple" markup not being recognized by calibre.
Apparently some software in some circumstances generate field using fldSimple rather than instrText. fldSimple is in the spec, so add support for it to calibre's DOCX engine.
This commit is contained in:
parent
97b20f38f5
commit
336d4054d1
1 changed files with 15 additions and 2 deletions
|
|
@ -23,7 +23,9 @@ def __init__(self, start):
|
|||
self.name = None
|
||||
|
||||
def add_instr(self, elem):
|
||||
raw = elem.text
|
||||
self.add_raw(elem.text)
|
||||
|
||||
def add_raw(self, raw):
|
||||
if not raw:
|
||||
return
|
||||
if self.name is None:
|
||||
|
|
@ -113,7 +115,10 @@ def __call__(self, doc, log):
|
|||
self.index_bookmark_prefix = self.index_bookmark_prefix.replace('-', '%d-' % c)
|
||||
stack = []
|
||||
for elem in self.namespace.XPath(
|
||||
'//*[name()="w:p" or name()="w:r" or name()="w:instrText" or (name()="w:fldChar" and (@w:fldCharType="begin" or @w:fldCharType="end"))]')(doc):
|
||||
'//*[name()="w:p" or name()="w:r" or'
|
||||
' name()="w:instrText" or'
|
||||
' (name()="w:fldChar" and (@w:fldCharType="begin" or @w:fldCharType="end") or'
|
||||
' name()="w:fldSimple")]')(doc):
|
||||
if elem.tag.endswith('}fldChar'):
|
||||
typ = self.namespace.get(elem, 'w:fldCharType')
|
||||
if typ == 'begin':
|
||||
|
|
@ -127,6 +132,14 @@ def __call__(self, doc, log):
|
|||
elif elem.tag.endswith('}instrText'):
|
||||
if stack:
|
||||
stack[-1].add_instr(elem)
|
||||
elif elem.tag.endswith('}fldSimple'):
|
||||
field = Field(elem)
|
||||
instr = self.namespace.get(elem, 'w:instr')
|
||||
if instr:
|
||||
field.add_raw(instr)
|
||||
self.fields.append(field)
|
||||
for r in self.namespace.XPath('descendant::w:r')(elem):
|
||||
field.contents.append(r)
|
||||
else:
|
||||
if stack:
|
||||
stack[-1].contents.append(elem)
|
||||
|
|
|
|||
Loading…
Reference in a new issue