HTML 实体十六进制字符引用无效
HTML Entity Hex Character reference not working
我正在尝试转义和取消转义 html 个实体。
对于转义,我已经习惯了下面的代码,它工作正常。
function reformat(string) {
var entityMap = {
'&' : '&',
'<' : '<',
'>' : '>',
'"' : '"',
"'" : "'",
'/' : '/',
'`' : '`',
'=' : '=',
'■' : '■',
'▲' : '▲'
};
if (string) {
return String(string).replace(/[&<>"'`=■▲\/]/g,
function fromEntityMap(s) {
return entityMap[s];
});
}
};
对于转义,我尝试使用 JSOUP 解析器,
Jsoup.parse(html).text();
boolean strictMode = true;
html = org.jsoup.parser.Parser.unescapeEntities(html, strictMode);
HTMLUtils:org.springframework.web.util.HtmlUtils
html = HtmlUtils.htmlUnescape(html);
Uebescape:org.unbescape.html.HtmlEscape
html = HtmlEscape.unescapeHtml(html);
此外,我尝试过使用commons-lang和commons-text。尽管如此,我还是没有运气只对这两个字符进行转义。
'■' : '■',
'▲' : '▲',
注意:我使用的是十六进制字符引用。
我在类路径中遇到冲突,有两个不同版本的 JSOUP 1.6.0 和 JSOUP 1.11.3。我刚刚删除了 jsoup1.6.0,一切都开始工作了。
We dont have org.jsoup.parser.Parser.unescapeEntities(html, true) method in Jsoup-1.6.0 version.
我正在尝试转义和取消转义 html 个实体。 对于转义,我已经习惯了下面的代码,它工作正常。
function reformat(string) {
var entityMap = {
'&' : '&',
'<' : '<',
'>' : '>',
'"' : '"',
"'" : "'",
'/' : '/',
'`' : '`',
'=' : '=',
'■' : '■',
'▲' : '▲'
};
if (string) {
return String(string).replace(/[&<>"'`=■▲\/]/g,
function fromEntityMap(s) {
return entityMap[s];
});
}
};
对于转义,我尝试使用 JSOUP 解析器,
Jsoup.parse(html).text();
boolean strictMode = true;
html = org.jsoup.parser.Parser.unescapeEntities(html, strictMode);
HTMLUtils:org.springframework.web.util.HtmlUtils
html = HtmlUtils.htmlUnescape(html);
Uebescape:org.unbescape.html.HtmlEscape
html = HtmlEscape.unescapeHtml(html);
此外,我尝试过使用commons-lang和commons-text。尽管如此,我还是没有运气只对这两个字符进行转义。
'■' : '■',
'▲' : '▲',
注意:我使用的是十六进制字符引用。
我在类路径中遇到冲突,有两个不同版本的 JSOUP 1.6.0 和 JSOUP 1.11.3。我刚刚删除了 jsoup1.6.0,一切都开始工作了。
We dont have org.jsoup.parser.Parser.unescapeEntities(html, true) method in Jsoup-1.6.0 version.