Parent Directory
|
Revision Log
Does not reparse if the text is not changed; support for query strings; note on restrictions is added; s/.in/.input/g for ES3 compliance
| 1 | wakaba | 1.1 | <!DOCTYPE HTML> |
| 2 | <html lang=en> | ||
| 3 | <head> | ||
| 4 | wakaba | 1.8 | <title>Live Scripting HTML Parser</title> |
| 5 | wakaba | 1.1 | <style> |
| 6 | wakaba | 1.7 | h1, h2 { |
| 7 | margin: 0; | ||
| 8 | font-size: 100%; | ||
| 9 | } | ||
| 10 | p, pre { | ||
| 11 | margin: 0; | ||
| 12 | } | ||
| 13 | wakaba | 1.1 | textarea { |
| 14 | wakaba | 1.7 | width: 100%; |
| 15 | -width: 99%; | ||
| 16 | height: 10em; | ||
| 17 | wakaba | 1.1 | } |
| 18 | output { | ||
| 19 | display: block; | ||
| 20 | font-family: monospace; | ||
| 21 | wakaba | 1.4 | white-space: -moz-pre-wrap; |
| 22 | white-space: pre-wrap; | ||
| 23 | wakaba | 1.1 | } |
| 24 | </style> | ||
| 25 | <script> | ||
| 26 | wakaba | 1.7 | var delayedUpdater = 0; |
| 27 | |||
| 28 | wakaba | 1.1 | function update () { |
| 29 | wakaba | 1.7 | 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 | wakaba | 1.8 | 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 | log (dumpTree (doc, '')); | ||
| 51 | } | ||
| 52 | wakaba | 1.7 | } // update2 |
| 53 | wakaba | 1.1 | |
| 54 | wakaba | 1.6 | var logIndentLevel = 0; |
| 55 | wakaba | 1.1 | function log (s) { |
| 56 | wakaba | 1.6 | for (var i = 0; i < logIndentLevel; i++) { |
| 57 | s = ' ' + s; | ||
| 58 | } | ||
| 59 | wakaba | 1.1 | document.logElement.appendChild (document.createTextNode (s + "\n")); |
| 60 | } // log | ||
| 61 | |||
| 62 | function InputStream (s) { | ||
| 63 | this.s = s; | ||
| 64 | } // InputStream | ||
| 65 | |||
| 66 | wakaba | 1.4 | function Parser (i, doc) { |
| 67 | wakaba | 1.1 | this.parseMode = 'pcdata'; |
| 68 | wakaba | 1.4 | if (!doc) { |
| 69 | doc = new JSDocument (this); | ||
| 70 | doc.manakaiIsHTML = true; | ||
| 71 | } | ||
| 72 | this.doc = doc; | ||
| 73 | this.openElements = [doc]; | ||
| 74 | wakaba | 1.8 | this.input = i; |
| 75 | wakaba | 1.4 | this.scriptsExecutedAfterParsing = []; |
| 76 | wakaba | 1.1 | } // Parser |
| 77 | |||
| 78 | wakaba | 1.2 | Parser.prototype.getNextToken = function () { |
| 79 | wakaba | 1.3 | var p = this; |
| 80 | wakaba | 1.8 | var i = this.input; |
| 81 | wakaba | 1.1 | if (this.parseMode == 'script') { |
| 82 | var token; | ||
| 83 | wakaba | 1.3 | if (p.insertionPoint <= 0) { |
| 84 | return {type: 'abort'}; | ||