homunculus
Advanced tools
Comparing version 0.4.2 to 0.4.3
{ | ||
"name": "homunculus", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"description": "A lexer&parser by Javascript", | ||
@@ -5,0 +5,0 @@ "maintainers": [ |
@@ -19,2 +19,4 @@ var Class = require('../util/Class'); | ||
this.state = false; //是否在<>状态中 | ||
this.style = false; | ||
this.script = false; | ||
this.last = null; | ||
@@ -115,2 +117,6 @@ }, | ||
} | ||
else if(this.style || this.script) { | ||
this.dealStSc(this.style ? 'style' : 'script', temp); | ||
this.style = this.script = false; | ||
} | ||
else { | ||
@@ -163,2 +169,9 @@ var idx = this.code.indexOf('<', this.index); | ||
} | ||
s = this.code.slice(idx + 1, idx + 7).toLowerCase(); | ||
if(/^style\b/i.test(s)) { | ||
this.style = true; | ||
} | ||
else if(/^script\b/i.test(s)) { | ||
this.script = true; | ||
} | ||
this.state = true; | ||
@@ -176,2 +189,18 @@ var token = new Token(Token.MARK, c1, c1); | ||
}, | ||
dealStSc: function(s, temp) { | ||
var reg = new RegExp('^/' + s + '\\b'); | ||
for(var i = this.index; i < this.code.length; i++) { | ||
if(this.code.charAt(i) == '<') { | ||
if(reg.test(this.code.slice(i + 1, i + 8))) { | ||
var s = this.code.slice(this.index, i); | ||
this.index = this.index2 = i; | ||
this.addText(s, temp); | ||
return; | ||
} | ||
} | ||
} | ||
var s = this.code.slice(this.index); | ||
this.index = this.index2 = this.code.length; | ||
this.addText(s, temp); | ||
}, | ||
addText: function(s, temp) { | ||
@@ -178,0 +207,0 @@ var token = new Token(Token.TEXT, s, s); |
@@ -0,0 +0,0 @@ var IParser = require('../Parser'); |
@@ -49,4 +49,2 @@ var IParser = require('../Parser'); | ||
this.length = 0; | ||
this.script = false; | ||
this.style = false; | ||
this.ignores = {}; | ||
@@ -92,5 +90,2 @@ this.hasMoveLine = false; | ||
var node = new Node(Node.MARK); | ||
if(this.script || this.style) { | ||
this.error(tagName + ' could not contain any mark.'); | ||
} | ||
node.add(this.match('<')); | ||
@@ -126,14 +121,5 @@ if(!this.look) { | ||
if(this.look.content() == '/>') { | ||
if(['script', 'style'].indexOf(tagName) > -1) { | ||
this.error(tagName + ' could not be single.'); | ||
} | ||
node.add(this.match('/>')); | ||
} | ||
else { | ||
if(tagName == 'script') { | ||
this.script = true; | ||
} | ||
else if(tagName == 'style') { | ||
this.style = true; | ||
} | ||
node.add(this.match('>')); | ||
@@ -155,3 +141,2 @@ if(!this.look) { | ||
node.add(this.match('>')); | ||
this.script = this.style = false; | ||
} | ||
@@ -158,0 +143,0 @@ } |
@@ -20,2 +20,4 @@ define(function(require, exports, module) { | ||
this.state = false; //是否在<>状态中 | ||
this.style = false; | ||
this.script = false; | ||
this.last = null; | ||
@@ -116,2 +118,6 @@ }, | ||
} | ||
else if(this.style || this.script) { | ||
this.dealStSc(this.style ? 'style' : 'script', temp); | ||
this.style = this.script = false; | ||
} | ||
else { | ||
@@ -164,2 +170,9 @@ var idx = this.code.indexOf('<', this.index); | ||
} | ||
s = this.code.slice(idx + 1, idx + 7).toLowerCase(); | ||
if(/^style\b/i.test(s)) { | ||
this.style = true; | ||
} | ||
else if(/^script\b/i.test(s)) { | ||
this.script = true; | ||
} | ||
this.state = true; | ||
@@ -177,2 +190,18 @@ var token = new Token(Token.MARK, c1, c1); | ||
}, | ||
dealStSc: function(s, temp) { | ||
var reg = new RegExp('^/' + s + '\\b'); | ||
for(var i = this.index; i < this.code.length; i++) { | ||
if(this.code.charAt(i) == '<') { | ||
if(reg.test(this.code.slice(i + 1, i + 8))) { | ||
var s = this.code.slice(this.index, i); | ||
this.index = this.index2 = i; | ||
this.addText(s, temp); | ||
return; | ||
} | ||
} | ||
} | ||
var s = this.code.slice(this.index); | ||
this.index = this.index2 = this.code.length; | ||
this.addText(s, temp); | ||
}, | ||
addText: function(s, temp) { | ||
@@ -179,0 +208,0 @@ var token = new Token(Token.TEXT, s, s); |
@@ -50,4 +50,2 @@ define(function(require, exports, module) { | ||
this.length = 0; | ||
this.script = false; | ||
this.style = false; | ||
this.ignores = {}; | ||
@@ -93,5 +91,2 @@ this.hasMoveLine = false; | ||
var node = new Node(Node.MARK); | ||
if(this.script || this.style) { | ||
this.error(tagName + ' could not contain any mark.'); | ||
} | ||
node.add(this.match('<')); | ||
@@ -127,14 +122,5 @@ if(!this.look) { | ||
if(this.look.content() == '/>') { | ||
if(['script', 'style'].indexOf(tagName) > -1) { | ||
this.error(tagName + ' could not be single.'); | ||
} | ||
node.add(this.match('/>')); | ||
} | ||
else { | ||
if(tagName == 'script') { | ||
this.script = true; | ||
} | ||
else if(tagName == 'style') { | ||
this.style = true; | ||
} | ||
node.add(this.match('>')); | ||
@@ -156,3 +142,2 @@ if(!this.look) { | ||
node.add(this.match('>')); | ||
this.script = this.style = false; | ||
} | ||
@@ -159,0 +144,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
516277
14871