[英]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
,因此如果new属性未设置为false
,JTidy可以以旧方式工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.