jTidy漂亮打印自定义HTML标记 [英] jTidy pretty print custom HTML tag

查看:124
本文介绍了jTidy漂亮打印自定义HTML标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JTidy来漂亮地打印用户生成的格式正确的HTML:

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>

这是我的配置:

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指令.有办法解决这个问题吗?

But jTidy is removing my AngularJS datasource directive. Is there a way to workarround this issue?

我是从日志中得到的:

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开始尝试关闭自封闭标签.

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

推荐答案

我已经通过在JTidy源代码中进行一些更改来解决了这个问题

I have solved this problem by make some changes in JTidy source

https://github.com/nanndoj/jtidy

我添加了一个名为dropProprietaryTags

tidy.setDropProprietaryTags(false);

现在对我来说很好.默认情况下将其设置为true,因此,如果未将新属性设置为false

Now it's working fine for me. It's set to true by default so JTidy can work in the old way if the new property is not set to false

这篇关于jTidy漂亮打印自定义HTML标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆