Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,16 @@ func FormatXml(reader io.Reader, writer io.Writer, indent string, colors int) er
_, _ = fmt.Fprintf(writer, "%s%s", tagColor("<?"), typedToken.Target)

pi := strings.TrimSpace(string(typedToken.Inst))
attrs := strings.Split(pi, " ")
for _, attr := range attrs {
attrComponents := strings.SplitN(attr, "=", 2)
_, _ = fmt.Fprintf(writer, " %s%s", attrComponents[0], attrColor("="+attrComponents[1]))
if pi != "" {
attrs := strings.Split(pi, " ")
for _, attr := range attrs {
attrComponents := strings.SplitN(attr, "=", 2)
if len(attrComponents) == 2 {
_, _ = fmt.Fprintf(writer, " %s%s", attrComponents[0], attrColor("="+attrComponents[1]))
} else {
_, _ = fmt.Fprintf(writer, " %s", attrComponents[0])
}
}
}

_, _ = fmt.Fprint(writer, tagColor("?>"), newline)
Expand Down
1 change: 1 addition & 0 deletions internal/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestFormatXml(t *testing.T) {
"unformatted14.xml": "formatted14.xml",
"unformatted15.xml": "formatted15.xml",
"unformatted16.xml": "formatted16.xml",
"unformatted17.xml": "formatted17.xml",
}

for unformattedFile, expectedFile := range files {
Expand Down
8 changes: 8 additions & 0 deletions test/data/xml/formatted17.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet?>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<rss>
<channel>
<title>Test</title>
</channel>
</rss>
4 changes: 4 additions & 0 deletions test/data/xml/unformatted17.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet?>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<rss><channel><title>Test</title></channel></rss>
Loading