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

prettyPrint and outline surround inline-tags with white space (where they shouldn't) #1305

Closed
EdyHinzen opened this issue Jan 22, 2020 · 2 comments
Labels
bug Confirmed bug that we should fix
Milestone

Comments

@EdyHinzen
Copy link

Using this code with jsoup 1.11.3:

String html = "<div><span>1:15</span>&ndash;<span>2:15</span>&nbsp;p.m.</div>";
org.jsoup.nodes.Document document = Jsoup.parse(html);
document.outputSettings().prettyPrint(false).outline(false);
System.out.println("Example 1:");
System.out.println(document.body().html());
document.outputSettings().prettyPrint(true).outline(false);
System.out.println("Example 2:");
System.out.println(document.body().html());
document.outputSettings().prettyPrint(true).outline(true);
System.out.println("Example 3:");
System.out.println(document.body().html());

Results in

Example 1:
<div><span>1:15</span>–<span>2:15</span>&nbsp;p.m.</div>
Example 2:
<div>
 <span>1:15</span>–
 <span>2:15</span>&nbsp;p.m.
</div>
Example 3:
<div>
 <span>1:15</span>
 –
 <span>2:15</span>
 &nbsp;p.m.
</div>

Example 1: Please watch that there are no white spaces around the en-dash. That's correct.
Example 2: Additional white space after the en-dash.
Example 3: Additional white space before and after the en-dash.

Examples 2 and 3 result in incorrect typography and I hereby consider that as a bug.

It is likely that this problem is similar to issue #851

kovacstamasx added a commit to kovacstamasx/jsoup that referenced this issue Jan 26, 2020
@kovacstamasx
Copy link
Contributor

Hi Edy,

I've opened a PR to fix your issue.
It would print inline tags in the same line when using pretty print without the outline option.

Though I'm not sure that your Example 3 is a bug.
When you use outline(true) all tags and nodes should be handled as blocks.
And line break is needed when you pretty print blocks.

@jhy jhy added the bug Confirmed bug that we should fix label Jan 31, 2020
@jhy jhy added this to the 1.12.2 milestone Jan 31, 2020
jhy pushed a commit that referenced this issue Feb 2, 2020
@jhy
Copy link
Owner

jhy commented Feb 2, 2020

Thanks! I have merged the PR (and tweaked with 279fbe1) to fix this.

@jhy jhy closed this as completed Feb 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug that we should fix
Projects
None yet
Development

No branches or pull requests

3 participants