Skip to content

Instantly share code, notes, and snippets.

@mcattx
Created November 2, 2017 12:43
Show Gist options
  • Save mcattx/4e98e9e0008fac4d7aae2527ec961b5f to your computer and use it in GitHub Desktop.
Save mcattx/4e98e9e0008fac4d7aae2527ec961b5f to your computer and use it in GitHub Desktop.
HTML 反转义
// 反转义
function toRegex(chars) {
var keys = Object.keys(chars).join('|');
var regex = new RegExp('(?=(' + keys + '))\\1', 'g');
return regex;
}
function unescape(str) {
var chars = {
'"': '"',
'"': '"',
''': '\'',
''': '\'',
'&': '&',
'&': '&',
'>': '>',
'>': '>',
'&lt;': '<',
'&#60;': '<'
}
var regex = toRegex(chars);
return str.replace(regex, function(m) {
return chars[m];
});
}
// test
var descContent = '&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; font-size: 16px; line-height: 26px; color: rgb(51, 51, 51); font-family: &amp;quot;Microsoft YaHei&amp;quot;, 微软雅黑, SimSun, 宋体; text-align: center;&quot;&gt;&lt;img src=&quot;http://sinastorage.com/storage.service.mix.sina.com.cn/6156be906bc36402aad40408e017a299.png&quot; title=&quot;uber.png&quot; style=&quot;margin: 0px; padding: 0px; border-width: initial; border-style: none; max-width: 100%;&quot;&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; font-size: 16px; line-height: 26px; color: rgb(51, 51, 51); font-family: &amp;quot;Microsoft YaHei&amp;quot;, 微软雅黑, SimSun, 宋体;&quot;&gt;&lt;span style=&quot;font-family: 楷体, 楷体_gb2312, simkai;&quot;&gt;  欢迎关注&ldquo;创事记&rdquo;的微信订阅号:sinachuangshiji&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; font-size: 16px; line-height: 26px; color: rgb(51, 51, 51); font-family: &amp;quot;Microsoft YaHei&amp;quot;, 微软雅黑, SimSun, 宋体;&quot;&gt;  文/大唐波斯将军&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; font-size: 16px; line-height: 26px; color: rgb(51, 51, 51); font-family: &amp;quot;Microsoft YaHei&amp;quot;, 微软雅黑, SimSun, 宋体;&quot;&gt;  最近,Uber广州总部被查一事在网上炒的沸沸扬扬,政府强硬的声明与广大网友的力挺形成了鲜明的对立。不管讨论有多么激烈,绝大多数讨论的参与者都基本同意这样三点共识:&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; font-size: 16px; line-height: 26px; color: rgb(51, 51, 51); font-family: &amp;quot;Microsoft YaHei&amp;quot;, 微软雅黑, SimSun, 宋体;&quot;&gt;  1、Uber的出现损害了出租车行业的整体利益。&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; font-size: 16px; line-height: 26px; color: rgb(51, 51, 51); font-family: &amp;quot;Microsoft YaHei&amp;quot;, 微软雅黑, SimSun, 宋体;&quot;&gt;  2、Uber的经营模式确实违反了我国的现行法律。&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; font-size: 16px; line-height: 26px; color: rgb(51, 51, 51); font-family: &amp;quot;Microsoft YaHei&amp;quot;, 微软雅黑, SimSun, 宋体;&quot;&gt;  3、对于乘客而言,Uber确实是一种方便高效的通勤方式。&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; font-size: 16px; line-height: 26px; color: rgb(51, 51, 51); font-family: &amp;quot;Microsoft YaHei&amp;quot;, 微软雅黑, SimSun, 宋体;&quot;&gt;  这样看来,争论似乎没有进行的必要,即便背后确有利益集团的黑手,广州市政府的行为也无可厚非。然而,争论的核心并不在于明晰法理上的对错或者平息利益的冲突,而在于政府是否应该包容Uber式的创新。这造成了一种尴尬,政府的行动与企业创新被人为地对立了起来。我认为这样是不妥的,&lt;strong&gt;Uber模式是一种典型的混合式破坏性创新,而破坏性创新的特点就是高风险高收益,被政府禁止本身也是风险的一种,Uber理应做好准备。&lt;/strong&gt;&lt;/p&gt;''
var rs = unescape(descContent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment