diff --git a/lib/ace/mode/html/saxparser.js b/lib/ace/mode/html/saxparser.js
index eb4cadca..e19e1fc4 100644
--- a/lib/ace/mode/html/saxparser.js
+++ b/lib/ace/mode/html/saxparser.js
@@ -1,487 +1,487 @@
define(function(require, exports, module) {
module.exports = (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o= 0; i--) {
- var node = this.elements[i];
- if (node.localName === localName)
- return true;
- if (isMarker(node))
- return false;
- }
-};
-
-/**
- * Pushes the item on the stack top
- * @param {StackItem} item
- */
-ElementStack.prototype.push = function(item) {
- this.elements.push(item);
-};
-
-/**
- * Pushes the item on the stack top
- * @param {StackItem} item HTML element stack item
- */
-ElementStack.prototype.pushHtmlElement = function(item) {
- this.rootNode = item.node;
- this.push(item);
-};
-
-/**
- * Pushes the item on the stack top
- * @param {StackItem} item HEAD element stack item
- */
-ElementStack.prototype.pushHeadElement = function(item) {
- this.headElement = item.node;
- this.push(item);
-};
-
-/**
- * Pushes the item on the stack top
- * @param {StackItem} item BODY element stack item
- */
-ElementStack.prototype.pushBodyElement = function(item) {
- this.bodyElement = item.node;
- this.push(item);
-};
-
-/**
- * Pops the topmost item
- * @return {StackItem}
- */
-ElementStack.prototype.pop = function() {
- return this.elements.pop();
-};
-
-/**
- * Removes the item from the element stack
- * @param {StackItem} item The item to remove
- */
-ElementStack.prototype.remove = function(item) {
- this.elements.splice(this.elements.indexOf(item), 1);
-};
-
-/**
- * Pops until an element with a given localName is popped
- * @param {String} localName
- */
-ElementStack.prototype.popUntilPopped = function(localName) {
- var element;
- do {
- element = this.pop();
- } while (element.localName != localName);
-};
-
-ElementStack.prototype.popUntilTableScopeMarker = function() {
- while (!isTableScopeMarker(this.top))
- this.pop();
-};
-
-ElementStack.prototype.popUntilTableBodyScopeMarker = function() {
- while (!isTableBodyScopeMarker(this.top))
- this.pop();
-};
-
-ElementStack.prototype.popUntilTableRowScopeMarker = function() {
- while (!isTableRowScopeMarker(this.top))
- this.pop();
-};
-
-/**
- *
- * @param {Number} index
- * @return {StackItem}
- */
-ElementStack.prototype.item = function(index) {
- return this.elements[index];
-};
-
-/**
- *
- * @param {StackItem} element
- * @return {Boolean}
- */
-ElementStack.prototype.contains = function(element) {
- return this.elements.indexOf(element) !== -1;
-};
-
-/**
- *
- * @param {String} localName
- * @return {Boolean}
- */
-ElementStack.prototype.inScope = function(localName) {
- return this._inScope(localName, isScopeMarker);
-};
-
-/**
- *
- * @param {String} localName
- * @return {Boolean}
- */
-ElementStack.prototype.inListItemScope = function(localName) {
- return this._inScope(localName, isListItemScopeMarker);
-};
-
-/**
- *
- * @param {String} localName
- * @return {Boolean}
- */
-ElementStack.prototype.inTableScope = function(localName) {
- return this._inScope(localName, isTableScopeMarker);
-};
-
-/**
- *
- * @param {String} localName
- * @return {Boolean}
- */
-ElementStack.prototype.inButtonScope = function(localName) {
- return this._inScope(localName, isButtonScopeMarker);
-};
-
-/**
- *
- * @param {String} localName
- * @return {Boolean}
- */
-ElementStack.prototype.inSelectScope = function(localName) {
- return this._inScope(localName, isSelectScopeMarker);
-};
-
-/**
- *
- * @return {Boolean}
- */
-ElementStack.prototype.hasNumberedHeaderElementInScope = function() {
- for (var i = this.elements.length - 1; i >= 0; i--) {
- var node = this.elements[i];
- if (node.isNumberedHeader())
- return true;
- if (isScopeMarker(node))
- return false;
- }
-};
-
-/**
- *
- * @param {Object} element
- * @return {StackItem}
- */
-ElementStack.prototype.furthestBlockForFormattingElement = function(element) {
- var furthestBlock = null;
- for (var i = this.elements.length - 1; i >= 0; i--) {
- var node = this.elements[i];
- if (node.node === element)
- break;
- if (node.isSpecial())
- furthestBlock = node;
- }
- return furthestBlock;
-};
-
-/**
- *
- * @param {String} localName
- * @return {Number}
- */
-ElementStack.prototype.findIndex = function(localName) {
- for (var i = this.elements.length - 1; i >= 0; i--) {
- if (this.elements[i].localName == localName)
- return i;
- }
- return -1;
-};
-
-ElementStack.prototype.remove_openElements_until = function(callback) {
- var finished = false;
- var element;
- while (!finished) {
- element = this.elements.pop();
- finished = callback(element);
- }
- return element;
-};
-
-Object.defineProperty(ElementStack.prototype, 'top', {
- get: function() {
- return this.elements[this.elements.length - 1];
- }
-});
-
-Object.defineProperty(ElementStack.prototype, 'length', {
- get: function() {
- return this.elements.length;
- }
-});
-
-exports.ElementStack = ElementStack;
+function isScopeMarker(node) {
+ if (node.namespaceURI === "http://www.w3.org/1999/xhtml") {
+ return node.localName === "applet"
+ || node.localName === "caption"
+ || node.localName === "marquee"
+ || node.localName === "object"
+ || node.localName === "table"
+ || node.localName === "td"
+ || node.localName === "th";
+ }
+ if (node.namespaceURI === "http://www.w3.org/1998/Math/MathML") {
+ return node.localName === "mi"
+ || node.localName === "mo"
+ || node.localName === "mn"
+ || node.localName === "ms"
+ || node.localName === "mtext"
+ || node.localName === "annotation-xml";
+ }
+ if (node.namespaceURI === "http://www.w3.org/2000/svg") {
+ return node.localName === "foreignObject"
+ || node.localName === "desc"
+ || node.localName === "title";
+ }
+}
+
+function isListItemScopeMarker(node) {
+ return isScopeMarker(node)
+ || (node.namespaceURI === "http://www.w3.org/1999/xhtml" && node.localName === 'ol')
+ || (node.namespaceURI === "http://www.w3.org/1999/xhtml" && node.localName === 'ul');
+}
+
+function isTableScopeMarker(node) {
+ return (node.namespaceURI === "http://www.w3.org/1999/xhtml" && node.localName === 'table')
+ || (node.namespaceURI === "http://www.w3.org/1999/xhtml" && node.localName === 'html');
+}
+
+function isTableBodyScopeMarker(node) {
+ return (node.namespaceURI === "http://www.w3.org/1999/xhtml" && node.localName === 'tbody')
+ || (node.namespaceURI === "http://www.w3.org/1999/xhtml" && node.localName === 'tfoot')
+ || (node.namespaceURI === "http://www.w3.org/1999/xhtml" && node.localName === 'thead')
+ || (node.namespaceURI === "http://www.w3.org/1999/xhtml" && node.localName === 'html');
+}
+
+function isTableRowScopeMarker(node) {
+ return (node.namespaceURI === "http://www.w3.org/1999/xhtml" && node.localName === 'tr')
+ || (node.namespaceURI === "http://www.w3.org/1999/xhtml" && node.localName === 'html');
+}
+
+function isButtonScopeMarker(node) {
+ return isScopeMarker(node)
+ || (node.namespaceURI === "http://www.w3.org/1999/xhtml" && node.localName === 'button');
+}
+
+function isSelectScopeMarker(node) {
+ return !(node.namespaceURI === "http://www.w3.org/1999/xhtml" && node.localName === 'optgroup')
+ && !(node.namespaceURI === "http://www.w3.org/1999/xhtml" && node.localName === 'option');
+}
+
+/**
+ * Represents a stack of open elements
+ * @constructor
+ */
+function ElementStack() {
+ this.elements = [];
+ this.rootNode = null;
+ this.headElement = null;
+ this.bodyElement = null;
+}
+
+/**
+ *
+ * @param {String} localName
+ * @param {Function} isMarker
+ * @return {Boolean}
+ * @private
+ */
+ElementStack.prototype._inScope = function(localName, isMarker) {
+ for (var i = this.elements.length - 1; i >= 0; i--) {
+ var node = this.elements[i];
+ if (node.localName === localName)
+ return true;
+ if (isMarker(node))
+ return false;
+ }
+};
+
+/**
+ * Pushes the item on the stack top
+ * @param {StackItem} item
+ */
+ElementStack.prototype.push = function(item) {
+ this.elements.push(item);
+};
+
+/**
+ * Pushes the item on the stack top
+ * @param {StackItem} item HTML element stack item
+ */
+ElementStack.prototype.pushHtmlElement = function(item) {
+ this.rootNode = item.node;
+ this.push(item);
+};
+
+/**
+ * Pushes the item on the stack top
+ * @param {StackItem} item HEAD element stack item
+ */
+ElementStack.prototype.pushHeadElement = function(item) {
+ this.headElement = item.node;
+ this.push(item);
+};
+
+/**
+ * Pushes the item on the stack top
+ * @param {StackItem} item BODY element stack item
+ */
+ElementStack.prototype.pushBodyElement = function(item) {
+ this.bodyElement = item.node;
+ this.push(item);
+};
+
+/**
+ * Pops the topmost item
+ * @return {StackItem}
+ */
+ElementStack.prototype.pop = function() {
+ return this.elements.pop();
+};
+
+/**
+ * Removes the item from the element stack
+ * @param {StackItem} item The item to remove
+ */
+ElementStack.prototype.remove = function(item) {
+ this.elements.splice(this.elements.indexOf(item), 1);
+};
+
+/**
+ * Pops until an element with a given localName is popped
+ * @param {String} localName
+ */
+ElementStack.prototype.popUntilPopped = function(localName) {
+ var element;
+ do {
+ element = this.pop();
+ } while (element.localName != localName);
+};
+
+ElementStack.prototype.popUntilTableScopeMarker = function() {
+ while (!isTableScopeMarker(this.top))
+ this.pop();
+};
+
+ElementStack.prototype.popUntilTableBodyScopeMarker = function() {
+ while (!isTableBodyScopeMarker(this.top))
+ this.pop();
+};
+
+ElementStack.prototype.popUntilTableRowScopeMarker = function() {
+ while (!isTableRowScopeMarker(this.top))
+ this.pop();
+};
+
+/**
+ *
+ * @param {Number} index
+ * @return {StackItem}
+ */
+ElementStack.prototype.item = function(index) {
+ return this.elements[index];
+};
+
+/**
+ *
+ * @param {StackItem} element
+ * @return {Boolean}
+ */
+ElementStack.prototype.contains = function(element) {
+ return this.elements.indexOf(element) !== -1;
+};
+
+/**
+ *
+ * @param {String} localName
+ * @return {Boolean}
+ */
+ElementStack.prototype.inScope = function(localName) {
+ return this._inScope(localName, isScopeMarker);
+};
+
+/**
+ *
+ * @param {String} localName
+ * @return {Boolean}
+ */
+ElementStack.prototype.inListItemScope = function(localName) {
+ return this._inScope(localName, isListItemScopeMarker);
+};
+
+/**
+ *
+ * @param {String} localName
+ * @return {Boolean}
+ */
+ElementStack.prototype.inTableScope = function(localName) {
+ return this._inScope(localName, isTableScopeMarker);
+};
+
+/**
+ *
+ * @param {String} localName
+ * @return {Boolean}
+ */
+ElementStack.prototype.inButtonScope = function(localName) {
+ return this._inScope(localName, isButtonScopeMarker);
+};
+
+/**
+ *
+ * @param {String} localName
+ * @return {Boolean}
+ */
+ElementStack.prototype.inSelectScope = function(localName) {
+ return this._inScope(localName, isSelectScopeMarker);
+};
+
+/**
+ *
+ * @return {Boolean}
+ */
+ElementStack.prototype.hasNumberedHeaderElementInScope = function() {
+ for (var i = this.elements.length - 1; i >= 0; i--) {
+ var node = this.elements[i];
+ if (node.isNumberedHeader())
+ return true;
+ if (isScopeMarker(node))
+ return false;
+ }
+};
+
+/**
+ *
+ * @param {Object} element
+ * @return {StackItem}
+ */
+ElementStack.prototype.furthestBlockForFormattingElement = function(element) {
+ var furthestBlock = null;
+ for (var i = this.elements.length - 1; i >= 0; i--) {
+ var node = this.elements[i];
+ if (node.node === element)
+ break;
+ if (node.isSpecial())
+ furthestBlock = node;
+ }
+ return furthestBlock;
+};
+
+/**
+ *
+ * @param {String} localName
+ * @return {Number}
+ */
+ElementStack.prototype.findIndex = function(localName) {
+ for (var i = this.elements.length - 1; i >= 0; i--) {
+ if (this.elements[i].localName == localName)
+ return i;
+ }
+ return -1;
+};
+
+ElementStack.prototype.remove_openElements_until = function(callback) {
+ var finished = false;
+ var element;
+ while (!finished) {
+ element = this.elements.pop();
+ finished = callback(element);
+ }
+ return element;
+};
+
+Object.defineProperty(ElementStack.prototype, 'top', {
+ get: function() {
+ return this.elements[this.elements.length - 1];
+ }
+});
+
+Object.defineProperty(ElementStack.prototype, 'length', {
+ get: function() {
+ return this.elements.length;
+ }
+});
+
+exports.ElementStack = ElementStack;
},
{}],
2:[function(_dereq_,module,exports){
-var entities = _dereq_('html5-entities');
-var InputStream = _dereq_('./InputStream').InputStream;
-
-var namedEntityPrefixes = {};
-Object.keys(entities).forEach(function (entityKey) {
- for (var i = 0; i < entityKey.length; i++) {
- namedEntityPrefixes[entityKey.substring(0, i + 1)] = true;
- }
-});
-
-function isAlphaNumeric(c) {
- return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
-}
-
-function isHexDigit(c) {
- return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
-}
-
-function isDecimalDigit(c) {
- return (c >= '0' && c <= '9');
-}
-
-var EntityParser = {};
-
-EntityParser.consumeEntity = function(buffer, tokenizer, additionalAllowedCharacter) {
- var decodedCharacter = '';
- var consumedCharacters = '';
- var ch = buffer.char();
- if (ch === InputStream.EOF)
- return false;
- consumedCharacters += ch;
- if (ch == '\t' || ch == '\n' || ch == '\v' || ch == ' ' || ch == '<' || ch == '&') {
- buffer.unget(consumedCharacters);
- return false;
- }
- if (additionalAllowedCharacter === ch) {
- buffer.unget(consumedCharacters);
- return false;
- }
- if (ch == '#') {
- ch = buffer.shift(1);
- if (ch === InputStream.EOF) {
- tokenizer._parseError("expected-numeric-entity-but-got-eof");
- buffer.unget(consumedCharacters);
- return false;
- }
- consumedCharacters += ch;
- var radix = 10;
- var isDigit = isDecimalDigit;
- if (ch == 'x' || ch == 'X') {
- radix = 16;
- isDigit = isHexDigit;
- ch = buffer.shift(1);
- if (ch === InputStream.EOF) {
- tokenizer._parseError("expected-numeric-entity-but-got-eof");
- buffer.unget(consumedCharacters);
- return false;
- }
- consumedCharacters += ch;
- }
- if (isDigit(ch)) {
- var code = '';
- while (ch !== InputStream.EOF && isDigit(ch)) {
- code += ch;
- ch = buffer.char();
- }
- code = parseInt(code, radix);
- var replacement = this.replaceEntityNumbers(code);
- if (replacement) {
- tokenizer._parseError("invalid-numeric-entity-replaced");
- code = replacement;
- }
- if (code > 0xFFFF && code <= 0x10FFFF) {
- // we substract 0x10000 from cp to get a 20-bits number
- // in the range 0..0xFFFF
- code -= 0x10000;
- // we add 0xD800 to the number formed by the first 10 bits
- // to give the first byte
- var first = ((0xffc00 & code) >> 10) + 0xD800;
- // we add 0xDC00 to the number formed by the low 10 bits
- // to give the second byte
- var second = (0x3ff & code) + 0xDC00;
- decodedCharacter = String.fromCharCode(first, second);
- } else
- decodedCharacter = String.fromCharCode(code);
- if (ch !== ';') {
- tokenizer._parseError("numeric-entity-without-semicolon");
- buffer.unget(ch);
- }
- return decodedCharacter;
- }
- buffer.unget(consumedCharacters);
- tokenizer._parseError("expected-numeric-entity");
- return false;
- }
- if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
- var mostRecentMatch = '';
- while (namedEntityPrefixes[consumedCharacters]) {
- if (entities[consumedCharacters]) {
- mostRecentMatch = consumedCharacters;
- }
- if (ch == ';')
- break;
- ch = buffer.char();
- if (ch === InputStream.EOF)
- break;
- consumedCharacters += ch;
- }
- if (!mostRecentMatch) {
- tokenizer._parseError("expected-named-entity");
- buffer.unget(consumedCharacters);
- return false;
- }
- decodedCharacter = entities[mostRecentMatch];
- if (ch === ';' || !additionalAllowedCharacter || !(isAlphaNumeric(ch) || ch === '=')) {
- if (consumedCharacters.length > mostRecentMatch.length) {
- buffer.unget(consumedCharacters.substring(mostRecentMatch.length));
- }
- if (ch !== ';') {
- tokenizer._parseError("named-entity-without-semicolon");
- }
- return decodedCharacter;
- }
- buffer.unget(consumedCharacters);
- return false;
- }
-};
-
-EntityParser.replaceEntityNumbers = function(c) {
- switch(c) {
- case 0x00: return 0xFFFD; // REPLACEMENT CHARACTER
- case 0x13: return 0x0010; // Carriage return
- case 0x80: return 0x20AC; // EURO SIGN
- case 0x81: return 0x0081; //
- case 0x82: return 0x201A; // SINGLE LOW-9 QUOTATION MARK
- case 0x83: return 0x0192; // LATIN SMALL LETTER F WITH HOOK
- case 0x84: return 0x201E; // DOUBLE LOW-9 QUOTATION MARK
- case 0x85: return 0x2026; // HORIZONTAL ELLIPSIS
- case 0x86: return 0x2020; // DAGGER
- case 0x87: return 0x2021; // DOUBLE DAGGER
- case 0x88: return 0x02C6; // MODIFIER LETTER CIRCUMFLEX ACCENT
- case 0x89: return 0x2030; // PER MILLE SIGN
- case 0x8A: return 0x0160; // LATIN CAPITAL LETTER S WITH CARON
- case 0x8B: return 0x2039; // SINGLE LEFT-POINTING ANGLE QUOTATION MARK
- case 0x8C: return 0x0152; // LATIN CAPITAL LIGATURE OE
- case 0x8D: return 0x008D; //
- case 0x8E: return 0x017D; // LATIN CAPITAL LETTER Z WITH CARON
- case 0x8F: return 0x008F; //
- case 0x90: return 0x0090; //
- case 0x91: return 0x2018; // LEFT SINGLE QUOTATION MARK
- case 0x92: return 0x2019; // RIGHT SINGLE QUOTATION MARK
- case 0x93: return 0x201C; // LEFT DOUBLE QUOTATION MARK
- case 0x94: return 0x201D; // RIGHT DOUBLE QUOTATION MARK
- case 0x95: return 0x2022; // BULLET
- case 0x96: return 0x2013; // EN DASH
- case 0x97: return 0x2014; // EM DASH
- case 0x98: return 0x02DC; // SMALL TILDE
- case 0x99: return 0x2122; // TRADE MARK SIGN
- case 0x9A: return 0x0161; // LATIN SMALL LETTER S WITH CARON
- case 0x9B: return 0x203A; // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
- case 0x9C: return 0x0153; // LATIN SMALL LIGATURE OE
- case 0x9D: return 0x009D; //
- case 0x9E: return 0x017E; // LATIN SMALL LETTER Z WITH CARON
- case 0x9F: return 0x0178; // LATIN CAPITAL LETTER Y WITH DIAERESIS
- default:
- if ((c >= 0xD800 && c <= 0xDFFF) || c > 0x10FFFF) {
- return 0xFFFD;
- } else if ((c >= 0x0001 && c <= 0x0008) || (c >= 0x000E && c <= 0x001F) ||
- (c >= 0x007F && c <= 0x009F) || (c >= 0xFDD0 && c <= 0xFDEF) ||
- c == 0x000B || c == 0xFFFE || c == 0x1FFFE || c == 0x2FFFFE ||
- c == 0x2FFFF || c == 0x3FFFE || c == 0x3FFFF || c == 0x4FFFE ||
- c == 0x4FFFF || c == 0x5FFFE || c == 0x5FFFF || c == 0x6FFFE ||
- c == 0x6FFFF || c == 0x7FFFE || c == 0x7FFFF || c == 0x8FFFE ||
- c == 0x8FFFF || c == 0x9FFFE || c == 0x9FFFF || c == 0xAFFFE ||
- c == 0xAFFFF || c == 0xBFFFE || c == 0xBFFFF || c == 0xCFFFE ||
- c == 0xCFFFF || c == 0xDFFFE || c == 0xDFFFF || c == 0xEFFFE ||
- c == 0xEFFFF || c == 0xFFFFE || c == 0xFFFFF || c == 0x10FFFE ||
- c == 0x10FFFF) {
- return c;
- }
- }
-};
-
-exports.EntityParser = EntityParser;
+var entities = _dereq_('html5-entities');
+var InputStream = _dereq_('./InputStream').InputStream;
+
+var namedEntityPrefixes = {};
+Object.keys(entities).forEach(function (entityKey) {
+ for (var i = 0; i < entityKey.length; i++) {
+ namedEntityPrefixes[entityKey.substring(0, i + 1)] = true;
+ }
+});
+
+function isAlphaNumeric(c) {
+ return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
+}
+
+function isHexDigit(c) {
+ return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
+}
+
+function isDecimalDigit(c) {
+ return (c >= '0' && c <= '9');
+}
+
+var EntityParser = {};
+
+EntityParser.consumeEntity = function(buffer, tokenizer, additionalAllowedCharacter) {
+ var decodedCharacter = '';
+ var consumedCharacters = '';
+ var ch = buffer.char();
+ if (ch === InputStream.EOF)
+ return false;
+ consumedCharacters += ch;
+ if (ch == '\t' || ch == '\n' || ch == '\v' || ch == ' ' || ch == '<' || ch == '&') {
+ buffer.unget(consumedCharacters);
+ return false;
+ }
+ if (additionalAllowedCharacter === ch) {
+ buffer.unget(consumedCharacters);
+ return false;
+ }
+ if (ch == '#') {
+ ch = buffer.shift(1);
+ if (ch === InputStream.EOF) {
+ tokenizer._parseError("expected-numeric-entity-but-got-eof");
+ buffer.unget(consumedCharacters);
+ return false;
+ }
+ consumedCharacters += ch;
+ var radix = 10;
+ var isDigit = isDecimalDigit;
+ if (ch == 'x' || ch == 'X') {
+ radix = 16;
+ isDigit = isHexDigit;
+ ch = buffer.shift(1);
+ if (ch === InputStream.EOF) {
+ tokenizer._parseError("expected-numeric-entity-but-got-eof");
+ buffer.unget(consumedCharacters);
+ return false;
+ }
+ consumedCharacters += ch;
+ }
+ if (isDigit(ch)) {
+ var code = '';
+ while (ch !== InputStream.EOF && isDigit(ch)) {
+ code += ch;
+ ch = buffer.char();
+ }
+ code = parseInt(code, radix);
+ var replacement = this.replaceEntityNumbers(code);
+ if (replacement) {
+ tokenizer._parseError("invalid-numeric-entity-replaced");
+ code = replacement;
+ }
+ if (code > 0xFFFF && code <= 0x10FFFF) {
+ // we substract 0x10000 from cp to get a 20-bits number
+ // in the range 0..0xFFFF
+ code -= 0x10000;
+ // we add 0xD800 to the number formed by the first 10 bits
+ // to give the first byte
+ var first = ((0xffc00 & code) >> 10) + 0xD800;
+ // we add 0xDC00 to the number formed by the low 10 bits
+ // to give the second byte
+ var second = (0x3ff & code) + 0xDC00;
+ decodedCharacter = String.fromCharCode(first, second);
+ } else
+ decodedCharacter = String.fromCharCode(code);
+ if (ch !== ';') {
+ tokenizer._parseError("numeric-entity-without-semicolon");
+ buffer.unget(ch);
+ }
+ return decodedCharacter;
+ }
+ buffer.unget(consumedCharacters);
+ tokenizer._parseError("expected-numeric-entity");
+ return false;
+ }
+ if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
+ var mostRecentMatch = '';
+ while (namedEntityPrefixes[consumedCharacters]) {
+ if (entities[consumedCharacters]) {
+ mostRecentMatch = consumedCharacters;
+ }
+ if (ch == ';')
+ break;
+ ch = buffer.char();
+ if (ch === InputStream.EOF)
+ break;
+ consumedCharacters += ch;
+ }
+ if (!mostRecentMatch) {
+ tokenizer._parseError("expected-named-entity");
+ buffer.unget(consumedCharacters);
+ return false;
+ }
+ decodedCharacter = entities[mostRecentMatch];
+ if (ch === ';' || !additionalAllowedCharacter || !(isAlphaNumeric(ch) || ch === '=')) {
+ if (consumedCharacters.length > mostRecentMatch.length) {
+ buffer.unget(consumedCharacters.substring(mostRecentMatch.length));
+ }
+ if (ch !== ';') {
+ tokenizer._parseError("named-entity-without-semicolon");
+ }
+ return decodedCharacter;
+ }
+ buffer.unget(consumedCharacters);
+ return false;
+ }
+};
+
+EntityParser.replaceEntityNumbers = function(c) {
+ switch(c) {
+ case 0x00: return 0xFFFD; // REPLACEMENT CHARACTER
+ case 0x13: return 0x0010; // Carriage return
+ case 0x80: return 0x20AC; // EURO SIGN
+ case 0x81: return 0x0081; //
+ case 0x82: return 0x201A; // SINGLE LOW-9 QUOTATION MARK
+ case 0x83: return 0x0192; // LATIN SMALL LETTER F WITH HOOK
+ case 0x84: return 0x201E; // DOUBLE LOW-9 QUOTATION MARK
+ case 0x85: return 0x2026; // HORIZONTAL ELLIPSIS
+ case 0x86: return 0x2020; // DAGGER
+ case 0x87: return 0x2021; // DOUBLE DAGGER
+ case 0x88: return 0x02C6; // MODIFIER LETTER CIRCUMFLEX ACCENT
+ case 0x89: return 0x2030; // PER MILLE SIGN
+ case 0x8A: return 0x0160; // LATIN CAPITAL LETTER S WITH CARON
+ case 0x8B: return 0x2039; // SINGLE LEFT-POINTING ANGLE QUOTATION MARK
+ case 0x8C: return 0x0152; // LATIN CAPITAL LIGATURE OE
+ case 0x8D: return 0x008D; //
+ case 0x8E: return 0x017D; // LATIN CAPITAL LETTER Z WITH CARON
+ case 0x8F: return 0x008F; //
+ case 0x90: return 0x0090; //
+ case 0x91: return 0x2018; // LEFT SINGLE QUOTATION MARK
+ case 0x92: return 0x2019; // RIGHT SINGLE QUOTATION MARK
+ case 0x93: return 0x201C; // LEFT DOUBLE QUOTATION MARK
+ case 0x94: return 0x201D; // RIGHT DOUBLE QUOTATION MARK
+ case 0x95: return 0x2022; // BULLET
+ case 0x96: return 0x2013; // EN DASH
+ case 0x97: return 0x2014; // EM DASH
+ case 0x98: return 0x02DC; // SMALL TILDE
+ case 0x99: return 0x2122; // TRADE MARK SIGN
+ case 0x9A: return 0x0161; // LATIN SMALL LETTER S WITH CARON
+ case 0x9B: return 0x203A; // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
+ case 0x9C: return 0x0153; // LATIN SMALL LIGATURE OE
+ case 0x9D: return 0x009D; //
+ case 0x9E: return 0x017E; // LATIN SMALL LETTER Z WITH CARON
+ case 0x9F: return 0x0178; // LATIN CAPITAL LETTER Y WITH DIAERESIS
+ default:
+ if ((c >= 0xD800 && c <= 0xDFFF) || c > 0x10FFFF) {
+ return 0xFFFD;
+ } else if ((c >= 0x0001 && c <= 0x0008) || (c >= 0x000E && c <= 0x001F) ||
+ (c >= 0x007F && c <= 0x009F) || (c >= 0xFDD0 && c <= 0xFDEF) ||
+ c == 0x000B || c == 0xFFFE || c == 0x1FFFE || c == 0x2FFFFE ||
+ c == 0x2FFFF || c == 0x3FFFE || c == 0x3FFFF || c == 0x4FFFE ||
+ c == 0x4FFFF || c == 0x5FFFE || c == 0x5FFFF || c == 0x6FFFE ||
+ c == 0x6FFFF || c == 0x7FFFE || c == 0x7FFFF || c == 0x8FFFE ||
+ c == 0x8FFFF || c == 0x9FFFE || c == 0x9FFFF || c == 0xAFFFE ||
+ c == 0xAFFFF || c == 0xBFFFE || c == 0xBFFFF || c == 0xCFFFE ||
+ c == 0xCFFFF || c == 0xDFFFE || c == 0xDFFFF || c == 0xEFFFE ||
+ c == 0xEFFFF || c == 0xFFFFE || c == 0xFFFFF || c == 0x10FFFE ||
+ c == 0x10FFFF) {
+ return c;
+ }
+ }
+};
+
+exports.EntityParser = EntityParser;
},
{"./InputStream":3,"html5-entities":12}],
@@ -601,185 +601,185 @@ exports.InputStream = InputStream;
},
{}],
4:[function(_dereq_,module,exports){
-var SpecialElements = {
- "http://www.w3.org/1999/xhtml": [
- 'address',
- 'applet',
- 'area',
- 'article',
- 'aside',
- 'base',
- 'basefont',
- 'bgsound',
- 'blockquote',
- 'body',
- 'br',
- 'button',
- 'caption',
- 'center',
- 'col',
- 'colgroup',
- 'dd',
- 'details',
- 'dir',
- 'div',
- 'dl',
- 'dt',
- 'embed',
- 'fieldset',
- 'figcaption',
- 'figure',
- 'footer',
- 'form',
- 'frame',
- 'frameset',
- 'h1',
- 'h2',
- 'h3',
- 'h4',
- 'h5',
- 'h6',
- 'head',
- 'header',
- 'hgroup',
- 'hr',
- 'html',
- 'iframe',
- 'img',
- 'input',
- 'isindex',
- 'li',
- 'link',
- 'listing',
- 'main',
- 'marquee',
- 'menu',
- 'menuitem',
- 'meta',
- 'nav',
- 'noembed',
- 'noframes',
- 'noscript',
- 'object',
- 'ol',
- 'p',
- 'param',
- 'plaintext',
- 'pre',
- 'script',
- 'section',
- 'select',
- 'source',
- 'style',
- 'summary',
- 'table',
- 'tbody',
- 'td',
- 'textarea',
- 'tfoot',
- 'th',
- 'thead',
- 'title',
- 'tr',
- 'track',
- 'ul',
- 'wbr',
- 'xmp'
- ],
- "http://www.w3.org/1998/Math/MathML": [
- 'mi',
- 'mo',
- 'mn',
- 'ms',
- 'mtext',
- 'annotation-xml'
- ],
- "http://www.w3.org/2000/svg": [
- 'foreignObject',
- 'desc',
- 'title'
- ]
-};
-
-
-function StackItem(namespaceURI, localName, attributes, node) {
- this.localName = localName;
- this.namespaceURI = namespaceURI;
- this.attributes = attributes;
- this.node = node;
-}
-
-// http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#special
-StackItem.prototype.isSpecial = function() {
- return this.namespaceURI in SpecialElements &&
- SpecialElements[this.namespaceURI].indexOf(this.localName) > -1;
-};
-
-StackItem.prototype.isFosterParenting = function() {
- if (this.namespaceURI === "http://www.w3.org/1999/xhtml") {
- return this.localName === 'table' ||
- this.localName === 'tbody' ||
- this.localName === 'tfoot' ||
- this.localName === 'thead' ||
- this.localName === 'tr';
- }
- return false;
-};
-
-StackItem.prototype.isNumberedHeader = function() {
- if (this.namespaceURI === "http://www.w3.org/1999/xhtml") {
- return this.localName === 'h1' ||
- this.localName === 'h2' ||
- this.localName === 'h3' ||
- this.localName === 'h4' ||
- this.localName === 'h5' ||
- this.localName === 'h6';
- }
- return false;
-};
-
-StackItem.prototype.isForeign = function() {
- return this.namespaceURI != "http://www.w3.org/1999/xhtml";
-};
-
-function getAttribute(item, name) {
- for (var i = 0; i < item.attributes.length; i++) {
- if (item.attributes[i].nodeName == name)
- return item.attributes[i].nodeValue;
- }
- return null;
-}
-
-StackItem.prototype.isHtmlIntegrationPoint = function() {
- if (this.namespaceURI === "http://www.w3.org/1998/Math/MathML") {
- if (this.localName !== "annotation-xml")
- return false;
- var encoding = getAttribute(this, 'encoding');
- if (!encoding)
- return false;
- encoding = encoding.toLowerCase();
- return encoding === "text/html" || encoding === "application/xhtml+xml";
- }
- if (this.namespaceURI === "http://www.w3.org/2000/svg") {
- return this.localName === "foreignObject"
- || this.localName === "desc"
- || this.localName === "title";
- }
- return false;
-};
-
-StackItem.prototype.isMathMLTextIntegrationPoint = function() {
- if (this.namespaceURI === "http://www.w3.org/1998/Math/MathML") {
- return this.localName === "mi"
- || this.localName === "mo"
- || this.localName === "mn"
- || this.localName === "ms"
- || this.localName === "mtext";
- }
- return false;
-};
-
-exports.StackItem = StackItem;
+var SpecialElements = {
+ "http://www.w3.org/1999/xhtml": [
+ 'address',
+ 'applet',
+ 'area',
+ 'article',
+ 'aside',
+ 'base',
+ 'basefont',
+ 'bgsound',
+ 'blockquote',
+ 'body',
+ 'br',
+ 'button',
+ 'caption',
+ 'center',
+ 'col',
+ 'colgroup',
+ 'dd',
+ 'details',
+ 'dir',
+ 'div',
+ 'dl',
+ 'dt',
+ 'embed',
+ 'fieldset',
+ 'figcaption',
+ 'figure',
+ 'footer',
+ 'form',
+ 'frame',
+ 'frameset',
+ 'h1',
+ 'h2',
+ 'h3',
+ 'h4',
+ 'h5',
+ 'h6',
+ 'head',
+ 'header',
+ 'hgroup',
+ 'hr',
+ 'html',
+ 'iframe',
+ 'img',
+ 'input',
+ 'isindex',
+ 'li',
+ 'link',
+ 'listing',
+ 'main',
+ 'marquee',
+ 'menu',
+ 'menuitem',
+ 'meta',
+ 'nav',
+ 'noembed',
+ 'noframes',
+ 'noscript',
+ 'object',
+ 'ol',
+ 'p',
+ 'param',
+ 'plaintext',
+ 'pre',
+ 'script',
+ 'section',
+ 'select',
+ 'source',
+ 'style',
+ 'summary',
+ 'table',
+ 'tbody',
+ 'td',
+ 'textarea',
+ 'tfoot',
+ 'th',
+ 'thead',
+ 'title',
+ 'tr',
+ 'track',
+ 'ul',
+ 'wbr',
+ 'xmp'
+ ],
+ "http://www.w3.org/1998/Math/MathML": [
+ 'mi',
+ 'mo',
+ 'mn',
+ 'ms',
+ 'mtext',
+ 'annotation-xml'
+ ],
+ "http://www.w3.org/2000/svg": [
+ 'foreignObject',
+ 'desc',
+ 'title'
+ ]
+};
+
+
+function StackItem(namespaceURI, localName, attributes, node) {
+ this.localName = localName;
+ this.namespaceURI = namespaceURI;
+ this.attributes = attributes;
+ this.node = node;
+}
+
+// http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#special
+StackItem.prototype.isSpecial = function() {
+ return this.namespaceURI in SpecialElements &&
+ SpecialElements[this.namespaceURI].indexOf(this.localName) > -1;
+};
+
+StackItem.prototype.isFosterParenting = function() {
+ if (this.namespaceURI === "http://www.w3.org/1999/xhtml") {
+ return this.localName === 'table' ||
+ this.localName === 'tbody' ||
+ this.localName === 'tfoot' ||
+ this.localName === 'thead' ||
+ this.localName === 'tr';
+ }
+ return false;
+};
+
+StackItem.prototype.isNumberedHeader = function() {
+ if (this.namespaceURI === "http://www.w3.org/1999/xhtml") {
+ return this.localName === 'h1' ||
+ this.localName === 'h2' ||
+ this.localName === 'h3' ||
+ this.localName === 'h4' ||
+ this.localName === 'h5' ||
+ this.localName === 'h6';
+ }
+ return false;
+};
+
+StackItem.prototype.isForeign = function() {
+ return this.namespaceURI != "http://www.w3.org/1999/xhtml";
+};
+
+function getAttribute(item, name) {
+ for (var i = 0; i < item.attributes.length; i++) {
+ if (item.attributes[i].nodeName == name)
+ return item.attributes[i].nodeValue;
+ }
+ return null;
+}
+
+StackItem.prototype.isHtmlIntegrationPoint = function() {
+ if (this.namespaceURI === "http://www.w3.org/1998/Math/MathML") {
+ if (this.localName !== "annotation-xml")
+ return false;
+ var encoding = getAttribute(this, 'encoding');
+ if (!encoding)
+ return false;
+ encoding = encoding.toLowerCase();
+ return encoding === "text/html" || encoding === "application/xhtml+xml";
+ }
+ if (this.namespaceURI === "http://www.w3.org/2000/svg") {
+ return this.localName === "foreignObject"
+ || this.localName === "desc"
+ || this.localName === "title";
+ }
+ return false;
+};
+
+StackItem.prototype.isMathMLTextIntegrationPoint = function() {
+ if (this.namespaceURI === "http://www.w3.org/1998/Math/MathML") {
+ return this.localName === "mi"
+ || this.localName === "mo"
+ || this.localName === "mn"
+ || this.localName === "ms"
+ || this.localName === "mtext";
+ }
+ return false;
+};
+
+exports.StackItem = StackItem;
},
{}],
@@ -2351,3076 +2351,3076 @@ exports.Tokenizer = Tokenizer;
},
{"./EntityParser":2,"./InputStream":3}],
6:[function(_dereq_,module,exports){
-var assert = _dereq_('assert');
-
-var messages = _dereq_('./messages.json');
-var constants = _dereq_('./constants');
-
-var EventEmitter = _dereq_('events').EventEmitter;
-
-var Tokenizer = _dereq_('./Tokenizer').Tokenizer;
-var ElementStack = _dereq_('./ElementStack').ElementStack;
-var StackItem = _dereq_('./StackItem').StackItem;
-
-var Marker = {};
-
-function isWhitespace(ch) {
- return ch === " " || ch === "\n" || ch === "\t" || ch === "\r" || ch === "\f";
-}
-
-function isWhitespaceOrReplacementCharacter(ch) {
- return isWhitespace(ch) || ch === '\uFFFD';
-}
-
-function isAllWhitespace(characters) {
- for (var i = 0; i < characters.length; i++) {
- var ch = characters[i];
- if (!isWhitespace(ch))
- return false;
- }
- return true;
-}
-
-function isAllWhitespaceOrReplacementCharacters(characters) {
- for (var i = 0; i < characters.length; i++) {
- var ch = characters[i];
- if (!isWhitespaceOrReplacementCharacter(ch))
- return false;
- }
- return true;
-}
-
-function getAttribute(node, name) {
- for (var i = 0; i < node.attributes.length; i++) {
- var attribute = node.attributes[i];
- if (attribute.nodeName === name) {
- return attribute;
- }
- }
- return null;
-}
-
-function CharacterBuffer(characters) {
- this.characters = characters;
- this.current = 0;
- this.end = this.characters.length;
-}
-
-CharacterBuffer.prototype.skipAtMostOneLeadingNewline = function() {
- if (this.characters[this.current] === '\n')
- this.current++;
-};
-
-CharacterBuffer.prototype.skipLeadingWhitespace = function() {
- while (isWhitespace(this.characters[this.current])) {
- if (++this.current == this.end)
- return;
- }
-};
-
-CharacterBuffer.prototype.skipLeadingNonWhitespace = function() {
- while (!isWhitespace(this.characters[this.current])) {
- if (++this.current == this.end)
- return;
- }
-};
-
-CharacterBuffer.prototype.takeRemaining = function() {
- return this.characters.substring(this.current);
-};
-
-CharacterBuffer.prototype.takeLeadingWhitespace = function() {
- var start = this.current;
- this.skipLeadingWhitespace();
- if (start === this.current)
- return "";
- return this.characters.substring(start, this.current - start);
-};
-
-Object.defineProperty(CharacterBuffer.prototype, 'length', {
- get: function(){
- return this.end - this.current;
- }
-});
-
-/**
- *
- * @constructor
- */
-function TreeBuilder() {
- this.tokenizer = null;
- this.errorHandler = null;
- this.scriptingEnabled = false;
- this.document = null;
- this.head = null;
- this.form = null;
- this.openElements = new ElementStack();
- this.activeFormattingElements = [];
- this.insertionMode = null;
- this.insertionModeName = "";
- this.originalInsertionMode = "";
- this.inQuirksMode = false; // TODO quirks mode
- this.compatMode = "no quirks";
- this.framesetOk = true;
- this.redirectAttachToFosterParent = false;
- this.selfClosingFlagAcknowledged = false;
- this.context = "";
- this.pendingTableCharacters = [];
- this.shouldSkipLeadingNewline = false;
-
- var tree = this;
- var modes = this.insertionModes = {};
- modes.base = {
- end_tag_handlers: {"-default": 'endTagOther'},
- start_tag_handlers: {"-default": 'startTagOther'},
- processEOF: function() {
- tree.generateImpliedEndTags();
- if (tree.openElements.length > 2) {
- tree.parseError('expected-closing-tag-but-got-eof');
- } else if (tree.openElements.length == 2 &&
- tree.openElements.item(1).localName != 'body') {
- // This happens for framesets or something?
- tree.parseError('expected-closing-tag-but-got-eof');
- } else if (tree.context && tree.openElements.length > 1) {
- // XXX This is not what the specification says. Not sure what to do here.
- //tree.parseError('eof-in-innerhtml');
- }
- },
- processComment: function(data) {
- // For most phases the following is forceQuirks. Where it's not it will be
- // overridden.
- tree.insertComment(data, tree.currentStackItem().node);
- },
- processDoctype: function(name, publicId, systemId, forceQuirks) {
- tree.parseError('unexpected-doctype');
- },
- processStartTag: function(name, attributes, selfClosing) {
- if (this[this.start_tag_handlers[name]]) {
- this[this.start_tag_handlers[name]](name, attributes, selfClosing);
- } else if (this[this.start_tag_handlers["-default"]]) {
- this[this.start_tag_handlers["-default"]](name, attributes, selfClosing);
- } else {
- throw(new Error("No handler found for "+name));
- }
- },
- processEndTag: function(name) {
- if (this[this.end_tag_handlers[name]]) {
- this[this.end_tag_handlers[name]](name);
- } else if (this[this.end_tag_handlers["-default"]]) {
- this[this.end_tag_handlers["-default"]](name);
- } else {
- throw(new Error("No handler found for "+name));
- }
- },
- startTagHtml: function(name, attributes) {
- modes.inBody.startTagHtml(name, attributes);
- }
- };
-
- modes.initial = Object.create(modes.base);
-
- modes.initial.processEOF = function() {
- tree.parseError("expected-doctype-but-got-eof");
- this.anythingElse();
- tree.insertionMode.processEOF();
- };
-
- modes.initial.processComment = function(data) {
- tree.insertComment(data, tree.document);
- };
-
- modes.initial.processDoctype = function(name, publicId, systemId, forceQuirks) {
- tree.insertDoctype(name || '', publicId || '', systemId || '');
-
- if (forceQuirks || name != 'html' || (publicId != null && ([
- "+//silmaril//dtd html pro v0r11 19970101//",
- "-//advasoft ltd//dtd html 3.0 aswedit + extensions//",
- "-//as//dtd html 3.0 aswedit + extensions//",
- "-//ietf//dtd html 2.0 level 1//",
- "-//ietf//dtd html 2.0 level 2//",
- "-//ietf//dtd html 2.0 strict level 1//",
- "-//ietf//dtd html 2.0 strict level 2//",
- "-//ietf//dtd html 2.0 strict//",
- "-//ietf//dtd html 2.0//",
- "-//ietf//dtd html 2.1e//",
- "-//ietf//dtd html 3.0//",
- "-//ietf//dtd html 3.0//",
- "-//ietf//dtd html 3.2 final//",
- "-//ietf//dtd html 3.2//",
- "-//ietf//dtd html 3//",
- "-//ietf//dtd html level 0//",
- "-//ietf//dtd html level 0//",
- "-//ietf//dtd html level 1//",
- "-//ietf//dtd html level 1//",
- "-//ietf//dtd html level 2//",
- "-//ietf//dtd html level 2//",
- "-//ietf//dtd html level 3//",
- "-//ietf//dtd html level 3//",
- "-//ietf//dtd html strict level 0//",
- "-//ietf//dtd html strict level 0//",
- "-//ietf//dtd html strict level 1//",
- "-//ietf//dtd html strict level 1//",
- "-//ietf//dtd html strict level 2//",
- "-//ietf//dtd html strict level 2//",
- "-//ietf//dtd html strict level 3//",
- "-//ietf//dtd html strict level 3//",
- "-//ietf//dtd html strict//",
- "-//ietf//dtd html strict//",
- "-//ietf//dtd html strict//",
- "-//ietf//dtd html//",
- "-//ietf//dtd html//",
- "-//ietf//dtd html//",
- "-//metrius//dtd metrius presentational//",
- "-//microsoft//dtd internet explorer 2.0 html strict//",
- "-//microsoft//dtd internet explorer 2.0 html//",
- "-//microsoft//dtd internet explorer 2.0 tables//",
- "-//microsoft//dtd internet explorer 3.0 html strict//",
- "-//microsoft//dtd internet explorer 3.0 html//",
- "-//microsoft//dtd internet explorer 3.0 tables//",
- "-//netscape comm. corp.//dtd html//",
- "-//netscape comm. corp.//dtd strict html//",
- "-//o'reilly and associates//dtd html 2.0//",
- "-//o'reilly and associates//dtd html extended 1.0//",
- "-//spyglass//dtd html 2.0 extended//",
- "-//sq//dtd html 2.0 hotmetal + extensions//",
- "-//sun microsystems corp.//dtd hotjava html//",
- "-//sun microsystems corp.//dtd hotjava strict html//",
- "-//w3c//dtd html 3 1995-03-24//",
- "-//w3c//dtd html 3.2 draft//",
- "-//w3c//dtd html 3.2 final//",
- "-//w3c//dtd html 3.2//",
- "-//w3c//dtd html 3.2s draft//",
- "-//w3c//dtd html 4.0 frameset//",
- "-//w3c//dtd html 4.0 transitional//",
- "-//w3c//dtd html experimental 19960712//",
- "-//w3c//dtd html experimental 970421//",
- "-//w3c//dtd w3 html//",
- "-//w3o//dtd w3 html 3.0//",
- "-//webtechs//dtd mozilla html 2.0//",
- "-//webtechs//dtd mozilla html//",
- "html"
- ].some(publicIdStartsWith)
- || [
- "-//w3o//dtd w3 html strict 3.0//en//",
- "-/w3c/dtd html 4.0 transitional/en",
- "html"
- ].indexOf(publicId.toLowerCase()) > -1
- || (systemId == null && [
- "-//w3c//dtd html 4.01 transitional//",
- "-//w3c//dtd html 4.01 frameset//"
- ].some(publicIdStartsWith)))
- )
- || (systemId != null && (systemId.toLowerCase() == "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd"))
- ) {
- tree.compatMode = "quirks";
- tree.parseError("quirky-doctype");
- } else if (publicId != null && ([
- "-//w3c//dtd xhtml 1.0 transitional//",
- "-//w3c//dtd xhtml 1.0 frameset//"
- ].some(publicIdStartsWith)
- || (systemId != null && [
- "-//w3c//dtd html 4.01 transitional//",
- "-//w3c//dtd html 4.01 frameset//"
- ].indexOf(publicId.toLowerCase()) > -1))
- ) {
- tree.compatMode = "limited quirks";
- tree.parseError("almost-standards-doctype");
- } else {
- if ((publicId == "-//W3C//DTD HTML 4.0//EN" && (systemId == null || systemId == "http://www.w3.org/TR/REC-html40/strict.dtd"))
- || (publicId == "-//W3C//DTD HTML 4.01//EN" && (systemId == null || systemId == "http://www.w3.org/TR/html4/strict.dtd"))
- || (publicId == "-//W3C//DTD XHTML 1.0 Strict//EN" && (systemId == "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"))
- || (publicId == "-//W3C//DTD XHTML 1.1//EN" && (systemId == "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"))
- ) {
- // warning
- //tree.warn("obsolete-doctype");
- } else if (!((systemId == null || systemId == "about:legacy-compat") && publicId == null)) {
- tree.parseError("unknown-doctype");
- }
- }
- tree.setInsertionMode('beforeHTML');
- function publicIdStartsWith(string) {
- return publicId.toLowerCase().indexOf(string) === 0;
- }
- };
-
- modes.initial.processCharacters = function(buffer) {
- buffer.skipLeadingWhitespace();
- if (!buffer.length)
- return;
- tree.parseError('expected-doctype-but-got-chars');
- this.anythingElse();
- tree.insertionMode.processCharacters(buffer);
- };
-
- modes.initial.processStartTag = function(name, attributes, selfClosing) {
- tree.parseError('expected-doctype-but-got-start-tag', {name: name});
- this.anythingElse();
- tree.insertionMode.processStartTag(name, attributes, selfClosing);
- };
-
- modes.initial.processEndTag = function(name) {
- tree.parseError('expected-doctype-but-got-end-tag', {name: name});
- this.anythingElse();
- tree.insertionMode.processEndTag(name);
- };
-
- modes.initial.anythingElse = function() {
- tree.compatMode = 'quirks';
- tree.setInsertionMode('beforeHTML');
- };
-
- modes.beforeHTML = Object.create(modes.base);
-
- modes.beforeHTML.start_tag_handlers = {
- html: 'startTagHtml',
- '-default': 'startTagOther'
- };
-
- modes.beforeHTML.processEOF = function() {
- this.anythingElse();
- tree.insertionMode.processEOF();
- };
-
- modes.beforeHTML.processComment = function(data) {
- tree.insertComment(data, tree.document);
- };
-
- modes.beforeHTML.processCharacters = function(buffer) {
- buffer.skipLeadingWhitespace();
- if (!buffer.length)
- return;
- this.anythingElse();
- tree.insertionMode.processCharacters(buffer);
- };
-
- modes.beforeHTML.startTagHtml = function(name, attributes, selfClosing) {
- tree.insertHtmlElement(attributes);
- tree.setInsertionMode('beforeHead');
- };
-
- modes.beforeHTML.startTagOther = function(name, attributes, selfClosing) {
- this.anythingElse();
- tree.insertionMode.processStartTag(name, attributes, selfClosing);
- };
-
- modes.beforeHTML.processEndTag = function(name) {
- this.anythingElse();
- tree.insertionMode.processEndTag(name);
- };
-
- modes.beforeHTML.anythingElse = function() {
- tree.insertHtmlElement();
- tree.setInsertionMode('beforeHead');
- };
-
- modes.afterAfterBody = Object.create(modes.base);
-
- modes.afterAfterBody.start_tag_handlers = {
- html: 'startTagHtml',
- '-default': 'startTagOther'
- };
-
- modes.afterAfterBody.processComment = function(data) {
- tree.insertComment(data, tree.document);
- };
-
- modes.afterAfterBody.processDoctype = function(data) {
- modes.inBody.processDoctype(data);
- };
-
- modes.afterAfterBody.startTagHtml = function(data, attributes) {
- modes.inBody.startTagHtml(data, attributes);
- };
-
- modes.afterAfterBody.startTagOther = function(name, attributes, selfClosing) {
- tree.parseError('unexpected-start-tag', {name: name});
- tree.setInsertionMode('inBody');
- tree.insertionMode.processStartTag(name, attributes, selfClosing);
- };
-
- modes.afterAfterBody.endTagOther = function(name) {
- tree.parseError('unexpected-end-tag', {name: name});
- tree.setInsertionMode('inBody');
- tree.insertionMode.processEndTag(name);
- };
-
- modes.afterAfterBody.processCharacters = function(data) {
- if (!isAllWhitespace(data.characters)) {
- tree.parseError('unexpected-char-after-body');
- tree.setInsertionMode('inBody');
- return tree.insertionMode.processCharacters(data);
- }
- modes.inBody.processCharacters(data);
- };
-
- modes.afterBody = Object.create(modes.base);
-
- modes.afterBody.end_tag_handlers = {
- html: 'endTagHtml',
- '-default': 'endTagOther'
- };
-
- modes.afterBody.processComment = function(data) {
- // This is needed because data is to be appended to the html element here
- // and not to whatever is currently open.
- tree.insertComment(data, tree.openElements.rootNode);
- };
-
- modes.afterBody.processCharacters = function(data) {
- if (!isAllWhitespace(data.characters)) {
- tree.parseError('unexpected-char-after-body');
- tree.setInsertionMode('inBody');
- return tree.insertionMode.processCharacters(data);
- }
- modes.inBody.processCharacters(data);
- };
-
- modes.afterBody.processStartTag = function(name, attributes, selfClosing) {
- tree.parseError('unexpected-start-tag-after-body', {name: name});
- tree.setInsertionMode('inBody');
- tree.insertionMode.processStartTag(name, attributes, selfClosing);
- };
-
- modes.afterBody.endTagHtml = function(name) {
- if (tree.context) {
- tree.parseError('end-html-in-innerhtml');
- } else {
- // XXX This may need to be done, not sure
- // Don't set last_phase to the current phase but to the inBody phase
- // instead. No need for extra parseErrors if there's something after
- //