DOCX Input: Fix incorrect font sizes for footnote references in paragraphs that have text with multiple font sizes. Fixes #1855403 [Private bug](https://bugs.launchpad.net/calibre/+bug/1855403)

This commit is contained in:
Kovid Goyal 2019-12-08 07:45:31 +05:30
parent 08ca34e735
commit 9d8ad144ff
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 16 additions and 8 deletions

View File

@ -104,7 +104,20 @@ def before_count(root, tag, limit=10):
return limit return limit
def wrap_contents(tag_name, elem):
wrapper = elem.makeelement(tag_name)
wrapper.text, elem.text = elem.text, ''
for child in elem:
elem.remove(child)
wrapper.append(child)
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):
# Apply vertical-align
for span in root.xpath('//span[@data-docx-vert]'):
wrap_contents(span.attrib.pop('data-docx-vert'), span)
# 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'):

View File

@ -10,7 +10,7 @@ from collections import OrderedDict, defaultdict
from lxml import html from lxml import html
from lxml.html.builder import ( from lxml.html.builder import (
HTML, HEAD, TITLE, BODY, LINK, META, P, SPAN, BR, DIV, SUP, A, DT, DL, DD, H1) HTML, HEAD, TITLE, BODY, LINK, META, P, SPAN, BR, DIV, A, DT, DL, DD, H1)
from calibre import guess_type from calibre import guess_type
from calibre.ebooks.docx.container import DOCX, fromstring from calibre.ebooks.docx.container import DOCX, fromstring
@ -684,7 +684,7 @@ class Convert(object):
elif self.namespace.is_tag(child, 'w:footnoteReference') or self.namespace.is_tag(child, 'w:endnoteReference'): elif self.namespace.is_tag(child, 'w:footnoteReference') or self.namespace.is_tag(child, 'w:endnoteReference'):
anchor, name = self.footnotes.get_ref(child) anchor, name = self.footnotes.get_ref(child)
if anchor and name: if anchor and name:
l = A(SUP(name, id='back_%s' % anchor), href='#' + anchor, title=name) l = A(name, id='back_%s' % anchor, href='#' + anchor, title=name)
l.set('class', 'noteref') l.set('class', 'noteref')
text.add_elem(l) text.add_elem(l)
ans.append(text.elem) ans.append(text.elem)
@ -703,12 +703,7 @@ class Convert(object):
style = self.styles.resolve_run(run) style = self.styles.resolve_run(run)
if style.vert_align in {'superscript', 'subscript'}: if style.vert_align in {'superscript', 'subscript'}:
if ans.text or len(ans): if ans.text or len(ans):
ans.tag = 'sub' if style.vert_align == 'subscript' else 'sup' ans.set('data-docx-vert', 'sup' if style.vert_align == 'superscript' else 'sub')
try:
if ans[0].tag == 'a' and ans[0].get('class', 'noteref') and ans[0][0].tag == 'sup' and ans.tag == 'sup':
ans[0][0].tag = 'span'
except Exception:
pass
if style.lang is not inherit: if style.lang is not inherit:
lang = html_lang(style.lang) lang = html_lang(style.lang)
if lang is not None and lang != self.doc_lang: if lang is not None and lang != self.doc_lang: