OutputStream: Added support for quote_char option.
Can be either ', ", or null (null means choose the one with fewest occurrences in the string, like the previous behavior). Use case: Serializing data-bind attributes (Knockout.js) into doublequote delimited attributes while avoiding an excessive number of " entities.
This commit is contained in:
parent
7628bcac01
commit
690d65ec51
|
|
@ -60,7 +60,8 @@ function OutputStream(options) {
|
||||||
bracketize : false,
|
bracketize : false,
|
||||||
semicolons : true,
|
semicolons : true,
|
||||||
comments : false,
|
comments : false,
|
||||||
preserve_line : false
|
preserve_line : false,
|
||||||
|
quote_char : null
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
var indentation = 0;
|
var indentation = 0;
|
||||||
|
|
@ -95,7 +96,8 @@ function OutputStream(options) {
|
||||||
return s;
|
return s;
|
||||||
});
|
});
|
||||||
if (options.ascii_only) str = to_ascii(str);
|
if (options.ascii_only) str = to_ascii(str);
|
||||||
if (dq > sq) return "'" + str.replace(/\x27/g, "\\'") + "'";
|
var quote_char = options.quote_char || (dq > sq ? "'" : '"');
|
||||||
|
if (quote_char === "'") return "'" + str.replace(/\x27/g, "\\'") + "'";
|
||||||
else return '"' + str.replace(/\x22/g, '\\"') + '"';
|
else return '"' + str.replace(/\x22/g, '\\"') + '"';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user