1.0.1 • Published 1 year ago

html-escape-tool v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

安装

npm install html-escape-tool

导入

const htmlEs = require('html-escape-tool')

转义 HTML 字符

  • <&lt;
  • >&gt;
  • "&quot;
  • &&amp;

方法:htmlEscape(htmlStr)

const htmlStr = '<h1 class="main">我是HTML!<span>哈&nbsp;哈</span></h1>';
let str = htmlEs.htmlEscape(htmlStr);
// &lt;h1 class=&quot;main&quot;&gt;我是HTML!&lt;span&gt;哈&amp;nbsp;哈&lt;/span&gt;&lt;/h1&gt;

还原 HTML 字符

  • &lt;<
  • &gt;>
  • &quot;"
  • &amp;&

方法:htmlUnEscape(str)

const str = '&lt;h1 class=&quot;main&quot;&gt;我是HTML!&lt;span&gt;哈&amp;nbsp;哈&lt;/span&gt;&lt;/h1&gt;';
let htmlStr = htmlEs.htmlUnEscape(str);
// <h1 class="main">我是HTML!<span>哈&nbsp;哈</span></h1>

开源协议

ISC