我正在尝试使用 JTidy 漂亮地打印用户生成的格式良好的 HTML:
<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>
这是我的配置:
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);
但是 jTidy 正在删除我的 AngularJSdatasource
指令。有没有办法解决这个问题?
我从日志中得到这个:
line 1 column 191 - Error: <datasource> is not recognized!
line 1 column 191 - Warning: discarding unexpected <datasource>
删除tidy.setXHTML(true)
或将其设置为 false 并添加tidy.setXmlTags(true)
实际上解决了这个问题,它开始考虑用户定义的标签,但这不是一个好的解决方案,因为 JTidy 开始尝试关闭自封闭标签。
<!-- this code -->
<img src="anythig.jpg"/>
<div id="anyid"></div>
<!-- will become -->
<img src="anythig.jpg">
<div id="anyid"></div>
</img>
我需要一个文本编辑器的格式化程序。我无法保证我们的用户将定义和使用哪些指令。它必须是适用于任何用户定义指令的通用解决方案