r111836 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111835‎ | r111836 | r111837 >
Date:17:28, 18 February 2012
Author:au
Status:ok
Tags:
Comment:
* 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.
Modified paths:
  • /trunk/extensions/VisualEditor/tests/parser/__patched-html5-parser.js (added) (history)
  • /trunk/extensions/VisualEditor/tests/parser/parserTests.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/tests/parser/__patched-html5-parser.js
@@ -0,0 +1,43 @@
 2+module.exports = function (HTML5) {
 3+ var htmlparser = new HTML5.Parser();
 4+ htmlparser.tree.elementInActiveFormattingElements = function(name) {
 5+ var els = this.activeFormattingElements;
 6+ for(var i = els.length - 1; i >= 0; i--) {
 7+ if(els[i].type == HTML5.Marker.type) break;
 8+ if(els[i].tagName.toLowerCase() == name) return els[i];
 9+ }
 10+ return false;
 11+ };
 12+ htmlparser.tree.reconstructActiveFormattingElements = function() {
 13+ // Within this algorithm the order of steps decribed in the specification
 14+ // is not quite the same as the order of steps in the code. It should still
 15+ // do the same though.
 16+
 17+ // Step 1: stop if there's nothing to do
 18+ if(this.activeFormattingElements.length == 0) return;
 19+
 20+ // Step 2 and 3: start with the last element
 21+ var i = this.activeFormattingElements.length - 1;
 22+ var entry = this.activeFormattingElements[i];
 23+ if(entry.type == HTML5.Marker.type || this.open_elements.indexOf(entry) != -1) return;
 24+
 25+ while(entry.type != HTML5.Marker.type && this.open_elements.indexOf(entry) == -1) {
 26+ i -= 1;
 27+ entry = this.activeFormattingElements[i];
 28+ if(!entry) break;
 29+ }
 30+
 31+ while(true) {
 32+ i += 1;
 33+ var clone = this.activeFormattingElements[i].cloneNode();
 34+
 35+ var element = this.insert_element(clone.tagName, clone.attributes);
 36+
 37+ this.activeFormattingElements[i] = element;
 38+
 39+ if(element == this.activeFormattingElements.last()) break;
 40+ }
 41+ };
 42+
 43+ return htmlparser;
 44+};
Index: trunk/extensions/VisualEditor/tests/parser/parserTests.js
@@ -186,7 +186,9 @@
187187
188188 //this.htmlwindow = jsdom.jsdom(null, null, {parser: HTML5}).createWindow();
189189 //this.htmlparser = new HTML5.Parser({document: this.htmlwindow.document});
190 - this.htmlparser = new HTML5.Parser();
 190+ //this.htmlparser = new HTML5.Parser()
 191+ // Use a patched version until https://github.com/aredridel/html5/issues/44 is merged
 192+ this.htmlparser = require('./__patched-html5-parser')(HTML5);
191193
192194 // Test statistics
193195 this.passedTests = 0;

Status & tagging log