Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

去除HTML标签(只保留文本内容)

  • Loading branch information...
commit 092538823dfcdcf55447580ce55aee95da1f1b9e 1 parent 5741fa5
@leizongmin authored
Showing with 40 additions and 0 deletions.
  1. +19 −0 README.md
  2. +21 −0 example/strip_tag.js
View
19 README.md
@@ -288,6 +288,25 @@ image list:
img1, img2, img3, img4
```
+### 去除HTML标签(只保留文本内容)
+
+```JavaScript
+var source = '<strong>hello</strong><script>alert(/xss/);</script>end';
+var html = xss(source, {
+ whiteList: [], // 白名单为空,表示过滤所有标签
+ stripIgnoreTag: true, // 过滤所有非白名单标签的HTML
+ stripIgnoreTagBody: ['script'] // script标签较特殊,需要过滤标签中间的内容
+});
+
+console.log('text: %s', html);
+```
+
+运行结果:
+
+```
+text: helloend
+```
+
## 性能
View
21 example/strip_tag.js
@@ -0,0 +1,21 @@
+/**
+ * 应用实例:去除HTML标签(只保留文本内容)
+ *
+ * @author 老雷<leizongmin@gmail.com>
+ */
+
+var xss = require('../');
+
+var source = '<strong>hello</strong><script>alert(/xss/);</script>end';
+var html = xss(source, {
+ whiteList: [], // 白名单为空,表示过滤所有标签
+ stripIgnoreTag: true, // 过滤所有非白名单标签的HTML
+ stripIgnoreTagBody: ['script'] // script标签较特殊,需要过滤标签中间的内容
+});
+
+console.log('text: %s', html);
+
+/*
+运行结果:
+text: helloend
+*/
Please sign in to comment.
Something went wrong with that request. Please try again.