Skip to content

Commit

Permalink
Allow config to specify use of self closing tags
Browse files Browse the repository at this point in the history
Allow config to specify `useShortTags` (default true).

When `useShortTags` is true, empty elements are terminated with />

When `useShortTags` is false, empty elements are closed with a full closing tag
e.g. </path>
  • Loading branch information
bradbarrow committed Jul 6, 2015
1 parent a0616b0 commit bd64cde
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lib/svgo/js2svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ var defaults = {
regEntities: /[&'"<>]/g,
regValEntities: /[&"<>]/g,
encodeEntity: encodeEntity,
pretty: false
pretty: false,
useShortTags: true
};

var entities = {
Expand Down Expand Up @@ -228,13 +229,22 @@ JS2SVG.prototype.createElem = function(data) {

// empty element and short tag
if (data.isEmpty()) {

return this.createIndent() +
this.config.tagShortStart +
data.elem +
this.createAttrs(data) +
this.config.tagShortEnd;

if (this.config.useShortTags) {
return this.createIndent() +
this.config.tagShortStart +
data.elem +
this.createAttrs(data) +
this.config.tagShortEnd;
} else {
return this.createIndent() +
this.config.tagShortStart +
data.elem +
this.createAttrs(data) +
this.config.tagOpenEnd +
this.config.tagCloseStart +
data.elem +
this.config.tagCloseEnd;
}
// non-empty element
} else {
var tagOpenStart = this.config.tagOpenStart,
Expand Down

0 comments on commit bd64cde

Please sign in to comment.