* Locally apply the HTML5.Marker.type patch.

This is needed until https://github.com/aredridel/html5/issues/44
  is merged into the upstream "html5" module.
This commit is contained in:
au 2012-02-18 17:28:35 +00:00
parent 4d80b8daa8
commit 0360e62da7
Notes: Gabriel Wicke 2012-02-27 16:40:01 +00:00
2 changed files with 46 additions and 1 deletions

View file

@ -0,0 +1,43 @@
module.exports = function (HTML5) {
var htmlparser = new HTML5.Parser();
htmlparser.tree.elementInActiveFormattingElements = function(name) {
var els = this.activeFormattingElements;
for(var i = els.length - 1; i >= 0; i--) {
if(els[i].type == HTML5.Marker.type) break;
if(els[i].tagName.toLowerCase() == name) return els[i];
}
return false;
};
htmlparser.tree.reconstructActiveFormattingElements = function() {
// Within this algorithm the order of steps decribed in the specification
// is not quite the same as the order of steps in the code. It should still
// do the same though.
// Step 1: stop if there's nothing to do
if(this.activeFormattingElements.length == 0) return;
// Step 2 and 3: start with the last element
var i = this.activeFormattingElements.length - 1;
var entry = this.activeFormattingElements[i];
if(entry.type == HTML5.Marker.type || this.open_elements.indexOf(entry) != -1) return;
while(entry.type != HTML5.Marker.type && this.open_elements.indexOf(entry) == -1) {
i -= 1;
entry = this.activeFormattingElements[i];
if(!entry) break;
}
while(true) {
i += 1;
var clone = this.activeFormattingElements[i].cloneNode();
var element = this.insert_element(clone.tagName, clone.attributes);
this.activeFormattingElements[i] = element;
if(element == this.activeFormattingElements.last()) break;
}
};
return htmlparser;
};

View file

@ -186,7 +186,9 @@ function ParserTests () {
//this.htmlwindow = jsdom.jsdom(null, null, {parser: HTML5}).createWindow();
//this.htmlparser = new HTML5.Parser({document: this.htmlwindow.document});
this.htmlparser = new HTML5.Parser();
//this.htmlparser = new HTML5.Parser()
// Use a patched version until https://github.com/aredridel/html5/issues/44 is merged
this.htmlparser = require('./__patched-html5-parser')(HTML5);
// Test statistics
this.passedTests = 0;