Skip to content
This repository has been archived by the owner on Feb 24, 2018. It is now read-only.

Allow "dot" that is not attached to a tag #12

Merged
merged 2 commits into from
Aug 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ Parser.prototype = {
* | filter
* | comment
* | text
* | dot
* | each
* | code
* | yield
Expand Down Expand Up @@ -178,6 +179,8 @@ Parser.prototype = {
case 'text':
case 'start-jade-interpolation':
return this.parseText({block: true});
case 'dot':
return this.parseDot();
case 'each':
return this.parseEach();
case 'code':
Expand Down Expand Up @@ -215,6 +218,11 @@ Parser.prototype = {
}
},

parseDot: function() {
this.advance();
return this.parseTextBlock() || {type: 'Block', nodes: []};
},

/**
* Text
*/
Expand Down
154 changes: 137 additions & 17 deletions test/cases/text.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,76 @@
"filename": "text.tokens.json",
"textOnly": true
},
{
"type": "Block",
"nodes": []
},
{
"type": "Text",
"val": "",
"line": 20,
"filename": "text.tokens.json"
},
{
"type": "Block",
"nodes": [
{
"type": "Text",
"val": "foo",
"line": 22
},
{
"type": "Text",
"val": "\n",
"line": 23
},
{
"type": "Text",
"val": "",
"line": 23
},
{
"type": "Text",
"val": "\n",
"line": 24
},
{
"type": "Text",
"val": "",
"line": 24
},
{
"type": "Text",
"val": "\n",
"line": 25
},
{
"type": "Text",
"val": "bar",
"line": 25
},
{
"type": "Text",
"val": "\n",
"line": 26
},
{
"type": "Text",
"val": "baz",
"line": 26
},
{
"type": "Text",
"val": "\n",
"line": 27
},
{
"type": "Text",
"val": "",
"line": 27
}
]
},
{
"type": "Tag",
"name": "pre",
Expand All @@ -193,55 +263,55 @@
{
"type": "Text",
"val": "foo",
"line": 20,
"line": 29,
"filename": "text.tokens.json"
},
{
"type": "Text",
"val": "\n",
"line": 21,
"line": 30,
"filename": "text.tokens.json"
},
{
"type": "Text",
"val": " bar",
"line": 21,
"line": 30,
"filename": "text.tokens.json"
},
{
"type": "Text",
"val": "\n",
"line": 22,
"line": 31,
"filename": "text.tokens.json"
},
{
"type": "Text",
"val": " baz",
"line": 22,
"line": 31,
"filename": "text.tokens.json"
},
{
"type": "Text",
"val": "\n",
"line": 23,
"line": 32,
"filename": "text.tokens.json"
},
{
"type": "Text",
"val": ".",
"line": 23,
"line": 32,
"filename": "text.tokens.json"
}
],
"line": 20,
"line": 29,
"filename": "text.tokens.json"
}
]
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 19,
"line": 28,
"filename": "text.tokens.json"
},
{
Expand All @@ -254,46 +324,96 @@
{
"type": "Text",
"val": "foo",
"line": 26
"line": 35
},
{
"type": "Text",
"val": "\n",
"line": 27
"line": 36
},
{
"type": "Text",
"val": " bar",
"line": 27
"line": 36
},
{
"type": "Text",
"val": "\n",
"line": 28
"line": 37
},
{
"type": "Text",
"val": " baz",
"line": 28
"line": 37
},
{
"type": "Text",
"val": "\n",
"line": 29
"line": 38
},
{
"type": "Text",
"val": ".",
"line": 29
"line": 38
},
{
"type": "Text",
"val": "\n",
"line": 39
},
{
"type": "Text",
"val": "",
"line": 39
}
]
},
"attrs": [],
"attributeBlocks": [],
"isInline": false,
"line": 25,
"line": 34,
"filename": "text.tokens.json",
"textOnly": true
},
{
"type": "Block",
"nodes": [
{
"type": "Text",
"val": "foo",
"line": 41
},
{
"type": "Text",
"val": "\n",
"line": 42
},
{
"type": "Text",
"val": " bar",
"line": 42
},
{
"type": "Text",
"val": "\n",
"line": 43
},
{
"type": "Text",
"val": " baz",
"line": 43
},
{
"type": "Text",
"val": "\n",
"line": 44
},
{
"type": "Text",
"val": ".",
"line": 44
}
]
}
],
"line": 0,
Expand Down
67 changes: 49 additions & 18 deletions test/cases/text.tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,56 @@
{"type":"text","line":18,"val":""}
{"type":"end-pipeless-text","line":18}
{"type":"newline","line":19}
{"type":"tag","line":19,"val":"pre","selfClosing":false}
{"type":"indent","line":20,"val":2}
{"type":"text","line":20,"val":"foo"}
{"type":"dot","line":19}
{"type":"text","line":20,"val":""}
{"type":"newline","line":21}
{"type":"text","line":21,"val":" bar"}
{"type":"newline","line":22}
{"type":"text","line":22,"val":" baz"}
{"type":"dot","line":21}
{"type":"start-pipeless-text","line":21}
{"type":"text","line":22,"val":"foo"}
{"type":"newline","line":23}
{"type":"text","line":23,"val":"."}
{"type":"outdent","line":25}
{"type":"tag","line":25,"val":"pre","selfClosing":false}
{"type":"dot","line":25}
{"type":"start-pipeless-text","line":25}
{"type":"text","line":26,"val":"foo"}
{"type":"text","line":23,"val":""}
{"type":"newline","line":24}
{"type":"text","line":24,"val":""}
{"type":"newline","line":25}
{"type":"text","line":25,"val":"bar"}
{"type":"newline","line":26}
{"type":"text","line":26,"val":"baz"}
{"type":"newline","line":27}
{"type":"text","line":27,"val":" bar"}
{"type":"text","line":27,"val":""}
{"type":"end-pipeless-text","line":27}
{"type":"newline","line":28}
{"type":"text","line":28,"val":" baz"}
{"type":"newline","line":29}
{"type":"text","line":29,"val":"."}
{"type":"end-pipeless-text","line":29}
{"type":"eos","line":29}
{"type":"tag","line":28,"val":"pre","selfClosing":false}
{"type":"indent","line":29,"val":2}
{"type":"text","line":29,"val":"foo"}
{"type":"newline","line":30}
{"type":"text","line":30,"val":" bar"}
{"type":"newline","line":31}
{"type":"text","line":31,"val":" baz"}
{"type":"newline","line":32}
{"type":"text","line":32,"val":"."}
{"type":"outdent","line":34}
{"type":"tag","line":34,"val":"pre","selfClosing":false}
{"type":"dot","line":34}
{"type":"start-pipeless-text","line":34}
{"type":"text","line":35,"val":"foo"}
{"type":"newline","line":36}
{"type":"text","line":36,"val":" bar"}
{"type":"newline","line":37}
{"type":"text","line":37,"val":" baz"}
{"type":"newline","line":38}
{"type":"text","line":38,"val":"."}
{"type":"newline","line":39}
{"type":"text","line":39,"val":""}
{"type":"end-pipeless-text","line":39}
{"type":"newline","line":40}
{"type":"dot","line":40}
{"type":"start-pipeless-text","line":40}
{"type":"text","line":41,"val":"foo"}
{"type":"newline","line":42}
{"type":"text","line":42,"val":" bar"}
{"type":"newline","line":43}
{"type":"text","line":43,"val":" baz"}
{"type":"newline","line":44}
{"type":"text","line":44,"val":"."}
{"type":"end-pipeless-text","line":44}
{"type":"eos","line":44}