/[suikacvs]/markup/html/scripting-parser/parser.html
Suika

Contents of /markup/html/scripting-parser/parser.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (show annotations) (download) (as text)
Sun Apr 27 10:34:18 2008 UTC (18 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.9: +70 -12 lines
File MIME type: text/html
Support for <script src> inserted by script (not by parser)

1 <!DOCTYPE HTML>
2 <html lang=en>
3 <head>
4 <title>Live Scripting HTML Parser</title>
5 <style>
6 h1, h2 {
7 margin: 0;
8 font-size: 100%;
9 }
10 p, pre {
11 margin: 0;
12 }
13 textarea {
14 width: 100%;
15 -width: 99%;
16 height: 10em;
17 }
18 output {
19 display: block;
20 font-family: monospace;
21 white-space: -moz-pre-wrap;
22 white-space: pre-wrap;
23 }
24 </style>
25 <script>
26 var delayedUpdater = 0;
27
28 function update () {
29 if (delayedUpdater) {
30 clearTimeout (delayedUpdater);
31 delayedUpdater = 0;
32 }
33 delayedUpdater = setTimeout (update2, 100);
34 } // 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) {
61 for (var i = 0; i < logIndentLevel; i++) {
62 s = ' ' + s;
63 }
64 document.logElement.appendChild (document.createTextNode (s + "\n"));
65 } // log
66
67 function InputStream (s) {
68 this.s = s;
69 } // InputStream
70
71 function Parser (i, doc) {
72 this.parseMode = 'pcdata';
73 if (!doc) {
74 doc = new JSDocument (this);
75 doc.manakaiIsHTML = true;
76 }
77 this.doc = doc;
78 this.openElements = [doc];
79 this.input = i;
80 this.scriptsExecutedAfterParsing = [];
81 this.scriptsExecutedSoon = [];
82 } // Parser
83
84 Parser.prototype.getNextToken = function () {
85 var p = this;
86 var i = this.input;
87 if (this.parseMode == 'script') {
88 var token;
89 if (p.insertionPoint <= 0) {
90 return {type: 'abort'};
91 }
92 i.s = i.s.replace (/^([^<]+)/,
93 function (s, t) {
94