Java – jtidy beautiful print custom HTML tags
I try to use jtidy to print well formed HTML generated by users:
<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 configuration:
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 deleting my angularjs data source instruction Is there any way to solve this problem?
I got this from the log:
line 1 column 191 - Error: <datasource> is not recognized! line 1 column 191 - Warning: discarding unexpected <datasource>
Delete tidy Setxhtml (true) or set it to false and add tidy Setxmltags (true) actually solves this problem. It starts to consider user-defined tags, but it is not a good solution because jtidy starts trying to turn off self encapsulating 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 formatted text editor I can't guarantee which instructions our users will define and use It must be a generic solution that applies to any user-defined instruction
Solution
Try to set the following properties after the 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.