Skip to content

Commit

Permalink
Fix #75: Correct formatting of nested tags with the same name
Browse files Browse the repository at this point in the history
  • Loading branch information
sibprogrammer committed Apr 15, 2024
1 parent ed40073 commit 4b7feb6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ func FormatXml(reader io.Reader, writer io.Writer, indent string, colors int) er
}
hasContent = false
lastTagName = currentTagName
if startTagClosed {
lastTagName = ""
}
case xml.Directive:
_, _ = fmt.Fprint(writer, tagColor("<!"), string(typedToken), tagColor(">"))
_, _ = fmt.Fprint(writer, newline, strings.Repeat(indent, level))
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 @@ -36,6 +36,7 @@ func TestFormatXml(t *testing.T) {
"unformatted11.xml": "formatted11.xml",
"unformatted12.xml": "formatted12.xml",
"unformatted13.xml": "formatted13.xml",
"unformatted14.xml": "formatted14.xml",
}

for unformattedFile, expectedFile := range files {
Expand Down
6 changes: 6 additions & 0 deletions test/data/xml/formatted14.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<svg height="297mm" width="210mm">
<g stroke="#2f4f4f" stroke-linecap="round" stroke-linejoin="round">
<g fill="#fff"/>
</g>
</svg>
7 changes: 7 additions & 0 deletions test/data/xml/unformatted14.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<svg height="297mm" width="210mm">
<g stroke="#2f4f4f" stroke-linecap="round" stroke-linejoin="round">
<g fill="#fff">
</g>
</g>
</svg>

0 comments on commit 4b7feb6

Please sign in to comment.