DOCX Input: When converting indices, put each sub-entry on its own line. See #1811611 (Word to EPUB adds a digit at the end of some chapters)

This commit is contained in:
Kovid Goyal 2019-01-17 15:04:51 +05:30
parent 78f093f1a3
commit 31bf791ad6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -59,9 +59,11 @@ def make_block(expand, style, parent, pos):
def add_xe(xe, t, expand): def add_xe(xe, t, expand):
text = xe.get('text', '') run = t.getparent()
idx = run.index(t)
t.text = xe.get('text') or ' '
pt = xe.get('page-number-text', None) pt = xe.get('page-number-text', None)
t.text = text or ' '
if pt: if pt:
p = t.getparent().getparent() p = t.getparent().getparent()
r = p.makeelement(expand('w:r')) r = p.makeelement(expand('w:r'))
@ -70,7 +72,9 @@ def add_xe(xe, t, expand):
t2.set(expand('xml:space'), 'preserve') t2.set(expand('xml:space'), 'preserve')
t2.text = ' [%s]' % pt t2.text = ' [%s]' % pt
r.append(t2) r.append(t2)
return xe['anchor'], t.getparent() # put separate entries on separate lines
run.insert(idx + 1, run.makeelement(expand('w:br')))
return xe['anchor'], run
def process_index(field, index, xe_fields, log, XPath, expand): def process_index(field, index, xe_fields, log, XPath, expand):
@ -139,6 +143,7 @@ def split_up_block(block, a, text, parts, ldict):
span.append(a) span.append(a)
ldict[span] = len(prefix) ldict[span] = len(prefix)
""" """
The merge algorithm is a little tricky. The merge algorithm is a little tricky.
We start with a list of elementary blocks. Each is an HtmlElement, a p node We start with a list of elementary blocks. Each is an HtmlElement, a p node
@ -255,6 +260,9 @@ def polish_index_markup(index, blocks):
span.append(a[0]) span.append(a[0])
ldict[span] = 0 ldict[span] = 0
for br in block.xpath('descendant::br'):
br.tail = None
# We want a single block for each main entry # We want a single block for each main entry
prev_block = blocks[0] prev_block = blocks[0]
for block in blocks[1:]: for block in blocks[1:]:
@ -263,4 +271,3 @@ def polish_index_markup(index, blocks):
merge_blocks(prev_block, block, 0, 0, pn, ldict) merge_blocks(prev_block, block, 0, 0, pn, ldict)
else: else:
prev_block = block prev_block = block