Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove indentation when formatting only whitespace #504

Merged
merged 1 commit into from
Jul 8, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ private void format(DOMNode node) throws BadLocationException {
if (node.hasChildNodes()) {
// element has body

// startElementClosed = true;
this.indentLevel++;
for (DOMNode child : node.getChildren()) {
boolean textElement = !child.isText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ else if(hasSiblings) {
int newLineCount = StringUtils.getNumberOfNewLines(text, isWhitespaceContent, delimiter, preservedNewLines);
for (int i = 0; i < newLineCount - 1; i++) { // - 1 because the node after will insert a delimiter
xml.append(delimiter);
this.indent(level);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1137,11 +1137,11 @@ public void testContentFormatting6() throws BadLocationException {
"<!DOCTYPE note>\r\n" +
"<note>\r\n" +
" <to>Fred</to>\r\n" +
" \r\n" +
"\r\n" +
" <from>Jani</from>\r\n" +
" \r\n" +
"\r\n" +
" <heading>Reminder</heading>\r\n" +
" \r\n" +
"\r\n" +
" <body>Don't forget me this weekend</body>\r\n" +
"</note>";
format(content, expected, formattingOptions);
Expand Down Expand Up @@ -1209,10 +1209,10 @@ public void testDoctypeNoInternalSubsetNoNewlines() throws BadLocationException
"]>\r\n" +
"<note>\r\n" +
" <to>Fred</to>\r\n" +
" \r\n" +
" \r\n" +
"\r\n" +
"\r\n" +
" <from>Jani</from>\r\n" +
" \r\n" +
"\r\n" +
" <heading>Reminder</heading>\r\n" +
" <body>Don't forget me this weekend</body>\r\n" +
"</note>";
Expand Down Expand Up @@ -1321,7 +1321,7 @@ public void testDoctypeNoInternalSubsetNoNewlines() throws BadLocationException
"]>\r\n" +
"\r\n" +
"<note>\r\n" +
" \r\n" +
"\r\n" +
" <to>Fred</to>\r\n" +
"</note>";
format(content, expected, formattingOptions);
Expand Down Expand Up @@ -1536,9 +1536,9 @@ public void testAllDoctypeParameters() throws BadLocationException {
"]>\r\n" +
"<web-app>\r\n" +
" <display-name>sdsd</display-name>\r\n" +
" \r\n" +
"\r\n" +
" <servlet>\r\n" +
" \r\n" +
"\r\n" +
" <servlet-name>er</servlet-name>\r\n" +
" <servlet-class>dd</servlet-class>\r\n" +
" </servlet>\r\n" +
Expand Down Expand Up @@ -2050,8 +2050,8 @@ public void testPreserveNewlines() throws BadLocationException {
String expected =
"<xml>\r\n" +
" <a></a>\r\n" +
" \r\n" +
" \r\n" +
"\r\n" +
"\r\n" +
"</xml>";
format(content, expected, formattingOptions);
}
Expand All @@ -2070,9 +2070,9 @@ public void testPreserveNewlines3Max() throws BadLocationException {
String expected =
"<xml>\r\n" +
" <a></a>\r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
"\r\n" +
"\r\n" +
"\r\n" +
"</xml>";
format(content, expected, formattingOptions);
}
Expand All @@ -2091,8 +2091,8 @@ public void testPreserveNewlines2() throws BadLocationException {
String expected =
"<xml>\r\n" +
" <a></a>\r\n" +
" \r\n" +
" \r\n" +
"\r\n" +
"\r\n" +
"</xml>";
format(content, expected, formattingOptions);
}
Expand All @@ -2114,11 +2114,11 @@ public void testPreserveNewlinesBothSides() throws BadLocationException {
"</xml>";
String expected =
"<xml>\r\n" +
" \r\n" +
" \r\n" +
"\r\n" +
"\r\n" +
" <a></a>\r\n" +
" \r\n" +
" \r\n" +
"\r\n" +
"\r\n" +
"</xml>";
format(content, expected, formattingOptions);
}
Expand Down Expand Up @@ -2146,14 +2146,14 @@ public void testPreserveNewlinesBothSidesMultipleTags() throws BadLocationExcept
"</xml>";
String expected =
"<xml>\r\n" +
" \r\n" +
" \r\n" +
"\r\n" +
"\r\n" +
" <a></a>\r\n" +
" \r\n" +
" \r\n" +
"\r\n" +
"\r\n" +
" <b></b>\r\n" +
" \r\n" +
" \r\n" +
"\r\n" +
"\r\n" +
"</xml>";
format(content, expected, formattingOptions);
}
Expand All @@ -2169,7 +2169,7 @@ public void testPreserveNewlinesSingleLine() throws BadLocationException {
String expected =
"<xml>\r\n" +
" <a></a>\r\n" +
" \r\n" +
"\r\n" +
"</xml>";
format(content, expected, formattingOptions);
}
Expand All @@ -2188,6 +2188,29 @@ public void testPreserveNewlines4() throws BadLocationException {
format(content, expected, formattingOptions);
}

@Test
public void testNoSpacesOnNewLine() throws BadLocationException {
XMLFormattingOptions formattingOptions = createDefaultFormattingOptions();
String content =
"<a>\r\n" +
" <b></b>\r\n" +
"\r\n" +
"\r\n" +
" \r\n" +
"\r\n" +
"\r\n" +
" \r\n" +
"\r\n" +
"\r\n" +
"</a>";
String expected =
"<a>\r\n" +
" <b></b>\r\n" +
"\r\n" +
"\r\n" +
"</a>";
format(content, expected, formattingOptions);
}


@Test
Expand Down