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

[alignment] Fix alignment issues so repeated processing works properly #1663

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/org/jsoup/nodes/Node.java
Expand Up @@ -696,6 +696,10 @@ public String toString() {
return outerHtml();
}

protected void indent(Appendable accum, int depth, Document.OutputSettings out, int lessSpace) throws IOException {
accum.append('\n').append(StringUtil.padding((depth * out.indentAmount()) - lessSpace, out.maxPaddingWidth()));
}

protected void indent(Appendable accum, int depth, Document.OutputSettings out) throws IOException {
accum.append('\n').append(StringUtil.padding(depth * out.indentAmount(), out.maxPaddingWidth()));
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/jsoup/nodes/TextNode.java
Expand Up @@ -89,8 +89,15 @@ void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) thr
if (parentIndent && StringUtil.startsWithNewline(coreValue()) && blank) // we are skippable whitespace
return;

if (prettyPrint && ((siblingIndex == 0 && parent != null && parent.tag().formatAsBlock() && !blank) || (out.outline() && siblingNodes().size()>0 && !blank) ))
indent(accum, depth, out);
if (prettyPrint && ((siblingIndex() == 0 && parent != null && parent.tag().formatAsBlock() && !blank) || (out.outline() && !siblingNodes().isEmpty() && !blank) )) {
String normalized = StringUtil.normaliseWhitespace(coreValue());
boolean startsWithSpace = normalized.startsWith(" ");
if (startsWithSpace) {
indent(accum, depth, out, 1);
} else {
indent(accum, depth, out);
}
}

final boolean normaliseWhite = prettyPrint && !Element.preserveWhitespace(parentNode);
final boolean stripWhite = prettyPrint && parentNode instanceof Document;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/jsoup/nodes/ElementTest.java
Expand Up @@ -499,7 +499,7 @@ public void testPrettyAndOutlineWithEnDashBody() {
Document document = Jsoup.parse(html);
document.outputSettings().outline(true);

assertEquals("<div>\n <span>1:15</span>\n –\n <span>2:15</span>\n &nbsp;p.m.\n</div>", document.body().html());
assertEquals("<div>\n <span>1:15</span>\n –\n <span>2:15</span>\n&nbsp;p.m.\n</div>", document.body().html());
}

@Test
Expand Down