http://www.mediawiki.org/wiki/Special:Code/MediaWiki/93943
Revision: 93943 Author: inez Date: 2011-08-05 00:34:00 +0000 (Fri, 05 Aug 2011) Log Message: ----------- Refactoring for getWikiDomLines Modified Paths: -------------- trunk/parsers/wikidom/lib/es/es.Content.js Modified: trunk/parsers/wikidom/lib/es/es.Content.js =================================================================== --- trunk/parsers/wikidom/lib/es/es.Content.js 2011-08-05 00:33:03 UTC (rev 93942) +++ trunk/parsers/wikidom/lib/es/es.Content.js 2011-08-05 00:34:00 UTC (rev 93943) @@ -638,20 +638,11 @@ * * @method */ -es.Content.prototype.handleAnnotation = function( bias, annotation, stack, index ) { - if ( bias === 'open' ) { - var annotation = es.Content.copyObject( annotation ); - annotation.range = { start: index }; - stack.push( annotation ); - } else if ( bias === 'close' ) { - for ( var i = stack.length - 1; i >= 0; i-- ) { - if ( stack[i].type === annotation.type ) { - if ( es.Content.compareObjects( stack[i].data, annotation.data ) ) { - stack[i].range.end = index; - break; - } - } - } +es.Content.prototype.closeAnnotations = function( stack, index ) { + for ( var i = 0; i < stack.length; i++) { + if ( !stack[i].range.end ) { + stack[i].range.end = index; + } } }; @@ -666,68 +657,63 @@ right, leftPlain, rightPlain, - i, j, // iterators + i, j, k, // iterators lines = [], line = null, offset = 0; for ( i = 0; i < this.data.length; i++ ) { + if ( line == null ) { line = { text : '', annotations : [] }; } + right = this.data[i]; leftPlain = typeof left === 'string'; rightPlain = typeof right === 'string'; + if ( rightPlain && right == "\n" ) { - if ( left ) { - for ( j = 1; j < left.length; j++ ) { - this.handleAnnotation( 'close', left[j], line.annotations, i - offset ); - } - } - if ( !line.annotations.length ) { - delete line.annotations; - } + this.closeAnnotations( line.annotations, i - offset ); lines.push(line); line = null; offset = i + 1; left = ''; continue; } + if ( !leftPlain && rightPlain ) { // [formatted][plain] pair, close any annotations for left - for ( j = 1; j < left.length; j++ ) { - this.handleAnnotation( 'close', left[j], line.annotations, i - offset ); - } - } else if ( leftPlain && !rightPlain ) { - // [plain][formatted] pair, open any annotations for right - for ( j = 1; j < right.length; j++ ) { - this.handleAnnotation( 'open', right[j], line.annotations, i - offset ); - } - } else if ( !leftPlain && !rightPlain ) { - // [formatted][formatted] pair, open/close any differences - for ( j = 1; j < left.length; j++ ) { - if ( this.indexOfAnnotation( i , left[j], true ) === -1 ) { - this.handleAnnotation( 'close', left[j], line.annotations, i - offset ); + this.closeAnnotations( line.annotations, i - offset ); + } else if ( !rightPlain ) { + // [plain|formatted][formatted] + if ( !leftPlain ) { + for ( j = 1; j < left.length; j++ ) { + if ( this.indexOfAnnotation( i , left[j], true ) === -1 ) { + for ( k = line.annotations.length - 1; k >= 0; k-- ) { + if ( line.annotations[k].type === left[j].type ) { + if ( es.Content.compareObjects( line.annotations[k].data, left[j].data ) ) { + line.annotations[k].range.end = i - offset; + break; + } + } + } + } } } for ( j = 1; j < right.length; j++ ) { - if ( this.indexOfAnnotation( i - 1, right[j], true ) === -1 ) { - this.handleAnnotation( 'open', right[j], line.annotations, i - offset ); + if ( leftPlain || this.indexOfAnnotation( i - 1, right[j], true ) === -1 ) { + var annotation = es.Content.copyObject( right[j] ); + annotation.range = { start: i - offset }; + line.annotations.push( annotation ); } } } line.text += rightPlain ? right : right[0]; left = right; } + if ( line != null ) { - if ( right ) { - for ( j = 1; j < right.length; j++ ) { - this.handleAnnotation( 'close', right[j], line.annotations, i - offset ); - } - } - if ( !line.annotations.length ) { - delete line.annotations; - } + this.closeAnnotations( line.annotations, i - offset ); lines.push( line ); } return lines; _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs