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

fix pretty print in Declaration #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Loading