diff --git a/src/calibre/ebooks/docx/cleanup.py b/src/calibre/ebooks/docx/cleanup.py index a46aef50e7..4b1828e39a 100644 --- a/src/calibre/ebooks/docx/cleanup.py +++ b/src/calibre/ebooks/docx/cleanup.py @@ -84,3 +84,14 @@ def cleanup_markup(root, styles): for child in span: parent.append(child) + # Make spans whose only styling is bold or italic into and tags + for span in root.xpath('//span[@class]'): + css = class_map.get(span.get('class', None), {}) + if len(css) == 1: + if css == {'font-style':'italic'}: + span.tag = 'i' + del span.attrib['class'] + elif css == {'font-weight':'bold'}: + span.tag = 'b' + del span.attrib['class'] +