Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
 def test_create_tabulation_pos(self):
     tab = odf_create_tabulation(4)
     expected = ('<text:tab text:tab-ref="4"/>')
     self.assertEqual(tab.serialize(), expected)
Exemplo n.º 4
0
 def test_create_tabulation(self):
     tab = odf_create_tabulation()
     expected = ('<text:tab/>')
     self.assertEqual(tab.serialize(), expected)
Exemplo n.º 5
0
 def test_create_tabulation_pos(self):
     tab = odf_create_tabulation(4)
     expected = ('<text:tab text:tab-ref="4"/>')
     self.assertEqual(tab.serialize(), expected)
Exemplo n.º 6
0
 def test_create_tabulation(self):
     tab = odf_create_tabulation()
     expected = ('<text:tab/>')
     self.assertEqual(tab.serialize(), expected)