Skip to content

Commit 6ace387

Browse files
author
mengshuang
committed
toHtml prop execlude
1 parent 1cd02de commit 6ace387

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html2obj",
3-
"version": "1.0.9",
3+
"version": "1.0.10",
44
"description": "pure js,html to obj,obj to html",
55
"main": "./src/html2obj.js",
66
"scripts": {

src/HtmlNode.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class HtmlNode {
2626
* @param {Array} remainAttrs 可以为空,表示保留所有,非空时,表示只保留这些属性
2727
* @returns
2828
*/
29-
toHtml(remainAttrs) {
29+
toHtml(includeAttrs, execludeAttrs) {
3030
if (this.tagName[0] == '#') {
3131
if (this.tagName != '#text') {
3232
return ''
@@ -35,7 +35,10 @@ class HtmlNode {
3535
}
3636
let html = `<${this.tagName}`
3737
for (const key in this.attrs) {
38-
if (remainAttrs && remainAttrs.length > 0 && remainAttrs.indexOf(key) == -1) {
38+
if (includeAttrs && includeAttrs.length > 0 && includeAttrs.indexOf(key) == -1) {
39+
continue
40+
}
41+
if (execludeAttrs && execludeAttrs.length > 0 && execludeAttrs.indexOf(key) > -1) {
3942
continue
4043
}
4144
let val = this.attrs[key]
@@ -47,7 +50,7 @@ class HtmlNode {
4750
}
4851
html += '>'
4952
for (let item of this.child) {
50-
html += item.toHtml(remainAttrs)
53+
html += item.toHtml(includeAttrs, execludeAttrs)
5154
}
5255
html += `</${this.tagName}>`
5356
return html

0 commit comments

Comments
 (0)