https://www.mediawiki.org/wiki/Special:Code/MediaWiki/111836

Revision: 111836
Author:   au
Date:     2012-02-18 17:28:35 +0000 (Sat, 18 Feb 2012)
Log Message:
-----------
* 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/parserTests.js

Added Paths:
-----------
    trunk/extensions/VisualEditor/tests/parser/__patched-html5-parser.js

Added: trunk/extensions/VisualEditor/tests/parser/__patched-html5-parser.js
===================================================================
--- trunk/extensions/VisualEditor/tests/parser/__patched-html5-parser.js        
                        (rev 0)
+++ trunk/extensions/VisualEditor/tests/parser/__patched-html5-parser.js        
2012-02-18 17:28:35 UTC (rev 111836)
@@ -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;
+};

Modified: trunk/extensions/VisualEditor/tests/parser/parserTests.js
===================================================================
--- trunk/extensions/VisualEditor/tests/parser/parserTests.js   2012-02-18 
17:11:39 UTC (rev 111835)
+++ trunk/extensions/VisualEditor/tests/parser/parserTests.js   2012-02-18 
17:28:35 UTC (rev 111836)
@@ -186,7 +186,9 @@
 
        //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;


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to