- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 Java 库 Tidy 来清理 html 代码。一些代码包含带有俄文字母的链接。例如
<a href="http://example.com/Русский">link with Russian letters</a>
我知道必须对“Русский”进行转义,但我从用户那里得到了这个 html。我的工作是将其转换为 XHTML。
我认为 tidy 试图转义非拉丁字母,但结果我得到了
<a href="http://example.com/%420%443%441%441%43A%438%439">link with Russian letters</a>
这不正确。正确的版本是
<a href="http://example.com/%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9">link with Russian letters</a>
Java代码是
private static Tidy getTidy() {
if (null == tidy) {
tidy = new Tidy();
tidy.setQuiet(true);
tidy.setShowErrors(0);
tidy.setShowWarnings(false);
tidy.setXHTML(true);
tidy.setOutputEncoding("UTF-8");
}
return tidy;
}
public static String sanitizeHtml(String html, URI pageUri) {
boolean escapeMedia = false;
String ret = "";
try {
Document doc = getTidy().parseDOM(new StringReader("<body>" + html + "</body>"), null);
// here I make some processing
// string output
ByteArrayOutputStream out = new ByteArrayOutputStream();
Node node = doc.getElementsByTagName("body").item(0);
getTidy().pprint(node, out);
ret = out.toString().trim();
}
catch (Exception e) {
ret = html;
e.printStackTrace();
}
return ret;
}
最佳答案
这是一种硬编码行为,可能是一个错误。当他们应该使用 UTF-8 时,他们使用 UTF-16 来转义 URL 中的非 ASCII 字符。参见 org/w3c/tidy/AttrCheckImpl.java
.
关于java - Tidy 断开与非拉丁字符的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2859984/
我对UDF pig 拉丁有问题。 我正在尝试实现一个系统,该系统必须验证本地存储的矩阵与hadoop存储库中存储的一组矩阵之间是否存在“映射”。 对于映射,我的意思是在hadoop中是否存在一个存储矩
数据库的排序规则用法是什么?好吧,对于 HTML UTF-8,我知道一点,比如显示其他语言类型。但是对于数据库呢?我正在使用 latin-1(默认),我的 friend 告诉我改用 UTF。当我问为什
我有以下带有架构的数据 (t0: chararray,t1: int,t2: int) (B,4,2) (A,2,3) (A,3,2) (B,2,2) (A,1,2) (B,1,2) 我想生成以下结果
我正在尝试构建 AOSP 拉丁 IME(源代码:https://android.googlesource.com/platform/packages/inputmethods/LatinIME/+/m
我正在实现过滤器功能。我使用以下方法定义字符串是否适合查询: someString.IndexOf(someSearch, StringComparison.OrdinalIgnoreCase) >=
我是一名优秀的程序员,十分优秀!