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_tabulation_pos(self): tab = odf_create_tabulation(4) expected = ('<text:tab text:tab-ref="4"/>') self.assertEqual(tab.serialize(), expected)
def test_create_tabulation(self): tab = odf_create_tabulation() expected = ('<text:tab/>') self.assertEqual(tab.serialize(), expected)