diff --git a/src/calibre/ebooks/mobi/mobiml.py b/src/calibre/ebooks/mobi/mobiml.py index 12ea561469..ca48fb0a7f 100644 --- a/src/calibre/ebooks/mobi/mobiml.py +++ b/src/calibre/ebooks/mobi/mobiml.py @@ -376,8 +376,8 @@ class MobiMLizer(object): istate.preserve = (style['white-space'] in ('pre', 'pre-wrap')) istate.bgcolor = style['background-color'] istate.fgcolor = style['color'] - istate.strikethrough = style['text-decoration'] == 'line-through' - istate.underline = style['text-decoration'] == 'underline' + istate.strikethrough = style.effective_text_decoration == 'line-through' + istate.underline = style.effective_text_decoration == 'underline' ff = style['font-family'].lower() if style['font-family'] else '' if 'monospace' in ff or 'courier' in ff or ff.endswith(' mono'): istate.family = 'monospace' diff --git a/src/calibre/ebooks/oeb/stylizer.py b/src/calibre/ebooks/oeb/stylizer.py index cc52b3f9a1..adef0f1bfb 100644 --- a/src/calibre/ebooks/oeb/stylizer.py +++ b/src/calibre/ebooks/oeb/stylizer.py @@ -714,6 +714,26 @@ class Style(object): self._lineHeight = result return self._lineHeight + @property + def effective_text_decoration(self): + ''' + Browsers do this creepy thing with text-decoration where even though the + property is not inherited, it looks like it is because containing + blocks apply it. The actual algorithm is utterly ridiculous, see + http://reference.sitepoint.com/css/text-decoration + This matters for MOBI output, where text-decoration is mapped to + and tags. Trying to implement the actual algorithm is too much + work, so we just use a simple fake that should cover most cases. + ''' + css = self._style.get('text-decoration', None) + pcss = None + parent = self._get_parent() + if parent is not None: + pcss = parent._style.get('text-decoration', None) + if css in ('none', None) and pcss not in (None, 'none'): + return pcss + return css + @property def marginTop(self): return self._unit_convert(