@@ -59,12 +59,17 @@ function render(tree, options) {
5959 replaceQuote = true ;
6060 }
6161
62+ let { quoteStyle} = options ;
63+ if ( quoteStyle === undefined ) {
64+ quoteStyle = 2 ;
65+ }
66+
6267 return html ( tree ) ;
6368
6469 /** @private */
6570 function isSingleTag ( tag ) {
6671 if ( singleRegExp . length > 0 ) {
67- return singleRegExp . some ( reg => reg . test ( tag ) )
72+ return singleRegExp . some ( reg => reg . test ( tag ) ) ;
6873 }
6974
7075 if ( ! singleTags . includes ( tag ) ) {
@@ -87,7 +92,7 @@ function render(tree, options) {
8792 attrValue = object [ key ] . replace ( / " / g, '"' ) ;
8893 }
8994
90- attr += ' ' + key + '="' + attrValue + '"' ;
95+ attr += makeAttr ( key , attrValue , quoteStyle ) ;
9196 } else if ( object [ key ] === '' ) {
9297 attr += ' ' + key ;
9398 } else {
@@ -96,7 +101,7 @@ function render(tree, options) {
96101 } else if ( object [ key ] === true ) {
97102 attr += ' ' + key ;
98103 } else if ( typeof object [ key ] === 'number' ) {
99- attr += ' ' + key + '="' + object [ key ] + '"' ;
104+ attr += makeAttr ( key , object [ key ] , quoteStyle ) ;
100105 }
101106 }
102107
@@ -112,6 +117,26 @@ function render(tree, options) {
112117 }
113118 }
114119
120+ /** @private */
121+ function makeAttr ( key , attrValue , quoteStyle = 1 ) {
122+ if ( quoteStyle === 1 ) {
123+ // Single Quote
124+ return ` ${ key } ='${ attrValue } '` ;
125+ }
126+
127+ if ( quoteStyle === 2 ) {
128+ // Double Quote
129+ return ` ${ key } ="${ attrValue } "` ;
130+ }
131+
132+ // Smart Quote
133+ if ( attrValue . includes ( '"' ) ) {
134+ return ` ${ key } ='${ attrValue } '` ;
135+ }
136+
137+ return ` ${ key } ="${ attrValue } "` ;
138+ }
139+
115140 /**
116141 * HTML Stringifier
117142 *
@@ -129,10 +154,10 @@ function render(tree, options) {
129154 traverse ( tree , node => {
130155 // Undefined, null, '', [], NaN
131156 if ( node === undefined ||
132- node === null ||
133- node === false ||
134- node . length === 0 ||
135- Number . isNaN ( node ) ) {
157+ node === null ||
158+ node === false ||
159+ node . length === 0 ||
160+ Number . isNaN ( node ) ) {
136161 return ;
137162 }
138163
0 commit comments