Skip to content

Commit

Permalink
Added explicit self-closing tag support. Closes pugjs#605
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed May 2, 2012
1 parent 2ce30df commit 9f37c44
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
14 changes: 14 additions & 0 deletions jade.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@
a Bar
a Baz

## Self-closing Tags

Some tags are flagged as self-closing by default, such
as `meta`, `link`, and so on. To explicitly self-close
a tag simply append the `/` character:

foo/
foo(bar='baz')/

Would yield:

<foo/>
<foo bar="baz"/>

## Attributes

Tag attributes look similar to HTML, however
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ Compiler.prototype = {
if (pp && !tag.isInline())
this.prettyIndent(0, true);

if (~selfClosing.indexOf(name) && !this.xml) {
if ((~selfClosing.indexOf(name) || tag.selfClosing) && !this.xml) {
this.buffer('<' + name);
this.visitAttributes(tag.attrs);
this.terse
Expand Down
8 changes: 7 additions & 1 deletion lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,13 @@ Parser.prototype = {
break out;
}
}


// self-closing
if ('/' == this.peek().val) {
this.advance();
tag.selfClosing = true;
}

return this.tag(tag);
},

Expand Down
6 changes: 6 additions & 0 deletions test/cases/tags.self-closing.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<body>
<foo></foo>
<foo bar="baz"></foo>
<foo/>
<foo bar="baz"/>
</body>
6 changes: 6 additions & 0 deletions test/cases/tags.self-closing.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

body
foo
foo(bar='baz')
foo/
foo(bar='baz')/

0 comments on commit 9f37c44

Please sign in to comment.