Ejemplo n.º 1
0
    def unindent(self, text):
        if text:
            match = first_char_exp.search(text)

            if match:
                first_char = match.group(1)

                if first_char == '<':
                    formatter = XmlIndentFormatter('', True)
                    return formatter.indent(text)
                else:
                    formatter = JsonFormatter(JsonReader(text), {'remove_comments': True, 'spacer': '', 'newline': '', 'indent_character': ''})
                    return formatter.format()
Ejemplo n.º 2
0
    def format(self, text, indent_char = '\t'):
        if text:
            match = first_char_exp.search(text)

            if match:
                first_char = match.group(1)

                if first_char == '<':
                    formatter = XmlIndentFormatter(indent_char)
                    return formatter.indent(text)
                else:
                    formatter = JsonFormatter(JsonReader(text), {'indent_character': indent_char})
                    return formatter.format()
Ejemplo n.º 3
0
    def format(self, text, indent_char='\t'):
        if text:
            match = first_char_exp.search(text)

            if match:
                first_char = match.group(1)

                if first_char == '<':
                    formatter = XmlIndentFormatter(indent_char)
                    return formatter.indent(text)
                else:
                    formatter = JsonFormatter(
                        JsonReader(text), {'indent_character': indent_char})
                    return formatter.format()
Ejemplo n.º 4
0
    def unindent(self, text):
        if text:
            match = first_char_exp.search(text)

            if match:
                first_char = match.group(1)

                if first_char == '<':
                    formatter = XmlIndentFormatter('', True)
                    return formatter.indent(text)
                else:
                    formatter = JsonFormatter(
                        JsonReader(text), {
                            'remove_comments': True,
                            'spacer': '',
                            'newline': '',
                            'indent_character': ''
                        })
                    return formatter.format()
Ejemplo n.º 5
0
 def test_should_format_strip_comments_and_white_pace(self):
     formatter = XmlIndentFormatter('', True, True)
     formattedText = formatter.indent('<root>\n\n\n\n <!-- comment -->\n <child a="1"\nb="2"></child>\n</root>')
     expect(formattedText).to_equal('<root><child a="1" b="2"></child></root>')
Ejemplo n.º 6
0
 def test_should_format_xml_removing_white_space(self):
     formatter = XmlIndentFormatter(' ', False, True)
     formattedText = formatter.indent('<root>\n\n\n<!--comment--><child></child></root>')
     expect(formattedText).to_equal('<root>\n <!--comment-->\n <child></child>\n</root>')
Ejemplo n.º 7
0
 def test_should_format_malformed_xml(self):
     formatter = XmlIndentFormatter(' ')
     formattedText = formatter.indent('<root><child><child with="this attribute" and="that attribute" /></root>')
     expect(formattedText).to_equal('<root>\n <child>\n  <child with="this attribute" and="that attribute" />\n </root>')
Ejemplo n.º 8
0
 def test_should_format_xml_with_comment(self):
     formatter = XmlIndentFormatter(' ')
     formattedText = formatter.indent('<root><!--comment--><child></child></root>')
     expect(formattedText).to_equal('<root>\n <!--comment-->\n <child></child>\n</root>')