Skip to content
Browse files

Added single line comment support. Closes #25

  • Loading branch information...
1 parent 4d3d18b commit bc1d8f9c7581e50d5f99e3653fa71fc922edf5ca @tj tj committed
Showing with 32 additions and 0 deletions.
  1. +15 −0 Readme.md
  2. +17 −0 lib/jade.js
View
15 Readme.md
@@ -141,6 +141,21 @@ Actually want `#{}` for some reason? escape it!
now we have `<p>#{something}</p>`
+### Comments
+
+Single line comments currently look the same as JavaScript comments,
+aka "//" and must be placed on their own line:
+
+ // just some paragraphs
+ p foo
+ p bar
+
+would output
+
+ <!-- just some paragraphs -->
+ <p>foo</p>
+ <p>bar</p>
+
### Nesting
ul
View
17 lib/jade.js
@@ -205,6 +205,11 @@ Parser.prototype = {
}
}
+ // Comment
+ if (captures = /^\/\/([^\n]+)/.exec(this.input)) {
+ return token('comment');
+ }
+
// Tag
if (captures = /^(\w[:\w]*)/.exec(this.input)) {
return token('tag');
@@ -378,6 +383,7 @@ Parser.prototype = {
* | text
* | filter
* | doctype
+ * | comment
* | each block
* | code block?
* | expr newline
@@ -391,6 +397,8 @@ Parser.prototype = {
return this.parseDoctype();
case 'filter':
return this.parseFilter();
+ case 'comment':
+ return this.parseComment();
case 'text':
return "buf.push('" + interpolate(this.advance.val.replace(/'/g, "\\'")) + " ');";
case 'id':
@@ -423,6 +431,15 @@ Parser.prototype = {
},
/**
+ * comment
+ */
+
+ parseComment: function(){
+ var str = this.expect('comment').val;
+ return "buf.push('<!--" + str + " -->')";
+ },
+
+ /**
* doctype
*/

0 comments on commit bc1d8f9

Please sign in to comment.
Something went wrong with that request. Please try again.