I'm trying to use JTidy to pretty print a well formed HTML generated by the user:
<div class="component-holder ng-binding ng-scope ui-draggable ui-draggable-handle" data-component="cronos-datasource" id="cronos-datasource-817277">
<datasource name="" entity="" key="" endpoint="" rows-per-page="">
<i class="cpn cpn-datasource"></i>
</datasource>
</div>
This is my config:
Tidy tidy = new Tidy();
tidy.setXHTML(true);
tidy.setIndentContent(true);
tidy.setPrintBodyOnly(true);
tidy.setTidyMark(false);
tidy.setWraplen(2000);
tidy.setDropProprietaryAttributes(false);
tidy.setDropEmptyParas(false);
tidy.setTrimEmptyElements(false);
But jTidy is removing my AngularJS datasource
directive. Is there a way to workarround this issue?
I'm getting this from the log:
line 1 column 191 - Error: <datasource> is not recognized!
line 1 column 191 - Warning: discarding unexpected <datasource>
Removing tidy.setXHTML(true)
or setting it to false and adding tidy.setXmlTags(true)
actually solve this issue and it start to consider user defined tags, but this is not a good solution because JTidy starts trying to close self enclosing tags.
<!-- this code -->
<img src="anythig.jpg"/>
<div id="anyid"></div>
<!-- will become -->
<img src="anythig.jpg">
<div id="anyid"></div>
</img>
I need a formatter for a text editor. I can't assure what directives our users will define and use. It must be a generic solution which works for any user defined directive
Try setting the following property after your current configuration:
Properties props = new Properties();
props.setProperty("new-blocklevel-tags", "datasource");
tidy.getConfiguration().addProps(props);
See http://tidy.sourceforge.net/docs/quickref.html#new-blocklevel-tags.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With