| 83 |
doc = new JSDocument (this); |
doc = new JSDocument (this); |
| 84 |
doc.manakaiIsHTML = true; |
doc.manakaiIsHTML = true; |
| 85 |
} |
} |
| 86 |
|
this.nextToken = []; |
| 87 |
this.doc = doc; |
this.doc = doc; |
| 88 |
this.openElements = [doc]; |
this.openElements = [doc]; |
| 89 |
this.input = i; |
this.input = i; |
| 93 |
} // Parser |
} // Parser |
| 94 |
|
|
| 95 |
Parser.prototype.getNextToken = function () { |
Parser.prototype.getNextToken = function () { |
| 96 |
|
if (this.nextToken.length) { |
| 97 |
|
return this.nextToken.shift (); |
| 98 |
|
} |
| 99 |
|
|
| 100 |
var p = this; |
var p = this; |
| 101 |
var i = this.input; |
var i = this.input; |
| 102 |
if (this.parseMode == 'cdata') { |
if (this.parseMode == 'cdata') { |
| 151 |
i.s = i.s.replace (/^<\/([^>]+)(?:>|$)/, function (s, e) { |
i.s = i.s.replace (/^<\/([^>]+)(?:>|$)/, function (s, e) { |
| 152 |
if (p.insertionPoint < s.length || |
if (p.insertionPoint < s.length || |
| 153 |
(p.insertionPoint <= s.length && |
(p.insertionPoint <= s.length && |
| 154 |
s.substring (s.length - 1, 1) != '>')) { |
s.substring (s.length - 1, s.length) != '>')) { |
| 155 |
token = {type: 'abort'}; |
token = {type: 'abort'}; |
| 156 |
return s; |
return s; |
| 157 |
} |
} |
| 163 |
i.s = i.s.replace (/^<([^>]+)(?:>|$)/, function (s, e) { |
i.s = i.s.replace (/^<([^>]+)(?:>|$)/, function (s, e) { |
| 164 |
if (p.insertionPoint < s.length || |
if (p.insertionPoint < s.length || |
| 165 |
(p.insertionPoint <= s.length && |
(p.insertionPoint <= s.length && |
| 166 |
s.substring (s.length - 1, 1) != '>')) { |
s.substring (s.length - 1, s.length) != '>')) { |
| 167 |
token = {type: 'abort'}; |
token = {type: 'abort'}; |
| 168 |
return s; |
return s; |
| 169 |
} |
} |
| 226 |
var token = this.getNextToken (); |
var token = this.getNextToken (); |
| 227 |
log ('token: ' + token.type + ' "' + token.value + '"'); |
log ('token: ' + token.type + ' "' + token.value + '"'); |
| 228 |
|
|
| 229 |
|
if (this.cdataEndTagRequired) { |
| 230 |
|
// Generic CDATA parsing algorithm |
| 231 |
|
|
| 232 |
|
if (token.type != 'abort') { |
| 233 |
|
// 7. |
| 234 |
|
if (token.type == 'end-tag' && token.value == this.endTagName) { |
| 235 |
|
// 7.1. Ignores it. |
| 236 |
|
// |
| 237 |
|
} else { |
| 238 |
|
// 7.2. Parse error. |
| 239 |
|
log ('Parse error: no </' + this.endTagName + '>'); |
| 240 |
|
this.nextToken.unshift (token); |
| 241 |
|
} |
| 242 |
|
this.cdataEndTagRequired = false; |
| 243 |
|
continue; |
| 244 |
|
} |
| 245 |
|
} |
| 246 |
|
|
| 247 |
if (token.type == 'start-tag') { |
if (token.type == 'start-tag') { |
| 248 |
if (token.value == 'script') { |
if (token.value == 'script') { |
| 249 |
// 1. Create an element for the token in the HTML namespace. |
// 1. Create an element for the token in the HTML namespace. |
| 280 |
if (!(token.type == 'end-tag' && token.value == 'script')) { |
if (!(token.type == 'end-tag' && token.value == 'script')) { |
| 281 |
// 7.2. This is a parse error. |
// 7.2. This is a parse error. |
| 282 |
log ('Parse error: no </' + 'script>'); |
log ('Parse error: no </' + 'script>'); |
| 283 |
|
this.nextToken.unshift (token); |
| 284 |
|
|
| 285 |
// 7.3. Mark the script element as "already executed". |
// 7.3. Mark the script element as "already executed". |
| 286 |
el.manakaiAlreadyExecuted = true; |
el.manakaiAlreadyExecuted = true; |
| 372 |
// 6. Switched back to the PCDATA state. |
// 6. Switched back to the PCDATA state. |
| 373 |
this.parseMode = 'pcdata'; |
this.parseMode = 'pcdata'; |
| 374 |
|
|
| 375 |
|
if (token.type == 'abort') { |
| 376 |
|
this.cdataEndTagRequired = true; |
| 377 |
|
break; |
| 378 |
|
} |
| 379 |
|
|
| 380 |
// 7.1. If the next token is not an end tag token with ... |
// 7.1. If the next token is not an end tag token with ... |
| 381 |
if (!(token.type == 'end-tag' && |
if (!(token.type == 'end-tag' && |
| 382 |
token.value == this.endTagName)) { |
token.value == this.endTagName)) { |
| 383 |
// 7.2. This is a parse error. |
// 7.2. This is a parse error. |
| 384 |
log ('Parse error: no </' + this.endTagName + '>'); |
log ('Parse error: no </' + this.endTagName + '>'); |
| 385 |
|
this.nextToken.unshift (token); |
| 386 |
|
|
| 387 |
// 7.3. Mark the script element as "already executed". |
// 7.3. Mark the script element as "already executed". |
| 388 |
el.manakaiAlreadyExecuted = true; |
el.manakaiAlreadyExecuted = true; |