代码之家  ›  专栏  ›  技术社区  ›  Steven

对由unescape处理的所有字符进行转义(不仅仅是&、<和>)

  •  -1
  • Steven  · 技术社区  · 7 年前

    html.escape()和.unescape()不是对称的。根据 the docs ,escape只转换&、<和>,而.unescape处理“所有命名和数字字符引用”。如何转义.unescape()unescapes的所有字符?

    当前行为:

    html.unescape('&deg;')
    '°'
    html.escape('°')
    '°'
    

    html.unescape('&deg;')
    '°'
    html.escape('°')
    '&deg;'
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   kshetline    7 年前

    您链接到的文档链接到此:

    html.entities.codepoint2name
    

    正如另一张海报所指出的,你可能并不真的想逃跑 一切 ,因为每个字符都有实体名,或者至少有数字转义。