Skip to content
Open
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 @@ -117,6 +117,11 @@ void onNextChar(char c, int depth, State initialState, State currentState) throw
case START:
indent = getElementIndent(depth);
break;
case IN_PROCESSING_INSTRUCTION_OR_DECLARATION:
if (initialState == State.TAG_LEFT_ANGLE_BRACKET) {
deferredLeftAngle = true;
}
break;
}

if (indent > 0 || deferredLeftAngle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ public void simplePrettyPrintTestTabIndent() throws IOException {
xmlPrettyPrintTest(expectedPrettyPrintedXml, inputXml, xmlPrettyPrinterBuilder);
}

@Test
public void simplePrettyPrintTestDeclaration() throws IOException {
String inputXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<p/>";
String expectedPrettyPrintedXml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<p/>";
XmlPrettyPrinter.Builder xmlPrettyPrinterBuilder = XmlPrettyPrinter
.builder()
.setTabWidth(2);
Copy link
Member

@Flowdalic Flowdalic Dec 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setTabWidth() seems unnecessary?


xmlPrettyPrintTest(expectedPrettyPrintedXml, inputXml, xmlPrettyPrinterBuilder);
}

private static void xmlPrettyPrintTest(String expectedPrettyPrintedXml, String inputXml,
XmlPrettyPrinter.Builder xmlPrettyPrinterBuilder) throws IOException {
final StringHolder stringHolder = new StringHolder();
Expand Down