Option to disable pretty print / intendation
theotherp opened this issue · 12 comments
I'm generating an HTML file with <pre>
elements. The first line of the content is incorrectly indented. Is there an option to prevent that?
Ok, I see your problem. What kind of disable indentation feature are you thinking?
-
Do you want to disable indentation at all and print whole document without any indentation?
-
Or do you want stop indentation at certain point (e.g. before invoking
pre()
) and then enable indentation again?
I don't really need pretty HTML at all so I don't have a preference. I guess ideally both, but disabling it globally would probably be easier. Looking at the code you would just have to skip the indent call.
Ok, I will include that feature for release 3.3. Can you please include here a small function with your use case of the pre
element for unit testing?
@Test
public void bla() throws Exception {
HtmlView htmlView = new HtmlView<>();
htmlView.body().pre().text("Some text");
String s;
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
htmlView.setPrintStream(new PrintStream(out));
htmlView.write();
s = out.toString();
}
assertTrue(s.replaceAll("<pre>\\s+", "<pre>").contains("<pre>Some text"));
assertFalse(s.contains("\tSome text"));
assertTrue(s.contains("<pre>Some text"));
}
@theotherp which version of HtmlFlow are you using?
@theotherp can you please tell me which version of HtmlFlow are you using?
2.0 I know it's a bit older but updating libraries is kind of a hassle here...
I just realized how crazy it is to write a feature request when I don't use the newest version... I'll try to update and see if it works. Sorry about that...
@theotherp Don't sorry.... In fact your issue just allow us to find a bug in the last release 3.2. Your example body().pre()
does not compile in the last version, because it does not allow pre()
after body()
. We will both fix that bug and also implement the disable indentation feature.
Thanks for your feedback.
@theotherp I have just released a new version with support to disable pretty print / indentation. Basically now we provide a new setIndented(boolean isIndented)
setter in HtmView
. Note that HtmlView
instances are immutable, so whenever you call setIndented
it returns a new HtmlView
object rather than changing the existing one.
Here in HtmlWithoutIndentation.java you can find some use cases of setIndented
usage.
Sorry for this late feature but I have been overwhelmed and I also included some other required fixes on this version.
By the way, I think you are not an HtmlFlow stargazer yet. Could you please give us a star?
Best regards,
Miguel
Will do.