mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
DOCX Input: When some text has multiple footnotes insert a space between the consecutive foot note numbers so that they are distinct. Fixes #2089433 [Separate several footnote/endnote references](https://bugs.launchpad.net/calibre/+bug/2089433)
This commit is contained in:
parent
90b33c9648
commit
2dacaf7da2
@ -113,11 +113,19 @@ def wrap_contents(tag_name, elem):
|
|||||||
elem.append(wrapper)
|
elem.append(wrapper)
|
||||||
|
|
||||||
|
|
||||||
def cleanup_markup(log, root, styles, dest_dir, detect_cover, XPath):
|
def cleanup_markup(log, root, styles, dest_dir, detect_cover, XPath, uuid):
|
||||||
# Apply vertical-align
|
# Apply vertical-align
|
||||||
for span in root.xpath('//span[@data-docx-vert]'):
|
for span in root.xpath('//span[@data-docx-vert]'):
|
||||||
wrap_contents(span.attrib.pop('data-docx-vert'), span)
|
wrap_contents(span.attrib.pop('data-docx-vert'), span)
|
||||||
|
|
||||||
|
for span in root.xpath(f'//*[@data-noteref-container="{uuid}"]'):
|
||||||
|
span.attrib.pop('data-noteref-container')
|
||||||
|
parent = span.getparent()
|
||||||
|
idx = parent.index(span)
|
||||||
|
if idx + 1 < len(parent) and (ns := parent[idx+1]) and hasattr(ns, 'get') and ns.get('data-noteref-container'):
|
||||||
|
if len(span) and not span[-1].tail:
|
||||||
|
span[-1].tail = '\xa0'
|
||||||
|
|
||||||
# Move <hr>s outside paragraphs, if possible.
|
# Move <hr>s outside paragraphs, if possible.
|
||||||
pancestor = XPath('|'.join('ancestor::%s[1]' % x for x in ('p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6')))
|
pancestor = XPath('|'.join('ancestor::%s[1]' % x for x in ('p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6')))
|
||||||
for hr in root.xpath('//span/hr'):
|
for hr in root.xpath('//span/hr'):
|
||||||
|
@ -75,6 +75,7 @@ class Convert:
|
|||||||
self.dest_dir = dest_dir or os.getcwd()
|
self.dest_dir = dest_dir or os.getcwd()
|
||||||
self.mi = self.docx.metadata
|
self.mi = self.docx.metadata
|
||||||
self.body = BODY()
|
self.body = BODY()
|
||||||
|
self.uuid = uuid.uuid4().hex
|
||||||
self.theme = Theme(self.namespace)
|
self.theme = Theme(self.namespace)
|
||||||
self.settings = Settings(self.namespace)
|
self.settings = Settings(self.namespace)
|
||||||
self.tables = Tables(self.namespace)
|
self.tables = Tables(self.namespace)
|
||||||
@ -241,7 +242,7 @@ class Convert:
|
|||||||
self.fields.polish_markup(self.object_map)
|
self.fields.polish_markup(self.object_map)
|
||||||
|
|
||||||
self.log.debug('Cleaning up redundant markup generated by Word')
|
self.log.debug('Cleaning up redundant markup generated by Word')
|
||||||
self.cover_image = cleanup_markup(self.log, self.html, self.styles, self.dest_dir, self.detect_cover, self.namespace.XPath)
|
self.cover_image = cleanup_markup(self.log, self.html, self.styles, self.dest_dir, self.detect_cover, self.namespace.XPath, self.uuid)
|
||||||
|
|
||||||
return self.write(doc)
|
return self.write(doc)
|
||||||
|
|
||||||
@ -713,6 +714,7 @@ class Convert:
|
|||||||
l.set('role', 'doc-noteref')
|
l.set('role', 'doc-noteref')
|
||||||
text.add_elem(l)
|
text.add_elem(l)
|
||||||
ans.append(text.elem)
|
ans.append(text.elem)
|
||||||
|
ans.set('data-noteref-container', self.uuid)
|
||||||
elif self.namespace.is_tag(child, 'w:tab'):
|
elif self.namespace.is_tag(child, 'w:tab'):
|
||||||
spaces = int(math.ceil((self.settings.default_tab_stop / 36) * 6))
|
spaces = int(math.ceil((self.settings.default_tab_stop / 36) * 6))
|
||||||
text.add_elem(SPAN(NBSP * spaces))
|
text.add_elem(SPAN(NBSP * spaces))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user