mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
* 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:
parent
4d80b8daa8
commit
0360e62da7
Notes:
Gabriel Wicke
2012-02-27 16:40:01 +00:00
43
tests/parser/__patched-html5-parser.js
Normal file
43
tests/parser/__patched-html5-parser.js
Normal 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;
|
||||
};
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue