def handle_whitespace(text): """Add ODF whitespace processing and ODF linebreak elements into multi-line text. Returns list with mixed unicode and odf elements.""" result = [] lines = text.split('\n') for index, line in enumerate(lines): # for every line for part in _whitespace_re.split(line): # split off tabulators and whitespace if part[:2] == ' ': # multiple spaces in ODF need markup result.append( odf_create_spaces(len(part))) elif part[:1] == '\t': # insert an actual tab result.append( odf_create_tabulation()) else: result.append( unicode(part)) # for all but the last line: add linebreak if index < len(lines)-1: result.append(odf_create_line_break()) return result
def test_create_spaces(self): sp5 = odf_create_spaces(5) expected = ('<text:s text:c="5"/>') self.assertEqual(sp5.serialize(), expected)
def test_create_space(self): sp1 = odf_create_spaces() expected = ('<text:s text:c="1"/>') self.assertEqual(sp1.serialize(), expected)