javascript - HTML 实体十六进制字符引用不起作用

标签 javascript java html-entities

我正在尝试转义和取消转义 html 实体。 对于转义,我已经使用了下面的代码,它工作得很好。

function reformat(string) {
var entityMap = {
    '&' : '&',
    '<' : '&lt;',
    '>' : '&gt;',
    '"' : '&quot;',
    "'" : "'",
    '/' : '/',
    '`' : '&#x60;',
    '=' : '=',
    '■' : '&#x25a0;',
    '▲' : '&#x25b2;'
};

if (string) {
    return String(string).replace(/[&<>"'`=■▲\/]/g,
            function fromEntityMap(s) {
                return entityMap[s];
            });
}

};

对于 Unescaping,我尝试过使用 JSOUP Parser,

        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。尽管如此,我还是没有运气只转义这两个字符。

     '■' : '&#x25a0;',
    '▲' : '&#x25b2;', 

注意:我使用的是十六进制字符引用。

最佳答案

我在类路径中遇到冲突,有两个不同版本的 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.

关于javascript - HTML 实体十六进制字符引用不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53636588/

相关文章:

java - 替换字符串内的子字符串不起作用? Java XML

html - 为什么&lt;textarea&gt;显示<>而不是<>?

php - 使用 htmlspecialchars 和 htmlentities 转换特殊字符

java - 如何从 JSoup 'Document' 中删除不间断空格?

javascript - iOS WebKit - 判断一个WebView是否已经完全加载JS内容

javascript - 咕噜声和angularJS : change peplacement on prod server

java - 如何生成 JSR-172 stub

java - GUI 从另一个类访问 JSlider

javascript - 通过 JAVASCRIPT 添加 iframe

javascript - Firestore 推送通知 "time out"错误通知并不总是被发送