ODT Input: Fix handling of span tags containing only whitespace. Fixes #887311 (Random dropping spaces in ODT text)

This commit is contained in:
Kovid Goyal 2011-11-10 18:04:42 +05:30
parent d0dd1c1918
commit 17fb07e8aa

View File

@ -24,12 +24,9 @@
# in memory. The user should then be able to make operations and then save # in memory. The user should then be able to make operations and then save
# the structure again. # the structure again.
from xml.sax import make_parser,handler from xml.sax import handler
from xml.sax.xmlreader import InputSource
import xml.sax.saxutils
from element import Element from element import Element
from namespaces import OFFICENS from namespaces import OFFICENS
from cStringIO import StringIO
# #
# Parse the XML files # Parse the XML files
@ -102,9 +99,18 @@ class LoadParser(handler.ContentHandler):
if self.parse == False: if self.parse == False:
return return
self.level = self.level - 1 self.level = self.level - 1
str = ''.join(self.data) # Changed by Kovid to deal with <span> tags with only whitespace
if len(str.strip()) > 0: # content.
self.curr.addText(str, check_grammar=False) data = ''.join(self.data)
tn = getattr(self.curr, 'tagName', '')
try:
do_strip = not tn.startswith('text:')
except:
do_strip = True
if do_strip:
data = data.strip()
if data:
self.curr.addText(data, check_grammar=False)
self.data = [] self.data = []
self.curr = self.curr.parentNode self.curr = self.curr.parentNode
self.parent = self.curr self.parent = self.curr