| 1 |
<!DOCTYPE HTML> |
<!DOCTYPE HTML> |
| 2 |
<html lang=en> |
<html lang=en> |
| 3 |
<head> |
<head> |
| 4 |
<title>Demo of HTML5 Parsing Algorithm with Scripting Enabled</title> |
<title>Live Scripting HTML Parser</title> |
| 5 |
<style> |
<style> |
| 6 |
|
h1, h2 { |
| 7 |
|
margin: 0; |
| 8 |
|
font-size: 100%; |
| 9 |
|
} |
| 10 |
|
p, pre { |
| 11 |
|
margin: 0; |
| 12 |
|
} |
| 13 |
textarea { |
textarea { |
| 14 |
display: block; |
width: 100%; |
| 15 |
width: 80%; |
-width: 99%; |
| 16 |
margin-left: auto; |
height: 10em; |
|
margin-right: auto; |
|
|
min-height: 20em; |
|
| 17 |
} |
} |
| 18 |
output { |
output { |
| 19 |
display: block; |
display: block; |
| 23 |
} |
} |
| 24 |
</style> |
</style> |
| 25 |
<script> |
<script> |
| 26 |
|
var delayedUpdater = 0; |
| 27 |
|
|
| 28 |
function update () { |
function update () { |
| 29 |
document.logElement.textContent = ''; |
if (delayedUpdater) { |
| 30 |
var p = new Parser (new InputStream (document.sourceElement.value)); |
clearTimeout (delayedUpdater); |
| 31 |
var doc = p.doc; |
delayedUpdater = 0; |
| 32 |
p.parse (); |
} |
| 33 |
log (dumpTree (doc, '')); |
delayedUpdater = setTimeout (update2, 100); |
| 34 |
} // update |
} // update |
| 35 |
|
|
| 36 |
|
function update2 () { |
| 37 |
|
var v = document.sourceElement.value; |
| 38 |
|
if (v != document.previousSourceText) { |
| 39 |
|
document.previousSourceText = v; |
| 40 |
|
document.links['permalink'].href |
| 41 |
|
= location.pathname + '?s=' + encodeURIComponent (v); |
| 42 |
|
document.links['ldvlink'].href |
| 43 |
|
= 'http://software.hixie.ch/utilities/js/live-dom-viewer/?' |
| 44 |
|
+ encodeURIComponent (v); |
| 45 |
|
|
| 46 |
|
document.logElement.textContent = ''; |
| 47 |
|
var p = new Parser (new InputStream (v)); |
| 48 |
|
var doc = p.doc; |
| 49 |
|
p.parse (); |
| 50 |
|
|
| 51 |
|
log (dumpTree (doc, '')); |
| 52 |
|
|
| 53 |
|
if (p.hasAsyncScript) { |
| 54 |
|
log ('Some script codes are executed asynchronously; it means that the document might be rendered in different ways depending on the network condition and other factors'); |
| 55 |
|
} |
| 56 |
|
} |
| 57 |
|
} // update2 |
| 58 |
|
|
| 59 |
|
var logIndentLevel = 0; |
| 60 |
function log (s) { |
function log (s) { |
| 61 |
|
for (var i = 0; i < logIndentLevel; i++) { |
| 62 |
|
s = ' ' + s; |
| 63 |
|
} |
| 64 |
document.logElement.appendChild (document.createTextNode (s + "\n")); |
document.logElement.appendChild (document.createTextNode (s + "\n")); |
| 65 |
} // log |
} // log |
| 66 |
|
|
| 76 |
} |
} |
| 77 |
this.doc = doc; |
this.doc = doc; |
| 78 |
this.openElements = [doc]; |
this.openElements = [doc]; |
| 79 |
this.in = i; |
this.input = i; |
| 80 |
this.scriptsExecutedAfterParsing = []; |
this.scriptsExecutedAfterParsing = []; |
| 81 |
|
this.scriptsExecutedSoon = []; |
| 82 |
} // Parser |
} // Parser |
| 83 |
|
|
| 84 |
Parser.prototype.getNextToken = function () { |
Parser.prototype.getNextToken = function () { |
| 85 |
var p = this; |
var p = this; |
| 86 |
var i = this.in; |
var i = this.input; |
| 87 |
if (this.parseMode == 'script') { |
if (this.parseMode == 'script') { |
| 88 |
var token; |
var token; |
| 89 |
if (p.insertionPoint <= 0) { |
if (p.insertionPoint <= 0) { |
| 156 |
tagName = v.toLowerCase (); |
tagName = v.toLowerCase (); |
| 157 |
return ''; |
return ''; |
| 158 |
}); |
}); |
| 159 |
e = e.replace (/^\s*(\S+)\s*(?:=\s*"([^"]*)"|'([^']*)'|([^"']+))?/, |
while (true) { |
| 160 |
function (x, attrName, attrValue1, attrValue2, attrValue3) { |
var m = false; |
| 161 |
attrs[attrName] = attrValue1 || attrValue2 || attrValue3; |
e = e.replace (/^\s*([^\s=]+)\s*(?:=\s*(?:"([^"]*)"|'([^']*)'|([^"'\s]*)))?/, |
| 162 |
return ''; |
function (x, attrName, attrValue1, attrValue2, attrValue3) { |
| 163 |
}); |
v = attrValue1 || attrValue2 || attrValue3; |
| 164 |
|
v = v.replace (/"/g, '"').replace (/'/g, "'") |
| 165 |
|
.replace (/&/g, '&'); |
| 166 |
|
attrs[attrName.toLowerCase ()] = v; |
| 167 |
|
m = true; |
| 168 |
|
return ''; |
| 169 |
|
}); |
| 170 |
|
if (!m) break; |
| 171 |
|
} |
| 172 |
|
if (e.length) { |
| 173 |
|
log ('Broken start tag: "' + e + '"'); |
| 174 |
|
} |
| 175 |
token = {type: 'start-tag', value: tagName, attrs: attrs}; |
token = {type: 'start-tag', value: tagName, attrs: attrs}; |
| 176 |
p.insertionPoint -= s.length; |
p.insertionPoint -= s.length; |
| 177 |
return ''; |
return ''; |
| 202 |
} // getNextToken |
} // getNextToken |
| 203 |
|
|
| 204 |
Parser.prototype.parse = function () { |
Parser.prototype.parse = function () { |
| 205 |
log ('start parsing'); |
logIndentLevel++; |
| 206 |
|
log ('parse: start'); |
| 207 |
|
|
| 208 |
while (true) { |
while (true) { |
| 209 |
var token = this.getNextToken (); |
var token = this.getNextToken (); |
| 271 |
this.openElements[this.openElements.length - 1].appendChild (el); |
this.openElements[this.openElements.length - 1].appendChild (el); |
| 272 |
|
|
| 273 |
// 11. Let the insertion point have the value of the old ... |
// 11. Let the insertion point have the value of the old ... |
| 274 |
|
|
| 275 |
oldInsertionPoint += this.insertionPoint; |
oldInsertionPoint += this.insertionPoint; |
| 276 |
this.setInsertionPoint (oldInsertionPoint); |
this.setInsertionPoint (oldInsertionPoint); |
| 277 |
|
|
| 278 |
// 12. If there is a script that will execute as soon as ... |
// 12. If there is a script that will execute as soon as ... |
| 279 |
|
while (this.scriptExecutedWhenParserResumes) { |
| 280 |
|
// 12.1. If the tree construction stage is being called reentrantly |
| 281 |
|
if (this.reentrant) { |
| 282 |
|
log ('parse: abort (reentrance)'); |
| 283 |
|
logIndentLevel--; |
| 284 |
|
return; |
| 285 |
|
|
| 286 |
|
// 12.2. Otherwise |
| 287 |
|
} else { |
| 288 |
|
// 1. |
| 289 |
|
var script = this.scriptExecutedWhenParserResumes; |
| 290 |
|
this.scriptExecutedWhenParserResumes = null; |
| 291 |
|
|
| 292 |
|
// 2. Pause until the script has completed loading. |
| 293 |
|
// |
| 294 |
|
|
| 295 |
|
// 3. Let the insertion point to just before the next input char. |
| 296 |
|
this.setInsertionPoint (0); |
| 297 |
|
|
| 298 |
|
// 4. Execute the script. |
| 299 |
|
executeScript (this.doc, script); |
| 300 |
|
|
| 301 |
|
// 5. Let the insertion point be undefined again. |
| 302 |
|
this.setInsertionPoint (undefined); |
| 303 |
|
|
| 304 |
|
// 6. If there is once again a script that will execute ... |
| 305 |
|
// |
| 306 |
|
} |
| 307 |
|
} |
| 308 |
} else { |
} else { |
| 309 |
var el = new JSElement (this.doc, token.value); |
var el = new JSElement (this.doc, token.value); |
| 310 |
this.openElements[this.openElements.length - 1].appendChild (el); |
this.openElements[this.openElements.length - 1].appendChild (el); |
| 324 |
break; |
break; |
| 325 |
} else if (token.type == 'abort') { |
} else if (token.type == 'abort') { |
| 326 |
log ('parse: abort'); |
log ('parse: abort'); |
| 327 |
|
logIndentLevel--; |
| 328 |
return; |
return; |
| 329 |
} |
} |
| 330 |
} |
} |
| 335 |
|
|
| 336 |
// "When a script completes loading" rules start applying. |
// "When a script completes loading" rules start applying. |
| 337 |
|
|
| 338 |
// TODO: Handles "list of scripts that will execute as soon as possible" |
// List of scripts that will execute as soon as possible |
| 339 |
// and "list of scripts that will execute asynchronously" |
for (var i = 0; i < this.scriptsExecutedSoon.length; i++) { |
| 340 |
|
var e = this.scriptsExecutedSoon[i]; |
| 341 |
|
|
| 342 |
|
// If it has completed loading |
| 343 |
|
log ('Execute an external script not inserted by parser...'); |
| 344 |
|
executeScript (this.doc, e); |
| 345 |
|
|
| 346 |
|
// NOTE: It MAY be executed before the end of the parsing, according |
| 347 |
|
// to the spec. |
| 348 |
|
this.hasAsyncScript = true; |
| 349 |
|
} |
| 350 |
|
|
| 351 |
|
// TODO: Handles |
| 352 |
|
// "list of scripts that will execute asynchronously" |
| 353 |
|
|
| 354 |
// Handle "list of scripts that will execute when the document has finished |
// Handle "list of scripts that will execute when the document has finished |
| 355 |
// parsing". |
// parsing". |
| 372 |
// "delays tha load event" things has completed: |
// "delays tha load event" things has completed: |
| 373 |
// readyState = 'complete' |
// readyState = 'complete' |
| 374 |
log ('load event fired'); |
log ('load event fired'); |
| 375 |
|
|
| 376 |
|
logIndentLevel--; |
| 377 |
} // parse |
} // parse |
| 378 |
|
|
| 379 |
Parser.prototype.setInsertionPoint = function (ip) { |
Parser.prototype.setInsertionPoint = function (ip) { |
| 380 |
if (ip == undefined || ip == null || isNaN (ip)) { |
if (ip == undefined || ip == null || isNaN (ip)) { |
| 381 |
log ('insertion point: set to undefined'); |
log ('insertion point: set to undefined'); |
| 382 |
this.insertionPoint = undefined; |
this.insertionPoint = undefined; |
| 383 |
} else if (ip == this.in.s.length) { |
} else if (ip == this.input.s.length) { |
| 384 |
log ('insertion point: end of file'); |
log ('insertion point: end of file'); |
| 385 |
this.insertionPoint = ip; |
this.insertionPoint = ip; |
| 386 |
} else { |
} else { |
| 387 |
log ('insertion point: set to ' + ip + |
log ('insertion point: set to ' + ip + |
| 388 |
' (before "' + this.in.s.substring (0, 10) + '")'); |
' (before "' + this.input.s.substring (0, 10) + '")'); |
| 389 |
this.insertionPoint = ip; |
this.insertionPoint = ip; |
| 390 |
} |
} |
| 391 |
}; // setInsertionPoint |
}; // setInsertionPoint |
| 407 |
e.parentNode = this; |
e.parentNode = this; |
| 408 |
|
|
| 409 |
if (e.localName == 'script') { |
if (e.localName == 'script') { |
| 410 |
|
logIndentLevel++; |
| 411 |
log ('Running a script: start'); |
log ('Running a script: start'); |
| 412 |
|
|
| 413 |
var doc = this.ownerDocument || this; |
var doc = this.ownerDocument || this; |
| 426 |
if (e.manakaiAlreadyExecuted) { |
if (e.manakaiAlreadyExecuted) { |
| 427 |
// 2.5. Abort these steps at this point. |
// 2.5. Abort these steps at this point. |
| 428 |
log ('Running a script: aborted'); |
log ('Running a script: aborted'); |
| 429 |
|
logIndentLevel--; |
| 430 |
return e; |
return e; |
| 431 |
} |
} |
| 432 |
|
|
| 449 |
/* && list of scripts that will execute asynchronously is not empty */) { |
/* && list of scripts that will execute asynchronously is not empty */) { |
| 450 |
// TODO |
// TODO |
| 451 |
} else if (e.src != null && e.manakaiParserInserted) { |
} else if (e.src != null && e.manakaiParserInserted) { |
| 452 |
// TODO |
if (p.scriptExecutedWhenParserResumes) { |
| 453 |
|
log ('Error: There is a script that will execute as soon as the parser resumes.'); |
| 454 |
|
} |
| 455 |
|
p.scriptExecutedWhenParserResumes = e; |
| 456 |
|
log ('Running a script: aborted (src parser-inserted)'); |
| 457 |
} else if (e.src != null) { |
} else if (e.src != null) { |
| 458 |
// TODO |
p.scriptsExecutedSoon.push (e); |
| 459 |
|
log ('Running a script: aborted (src)'); |
| 460 |
} else { |
} else { |
| 461 |
executeScript (doc, e); // even if other scripts are already executing. |
executeScript (doc, e); // even if other scripts are already executing. |
| 462 |
} |
} |
| 463 |
|
|
| 464 |
log ('Running a script: end'); |
log ('Running a script: end'); |
| 465 |
|
logIndentLevel--; |
| 466 |
} |
} |
| 467 |
|
|
| 468 |
return e; |
return e; |
| 471 |
function executeScript (doc, e) { |
function executeScript (doc, e) { |
| 472 |
log ('executing a script block: start'); |
log ('executing a script block: start'); |
| 473 |
|
|
| 474 |
// If the load resulted in an error, then ... firing an error event ... |
var s; |
| 475 |
|
if (e.src != null) { |
| 476 |
|
s = getExternalScript (e.src); |
| 477 |
|
|
| 478 |
|
// If the load resulted in an error, then ... firing an error event ... |
| 479 |
|
if (s == null) { |
| 480 |
|
log ('error event fired at the script element'); |
| 481 |
|
return; |
| 482 |
|
} |
| 483 |
|
|
| 484 |
|
log ('External script loaded: "' + s + '"'); |
| 485 |
|
} else { |
| 486 |
|
s = e.text; |
| 487 |
|
} |
| 488 |
|
|
| 489 |
// If the load was successful |
// If the load was successful |
| 490 |
log ('load event fired at the script element'); |
log ('load event fired at the script element'); |
| 493 |
// Scripting is enabled, Document.designMode is disabled, |
// Scripting is enabled, Document.designMode is disabled, |
| 494 |
// Document is the active document in its browsing context |
// Document is the active document in its browsing context |
| 495 |
|
|
|
var s; |
|
|
if (e.src != null) { |
|
|
// TODO: from external file |
|
|
} else { |
|
|
s = e.text; |
|
|
} |
|
|
|
|
| 496 |
parseAndRunScript (doc, s); |
parseAndRunScript (doc, s); |
| 497 |
} |
} |
| 498 |
|
|
| 499 |
log ('executing a script block: end'); |
log ('executing a script block: end'); |
| 500 |
} // executeScript |
} // executeScript |
| 501 |
|
|
| 502 |
|
function getExternalScript (uri) { |
| 503 |
|
if (uri.match (/^javascript:/i)) { |
| 504 |
|
var m; |
| 505 |
|
if (m = uri.match (/^javascript:\s*(?:'([^']*)'|"([^"]+)")\s*$/i)) { |
| 506 |
|
if (m[1]) { |
| 507 |
|
return m[1].replace (/\\u([0-9A-F]{4})/g, function (s, v) { |
| 508 |
|
return String.fromCharCode (parseInt ('0x' + v)); |
| 509 |
|
}); |
| 510 |
|
} else if (m[2]) { |
| 511 |
|
return m[2].replace (/\\u([0-9A-F]{4})/g, function (s, v) { |
| 512 |
|
return String.fromCharCode (parseInt ('0x' + v)); |
| 513 |
|
}); |
| 514 |
|
} else { |
| 515 |
|
return null; |
| 516 |
|
} |
| 517 |
|
} else { |
| 518 |
|
log ('Complex javascript: URI is not supported: <' + uri + '>'); |
| 519 |
|
return null; |
| 520 |
|
} |
| 521 |
|
} else { |
| 522 |
|
log ('URI scheme not supported: <' + uri + '>'); |
| 523 |
|
return null; |
| 524 |
|
} |
| 525 |
|
} // getExternalScript |
| 526 |
|
|
| 527 |
function parseAndRunScript (doc, s) { |
function parseAndRunScript (doc, s) { |
| 528 |
while (true) { |
while (true) { |
| 529 |
var matched = false; |
var matched = false; |
| 537 |
doc.write.apply (doc, args); |
doc.write.apply (doc, args); |
| 538 |
return ''; |
return ''; |
| 539 |
}); |
}); |
| 540 |
|
s = s.replace (/^\s*var\s+s\s*=\s*document\.createElement\s*\(\s*['"]script['"]\s*\)\s*;\s*s\.src\s*=\s*(?:'(javascript:[^']*)'|"(javascript:[^"]*)")\s*;\s*document\.documentElement\.appendChild\s*\(\s*s\s*\)\s*;\s*/, |
| 541 |
|
function (s, t, u) { |
| 542 |
|
matched = true; |
| 543 |
|
var args = [t ? t : u]; |
| 544 |
|
doc._insertExternalScript.apply (doc, args); |
| 545 |
|
return ''; |
| 546 |
|
}); |
| 547 |
if (s == '') break; |
if (s == '') break; |
| 548 |
if (!matched) { |
if (!matched) { |
| 549 |
log ('Script parse error: "' + s + '"'); |
log ('Script parse error: "' + s + '"'); |
| 579 |
// Step 3. |
// Step 3. |
| 580 |
if (this._parser && |
if (this._parser && |
| 581 |
!this._parser.scriptCreated && |
!this._parser.scriptCreated && |
| 582 |
this._parser.in.insertionPoint != undefined) { |
this._parser.input.insertionPoint != undefined) { |
| 583 |
log ('document.open () in parsing mode is ignored'); |
log ('document.open () in parsing mode is ignored'); |
| 584 |
return this; |
return this; |
| 585 |
} |
} |
| 613 |
} |
} |
| 614 |
|
|
| 615 |
// Step 11. |
// Step 11. |
| 616 |
this._parser.setInsertionPoint (this._parser.in.s.length); |
this._parser.setInsertionPoint (this._parser.input.s.length); |
| 617 |
|
|
| 618 |
// Step 12. |
// Step 12. |
| 619 |
return this; |
return this; |
| 620 |
}; // document.open |
}; // document.open |
| 621 |
|
|
| 622 |
JSDocument.prototype.write = function () { |
JSDocument.prototype.write = function () { |
| 623 |
|
logIndentLevel++; |
| 624 |
|
|
| 625 |
var p = this._parser; |
var p = this._parser; |
| 626 |
|
|
| 627 |
// 1. If the insertion point is undefined, the open() method must be ... |
// 1. If the insertion point is undefined, the open() method must be ... |
| 633 |
// 2. ... inserted into the input stream just before the insertion point. |
// 2. ... inserted into the input stream just before the insertion point. |
| 634 |
var s = Array.join (arguments, ''); |
var s = Array.join (arguments, ''); |
| 635 |
log ('document.write: insert "' + s + '"' + |
log ('document.write: insert "' + s + '"' + |
| 636 |
' before "' + p.in.s.substring (p.insertionPoint, p.insertionPoint + 10) + '"'); |
' before "' + |
| 637 |
p.in.s = p.in.s.substring (0, p.insertionPoint) + s |
p.input.s.substring (p.insertionPoint, p.insertionPoint + 10) + '"'); |
| 638 |
+ p.in.s.substring (p.insertionPoint, p.in.s.length); |
p.input.s = p.input.s.substring (0, p.insertionPoint) + s |
| 639 |
|
+ p.input.s.substring (p.insertionPoint, p.input.s.length); |
| 640 |
p.insertionPoint += s.length; |
p.insertionPoint += s.length; |
| 641 |
|
|
| 642 |
// 3. If there is a script that will execute as soon as the parser resumes |
// 3. If there is a script that will execute as soon as the parser resumes |
| 643 |
// TODO |
if (p.scriptExecutedAfterParserResumes) { |
| 644 |
|
log ('document.write: processed later (there is an unprocessed <script src>)'); |
| 645 |
|
logIndentLevel--; |
| 646 |
|
return; |
| 647 |
|
} |
| 648 |
|
|
| 649 |
// 4. Process the characters that were inserted, ... |
// 4. Process the characters that were inserted, ... |
| 650 |
|
var originalReentrant = p.reentrant; |
| 651 |
|
p.reentrant = true; |
| 652 |
p.parse (); |
p.parse (); |
| 653 |
|
p.reentrant = originalReentrant; |
| 654 |
|
// TODO: "Abort the processing of any nested invokations of the tokeniser, |
| 655 |
|
// yielding control back to the caller." (<script> parsing). Do we need |
| 656 |
|
// to do something here? |
| 657 |
|
|
| 658 |
// 5. Return |
// 5. Return |
| 659 |
log ('document.write: return'); |
log ('document.write: return'); |
| 660 |
|
|
| 661 |
|
logIndentLevel--; |
| 662 |
return; |
return; |
| 663 |
}; // document.write |
}; // document.write |
| 664 |
|
|
| 665 |
|
JSDocument.prototype._insertExternalScript = function (uri) { |
| 666 |
|
var s = new JSElement (this, 'script'); |
| 667 |
|
s.src = uri; |
| 668 |
|
this.documentElement.appendChild (s); |
| 669 |
|
}; // _insertExternalScript |
| 670 |
|
|
| 671 |
|
JSDocument.prototype.__defineGetter__ ('documentElement', function () { |
| 672 |
|
var cn = this.childNodes; |
| 673 |
|
for (var i = 0; i < cn.length; i++) { |
| 674 |
|
if (cn[i] instanceof JSElement) { |
| 675 |
|
return cn[i] |
| 676 |
|
} |
| 677 |
|
} |
| 678 |
|
return null; |
| 679 |
|
}); |
| 680 |
|
|
| 681 |
JSElement.prototype.__defineGetter__ ('text', function () { |
JSElement.prototype.__defineGetter__ ('text', function () { |
| 682 |
var r = ''; |
var r = ''; |
| 683 |
for (var i = 0; i < this.childNodes.length; i++) { |
for (var i = 0; i < this.childNodes.length; i++) { |
| 696 |
r += '| ' + indent + node.localName + '\n'; |
r += '| ' + indent + node.localName + '\n'; |
| 697 |
if (node.async) r += '| ' + indent + ' async=""\n'; |
if (node.async) r += '| ' + indent + ' async=""\n'; |
| 698 |
if (node.defer) r += '| ' + indent + ' defer=""\n'; |
if (node.defer) r += '| ' + indent + ' defer=""\n'; |
| 699 |
if (node.src) r += '| ' + indent + ' src="' + node.src + '"\n'; |
if (node.src != null) { |
| 700 |
|
r += '| ' + indent + ' src="' + node.src + '"\n'; |
| 701 |
|
} |
| 702 |
r += dumpTree (node, indent + ' '); |
r += dumpTree (node, indent + ' '); |
| 703 |
} else if (node instanceof JSText) { |
} else if (node instanceof JSText) { |
| 704 |
r += '| ' + indent + '"' + node.data + '"\n'; |
r += '| ' + indent + '"' + node.data + '"\n'; |
| 712 |
</head> |
</head> |
| 713 |
<body onload=" |
<body onload=" |
| 714 |
document.sourceElement = document.getElementsByTagName ('textarea')[0]; |
document.sourceElement = document.getElementsByTagName ('textarea')[0]; |
| 715 |
|
|
| 716 |
|
var q = location.search; |
| 717 |
|
if (q != null) { |
| 718 |
|
q = q.substring (1).split (/;/); |
| 719 |
|
for (var i = 0; i < q.length; i++) { |
| 720 |
|
var v = q[i].split (/=/, 2); |
| 721 |
|
v[0] = decodeURIComponent (v[0]); |
| 722 |
|
v[1] = decodeURIComponent (v[1] || ''); |
| 723 |
|
if (v[0] == 's') { |
| 724 |
|
document.sourceElement.value = v[1]; |
| 725 |
|
} |
| 726 |
|
} |
| 727 |
|
} |
| 728 |
|
|
| 729 |
document.logElement = document.getElementsByTagName ('output')[0]; |
document.logElement = document.getElementsByTagName ('output')[0]; |
| 730 |
update (); |
update (); |
| 731 |
"> |
"> |
| 732 |
|
<h1>Live Scripting <abbr title="Hypertext Markup Language">HTML</abbr> |
| 733 |
|
Parser</h1> |
| 734 |
|
|
| 735 |
<textarea onchange=" update () "><html> |
<h2>Markup to test |
| 736 |
|
(<a href=data:, id=permalink rel=bookmark>permalink</a>, |
| 737 |
|
<a href="http://software.hixie.ch/utilities/js/live-dom-viewer/" |
| 738 |
|
id=ldvlink>Live <abbr title="Document Object Model">DOM</abbr> |
| 739 |
|
Viewer</a>)</h2> |
| 740 |
|
<p> |
| 741 |
|
<textarea onkeydown=" update () " onchange=" update () " oninput=" update () "><html> |
| 742 |
<head></head><body> |
<head></head><body> |
| 743 |
<p> |
<p> |
| 744 |
<script> |
<script> |
| 747 |
<p> |
<p> |
| 748 |
</textarea> |
</textarea> |
| 749 |
|
|
| 750 |
<output></output> |
<h2 id=log>Log</h2> |
| 751 |
|
<p><output></output> |
| 752 |
|
|
| 753 |
|
<h2 id=notes>Notes</h2> |
| 754 |
|
|
| 755 |
|
<p>This is a <em>simplified</em> implementation of |
| 756 |
|
<a href="http://www.whatwg.org/specs/web-apps/current-work/#parsing">HTML5 |
| 757 |
|
Parsing Algorithm</a>. It only implements script-related part of the |
| 758 |
|
algorithm. Especially, this parser: |
| 759 |
|
<ul> |
| 760 |
|
<li>Does not support <code>DOCTYPE</code> and comment tokens. |
| 761 |
|
<li>Does not support entities except for <code>&quot;</code>, |
| 762 |
|
<code>&apos;</code>, and <code>&amp;</code> in <code>script</code> |
| 763 |
|
<code>src</code> attribute value. |
| 764 |
|
<li>Does not support omissions of start or end tags, the <abbr>AAA</abbr> |
| 765 |
|
algorithm, and so on. |
| 766 |
|
<li>Does not raise parse errors for invalid attribute specifications in start |
| 767 |
|
or end tags. |
| 768 |
|
<li>Does not support CDATA/PCDATA element other than <code>script</code>. |
| 769 |
|
<li>Does not support <code><!--</code>..<code>--></code> parsing rule |
| 770 |
|
in <code>script</code> element. |
| 771 |
|
<li>Does not support foreign (SVG or MathML) elements. |
| 772 |
|
<li>Only supports <code>script</code> <code>type</code> |
| 773 |
|
<code>text/javascript</code>. <code>type</code> and <code>language</code> |
| 774 |
|
attributes are ignored. |
| 775 |
|
<li>Only supports limited statements. It must consist of zero or more |
| 776 |
|
of statements looking similar to the following statements, possibly |
| 777 |
|
introduced, followed, or separated by white space characters: |
| 778 |
|
<ul> |
| 779 |
|
<li><code>document.write ("<var>string</var>", ["<var>string</var>", ...]);</code>. |
| 780 |
|
<li><code>var s = document.createElement ("script"); |
| 781 |
|
s.src = "<var>string</var>"; |
| 782 |
|
document.documentElement.appendChild (s);</code> |
| 783 |
|
</ul> |
| 784 |
|
Note that strings may be delimited by <code>'</code>s instead of |
| 785 |
|
<code>"</code>s. |
| 786 |
|
<li>Only supports <code>javascript:</code> |
| 787 |
|
<abbr title="Uniform Resourace Identifiers">URI</abbr> scheme in the |
| 788 |
|
<code>src</code> attribute of the <code>script</code> element. In addition, |
| 789 |
|
the <abbr title="Uniform Resource Identifiers">URI</abbr> must be conform to |
| 790 |
|
the regular expression <code>^javascript:\s*(?:"[^"]*"|'[^']*')\s*$</code>. |
| 791 |
|
<li>Only supports <code>\u<var>HHHH</var></code> escapes only in |
| 792 |
|
<code>javascript:</code> URI. |
| 793 |
|
</ul> |
| 794 |
|
|
| 795 |
|
<p>For some reason, this parser does not work in browsers that do |
| 796 |
|
not support JavaScript 1.5. |
| 797 |
|
|
| 798 |
|
<!-- TODO: license --> |
| 799 |
|
|
| 800 |
</body> |
</body> |
| 801 |
</html> |
</html> |