vkiryukhin / vkBeautify

vkBeautify is a small, simple and powerfull javascript plugin to beautify XML, JSON, CSS and SQL text.
http://www.eslinstructor.net/vkbeautify/
Other
316 stars 97 forks source link

xml format issue #1

Closed Jimflip closed 12 years ago

Jimflip commented 12 years ago

It's not starting all elements on newlines, I get the same issue when using other xml sources.

<xs:schema>
    <xs:include schemaLocation="type.xsd"/>
    <xs:complexType name="GAME">
        <xs:sequence>
            <xs:element id="target" type="TARGET" name="TARGET"/>
            <xs:element name="AA" id="fonts_AA" type="AA">
                <xs:annotation>
                    <xs:appinfo source="FNT"/></xs:annotation>
            </xs:element>
            <xs:element name="AA" id="layers_AA" type="AA">
                <xs:annotation>
                    <xs:appinfo source="LAYER"/></xs:annotation>
            </xs:element>
            <xs:element name="AA" id="scenes_AA" type="AA">
                <xs:annotation>
                    <xs:appinfo source="SCENE"/></xs:annotation>
            </xs:element>
            <xs:element id="game_SOCK" type="SOCK" name="SOCK"/></xs:sequence>
        <xs:attribute name="id" type="xs:NMTOKEN"/></xs:complexType>
    <xs:complexType name="MAIN_SCENE">
        <xs:complexContent>
            <xs:extension base="SCENE">
                <xs:sequence>
                    <xs:element id="logo_SPR_REND" type="SPR_REND" name="SPR_REND"/></xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
</xs:schema>
Jimflip commented 12 years ago

This seems to fix it :)

if( /^<\w/.exec(ar[ix-1]) && /^<\/\w/.exec(ar[ix]) &&
/^<\w+/.exec(ar[ix-1]) == /^<\/\w+/.exec(ar[ix])[0].replace('/',''))
{ 
        str += this.shift[--deep]+ar[ix];
        if(!inComment) deep--;
}
vkiryukhin commented 12 years ago

Thank you for opening this issue, Jimflip.

Your solution works, but not exactly I want to. The matter is: I want to keep empty element at the same line to make text more compact. So I simply modified affected regexp statement.

-Vadim