--- markup/html/scripting-parser/parser.html 2008/04/20 07:48:00 1.2
+++ markup/html/scripting-parser/parser.html 2008/04/27 11:27:04 1.13
@@ -1,30 +1,73 @@
-Demo of HTML5 Parsing Algorithm with Scripting Enabled
+Live Scripting HTML Parser
+
+
]+)>/, function (s, e) {
+ i.s = i.s.replace (/^<\/([^>]+)(?:>|$)/, function (s, e) {
+ if (p.insertionPoint < s.length ||
+ (p.insertionPoint <= s.length &&
+ s.substring (s.length - 1, 1) != '>')) {
+ token = {type: 'abort'};
+ return s;
+ }
token = {type: 'end-tag', value: e.toLowerCase ()};
+ p.insertionPoint -= s.length;
return '';
});
if (token) return token;
- i.s = i.s.replace (/^<([^>]+)>/, function (s, e) {
- token = {type: 'start-tag', value: e.toLowerCase ()};
+ i.s = i.s.replace (/^<([^>]+)(?:>|$)/, function (s, e) {
+ if (p.insertionPoint < s.length ||
+ (p.insertionPoint <= s.length &&
+ s.substring (s.length - 1, 1) != '>')) {
+ token = {type: 'abort'};
+ return s;
+ }
+ var tagName;
+ var attrs = {};
+ e = e.replace (/^[\S]+/, function (v) {
+ tagName = v.toLowerCase ();
+ return '';
+ });
+ while (true) {
+ var m = false;
+ e = e.replace (/^\s*([^\s=]+)\s*(?:=\s*(?:"([^"]*)"|'([^']*)'|([^"'\s]*)))?/,
+ function (x, attrName, attrValue1, attrValue2, attrValue3) {
+ v = attrValue1 || attrValue2 || attrValue3;
+ v = v.replace (/"/g, '"').replace (/'/g, "'")
+ .replace (/&/g, '&');
+ attrs[attrName.toLowerCase ()] = v;
+ m = true;
+ return '';
+ });
+ if (!m) break;
+ }
+ if (e.length) {
+ log ('Broken start tag: "' + e + '"');
+ }
+ token = {type: 'start-tag', value: tagName, attrs: attrs};
+ p.insertionPoint -= s.length;
return '';
});
if (token) return token;
+ if (p.insertionPoint <= 0) {
+ return {type: 'abort'};
+ }
i.s = i.s.replace (/^[^<]+/, function (s) {
+ if (p.insertionPoint < s.length) {
+ token = {type: 'char', value: s.substring (0, p.insertionPoint)};
+ var ip = p.insertionPoint;
+ p.insertionPoint = 0;
+ return s.substring (ip, s.length);
+ }
token = {type: 'char', value: s};
+ p.insertionPoint -= s.length;
return '';
});
if (token) return token;
i.s = i.s.replace (/^[\s\S]/, function (s) {
token = {type: 'char', value: s};
+ p.insertionPoint -= s.length;
return '';
});
if (token) return token;
@@ -82,7 +210,8 @@
} // getNextToken
Parser.prototype.parse = function () {
- log ('start parsing');
+ logIndentLevel++;
+ log ('parse: start');
while (true) {
var token = this.getNextToken ();
@@ -92,6 +221,9 @@
if (token.value == 'script') {
// 1. Create an element for the token in the HTML namespace.
var el = new JSElement (this.doc, token.value);
+ if (token.attrs.async != null) el.async = true;
+ if (token.attrs.defer != null) el.defer = true;
+ if (token.attrs.src != null) el.src = token.attrs.src;
// 2. Mark the element as being "parser-inserted".
el.manakaiParserInserted = true;
@@ -109,9 +241,10 @@
el.manakaiAppendText (token.value);
// 4.2. Until it returns a token that is not a character token, or
- // TODO: 4.3. Until it stops tokenising.
+ // until it stops tokenising.