示例#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
示例#2
0
文件: odpdown.py 项目: xrmx/odpdown
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
示例#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)
示例#4
0
 def test_create_tabulation(self):
     tab = odf_create_tabulation()
     expected = ('<text:tab/>')
     self.assertEqual(tab.serialize(), expected)
示例#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)
示例#6
0
 def test_create_tabulation(self):
     tab = odf_create_tabulation()
     expected = ('<text:tab/>')
     self.assertEqual(tab.serialize(), expected)