From f403520cc81ca40382b80c0b0a613097e5820070 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 10 Feb 2011 12:58:22 -0700 Subject: [PATCH] MOBI Output: Fix bug that was discarding non breaking spaces at the start of a paragraph when they were followed immediately by a tag. Fixes #4887 (Treatment of italics when converting to Mobi) --- src/calibre/ebooks/mobi/mobiml.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/mobi/mobiml.py b/src/calibre/ebooks/mobi/mobiml.py index 9733c5f4ca..17a14d9e12 100644 --- a/src/calibre/ebooks/mobi/mobiml.py +++ b/src/calibre/ebooks/mobi/mobiml.py @@ -39,6 +39,13 @@ def asfloat(value): return 0.0 return float(value) +def isspace(text): + if not text: + return True + if u'\xa0' in text: + return False + return text.isspace() + class BlockState(object): def __init__(self, body): self.body = body @@ -438,7 +445,7 @@ class MobiMLizer(object): if elem.text: if istate.preserve: text = elem.text - elif len(elem) > 0 and elem.text.isspace(): + elif len(elem) > 0 and isspace(elem.text): text = None else: text = COLLAPSE.sub(' ', elem.text) @@ -481,7 +488,7 @@ class MobiMLizer(object): if child.tail: if istate.preserve: tail = child.tail - elif bstate.para is None and child.tail.isspace(): + elif bstate.para is None and isspace(child.tail): tail = None else: tail = COLLAPSE.sub(' ', child.tail)