Skip to content

Commit 00927c3

Browse files
committed
feat: replaceQuote, close #43
1 parent ccb7d23 commit 00927c3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,15 @@ function render (tree, options) {
4949

5050
var closingSingleTag = options.closingSingleTag
5151
var quoteAllAttributes = options.quoteAllAttributes
52-
if (typeof quoteAllAttributes === 'undefined') {
52+
if (quoteAllAttributes === undefined) {
5353
quoteAllAttributes = true
5454
}
5555

56+
var replaceQuote = options.replaceQuote
57+
if (replaceQuote === undefined) {
58+
replaceQuote = true
59+
}
60+
5661
return html(tree)
5762

5863
/** @private */
@@ -77,7 +82,12 @@ function render (tree, options) {
7782
for (var key in obj) {
7883
if (typeof obj[key] === 'string') {
7984
if (quoteAllAttributes || obj[key].match(ATTRIBUTE_QUOTES_REQUIRED)) {
80-
attr += ' ' + key + '="' + obj[key].replace(/"/g, '"') + '"'
85+
var attrValue = obj[key]
86+
87+
if (replaceQuote) {
88+
attrValue = obj[key].replace(/"/g, '"')
89+
}
90+
attr += ' ' + key + '="' + attrValue + '"'
8191
} else if (obj[key] === '') {
8292
attr += ' ' + key
8393
} else {

0 commit comments

Comments
 (0)