jTidy 漂亮打印自定义 HTML 标签
jTidy pretty print custom HTML tag
我正在尝试使用 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 正在删除我的 AngularJS datasource
指令。有办法解决这个问题吗?
我从日志中得到这个:
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>
我需要一个文本编辑器的格式化程序。我无法确定我们的用户将定义和使用哪些指令。它必须是适用于任何用户定义指令的通用解决方案
尝试在当前配置后设置以下 属性:
Properties props = new Properties();
props.setProperty("new-blocklevel-tags", "datasource");
tidy.getConfiguration().addProps(props);
见http://tidy.sourceforge.net/docs/quickref.html#new-blocklevel-tags。
我已经通过对 JTidy 源代码进行一些更改解决了这个问题
https://github.com/nanndoj/jtidy
我添加了一个名为 dropProprietaryTags
的新配置
tidy.setDropProprietaryTags(false);
现在它对我来说工作正常。它默认设置为 true
,因此如果新的 属性 未设置为 false
,JTidy 可以以旧方式工作
我正在尝试使用 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 正在删除我的 AngularJS datasource
指令。有办法解决这个问题吗?
我从日志中得到这个:
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>
我需要一个文本编辑器的格式化程序。我无法确定我们的用户将定义和使用哪些指令。它必须是适用于任何用户定义指令的通用解决方案
尝试在当前配置后设置以下 属性:
Properties props = new Properties();
props.setProperty("new-blocklevel-tags", "datasource");
tidy.getConfiguration().addProps(props);
见http://tidy.sourceforge.net/docs/quickref.html#new-blocklevel-tags。
我已经通过对 JTidy 源代码进行一些更改解决了这个问题
https://github.com/nanndoj/jtidy
我添加了一个名为 dropProprietaryTags
tidy.setDropProprietaryTags(false);
现在它对我来说工作正常。它默认设置为 true
,因此如果新的 属性 未设置为 false