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