File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed
Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change 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" : {
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments