From 08ca34e73595c5a0418ce6134b2024a6669bb39a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 8 Dec 2019 06:47:42 +0530 Subject: [PATCH] DOCX Input: Avoid nested tags for footnote references Also avoid empty or tags. --- src/calibre/ebooks/docx/to_html.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/docx/to_html.py b/src/calibre/ebooks/docx/to_html.py index cc1175bbce..59f40d7745 100644 --- a/src/calibre/ebooks/docx/to_html.py +++ b/src/calibre/ebooks/docx/to_html.py @@ -702,7 +702,13 @@ class Convert(object): style = self.styles.resolve_run(run) if style.vert_align in {'superscript', 'subscript'}: - ans.tag = 'sub' if style.vert_align == 'subscript' else 'sup' + if ans.text or len(ans): + ans.tag = 'sub' if style.vert_align == 'subscript' else 'sup' + 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: lang = html_lang(style.lang) if lang is not None and lang != self.doc_lang: