mediawiki-extensions-Visual.../tests/parser/__patched-html5-parser.js
au 0ca9b00100 * Convert __patched-html-parser to .coffee.
Note that the compiled .js file (generated by "make"/"make test")
  is still under version control so folks can work on the project
  even without a running "coffee" command in PATH.

  Also updated README to mention coffee-script and "make test".
2012-02-18 18:54:12 +00:00

39 lines
1.3 KiB
JavaScript

module.exports = function(HTML5) {
var htmlparser;
htmlparser = new HTML5.Parser;
htmlparser.tree.elementInActiveFormattingElements = function(name) {
var els, i;
els = this.activeFormattingElements;
i = els.length - 1;
while (i >= 0) {
if (els[i].type === HTML5.Marker.type) break;
if (els[i].tagName.toLowerCase() === name) return els[i];
i--;
}
return false;
};
htmlparser.tree.reconstructActiveFormattingElements = function() {
var clone, element, entry, i;
if (this.activeFormattingElements.length === 0) return;
i = this.activeFormattingElements.length - 1;
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;
clone = this.activeFormattingElements[i].cloneNode();
element = this.insert_element(clone.tagName, clone.attributes);
this.activeFormattingElements[i] = element;
if (element === this.activeFormattingElements.last()) break;
}
};
return htmlparser;
};