Permalink
Browse files

Blank lines are much more permissible in Blade documents (fixes #81)

Added appropriate tests
  • Loading branch information...
bminer committed Aug 29, 2012
1 parent 00c8af7 commit c06babbec96d9a068feee60dddb5417d4fb2e928
Showing with 98 additions and 7 deletions.
  1. +3 −0 lib/compiler.js
  2. +10 −3 lib/parser/blade-grammer.pegjs
  3. +64 −4 lib/parser/index.js
  4. +4 −0 test/output/blank_lines.html
  5. +17 −0 test/templates/blank_lines.blade
View
@@ -538,6 +538,9 @@ Compiler.prototype._compileNode = function(node) {
this._compileNode(node.children[i]);
this._pushOff("return this;}, " + ns + ");");
break;
+ case 'blank_line':
+ //Ignore these lines
+ break;
default:
var e = new Error("Unknown node type: " + node.type);
e.line = node.line, e.column = node.col;
@@ -42,6 +42,10 @@ doctype "doctype" =
/
"!!!" whitespace? type:text_until_eol {return type;}
+blank_line "blank line" =
+ whitespace* & (newline)
+ {return {"type": "blank_line"};}
+
/************** Node rules, which also handles indentation **************/
//Note: each node contains line and col for enhanced error reporting (YAY!)
node =
@@ -90,6 +94,8 @@ node =
comment.line = line, comment.col = column;
return comment;
}
+ /
+ blank_line
/* Any node that might have children
Each parent node must contain the following properties:
@@ -124,7 +130,7 @@ parent_node_types =
code
child_node "child node" =
- newline child_indent:indents & {
+ newline+ child_indent:indents & {
return child_indent == currentParentNode._indent + 1;
} child:node
{return child;}
@@ -465,18 +471,19 @@ text_until_eol "some text before the end of the line" =
{return text.join("");}
//Will reset the `indent` global variable
+//Note: Only Linux and Windows line feeds are supported; Old Mac-style "\r" is not a newline
newline "newline" =
"\r" ? "\n" {indent = 0;}
//Will update `indent` global variable and return the # of indents
indents "indents" =
- data: "\t"+ & {
+ tabs: "\t"+ & {
//Predicate accepts \t token if it matches `indentToken`
if(indentToken == undefined)
indentToken = "\t";
return indentToken == "\t";
} {
- return indent = data.length; //Return the indent value
+ return indent = tabs.length; //Return the indent value
}
/
spaces: " "+ & {
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,4 @@
+<!DOCTYPE html><html><head></head><body><h1>Hello</h1><h3>This is a test
+of blank lines, which
+
+is super awesome</h3></body></html>
@@ -0,0 +1,17 @@
+!!! 5
+html
+
+ head
+
+ body
+ h1 Hello
+
+
+
+ h3 This is a test
+
+
+ |
+ of blank lines, which
+
+ is super awesome

0 comments on commit c06babb

Please sign in to comment.