r93924 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93923‎ | r93924 | r93925 >
Date:22:15, 4 August 2011
Author:inez
Status:deferred
Tags:
Comment:
Fix bug in render function - tags at the end of content were never closed (it was not really affecting user experience since browser was closing those tags anyway)
Fix same bug in getWikiDomLines
Modified paths:
  • /trunk/parsers/wikidom/lib/es/es.Content.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.Content.js
@@ -587,10 +587,16 @@
588588 }
589589 }
590590 }
 591+
591592 out += right[0] in es.Content.htmlCharacters
592593 ? es.Content.htmlCharacters[right[0]] : right[0];
593594 left = right;
594595 }
 596+ if ( !rightPlain ) {
 597+ for ( j = 1; j < right.length; j++ ) {
 598+ out += es.Content.renderAnnotation( 'close', right[j], stack );
 599+ }
 600+ }
595601 return out;
596602 };
597603
@@ -626,6 +632,23 @@
627633 return new es.Range( start, end );
628634 };
629635
 636+es.Content.prototype.handleAnnotation = function( bias, annotation, stack, index ) {
 637+ if ( bias === 'open' ) {
 638+ var annotation = es.Content.copyObject( annotation );
 639+ annotation.range = { start: index };
 640+ stack.push( annotation );
 641+ } else if ( bias === 'close' ) {
 642+ for ( var i = 0; i < stack.length; i++ ) {
 643+ if ( stack[i].type === annotation.type ) {
 644+ if ( es.Content.compareObjects( stack[i].data, annotation.data ) ) {
 645+ stack[i].range.end = index;
 646+ break;
 647+ }
 648+ }
 649+ }
 650+ }
 651+};
 652+
630653 /**
631654 * Get WikiDom line objects from content.
632655 *
@@ -633,20 +656,18 @@
634657 * @returns {Array} List of WikiDom line objects
635658 */
636659 es.Content.prototype.getWikiDomLines = function() {
637 - var lines = [],
638 - right = '',
 660+ var left = '',
 661+ right,
 662+ leftPlain,
639663 rightPlain,
640 - left = '',
641 - leftPlain,
642 - line,
643 - offset = 0,
644 - i, j, k;
 664+ i, j, // iterators
 665+ lines = [],
 666+ line = null,
 667+ offset = 0;
 668+
645669 for ( i = 0; i < this.data.length; i++ ) {
646670 if ( line == null ) {
647 - line = {
648 - text : '',
649 - annotations : []
650 - };
 671+ line = { text : '', annotations : [] };
651672 }
652673 right = this.data[i];
653674 leftPlain = typeof left === 'string';
@@ -658,37 +679,41 @@
659680 left = '';
660681 continue;
661682 }
662 - if ( !leftPlain ) {
 683+ if ( !leftPlain && rightPlain ) {
 684+ // [formatted][plain] pair, close any annotations for left
663685 for ( j = 1; j < left.length; j++ ) {
664 - for ( k = line.annotations.length - 1; k >= 0; k-- ) {
665 - if ( left[j].type === line.annotations[k].type ) {
666 - if ( es.Content.compareObjects( left[j].data, line.annotations[k].data ) ) {
667 - line.annotations[k].range.end = i - offset;
668 - break;
669 - }
670 - }
 686+ this.handleAnnotation( 'close', left[j], line.annotations, i - offset );
 687+ }
 688+ } else if ( leftPlain && !rightPlain ) {
 689+ // [plain][formatted] pair, open any annotations for right
 690+ for ( j = 1; j < right.length; j++ ) {
 691+ this.handleAnnotation( 'open', right[j], line.annotations, i - offset );
 692+ }
 693+ } else if ( !leftPlain && !rightPlain ) {
 694+ // [formatted][formatted] pair, open/close any differences
 695+ for ( j = 1; j < left.length; j++ ) {
 696+ if ( right.indexOf( left[j] ) === -1 ) {
 697+ this.handleAnnotation( 'close', left[j], line.annotations, i - offset );
671698 }
672699 }
673 - }
674 - if ( !rightPlain ) {
675700 for ( j = 1; j < right.length; j++ ) {
676 - if ( leftPlain || this.indexOfAnnotation( i - 1, right[j], true ) === -1 ) {
677 - var annotation = es.Content.copyObject( right[j] );
678 - annotation.range = {
679 - start : i - offset,
680 - end : i + 1 - offset
681 - };
682 - line.annotations.push( annotation );
 701+ if ( left.indexOf( right[j] ) === -1 ) {
 702+ this.handleAnnotation( 'open', right[j], line.annotations, i - offset );
683703 }
684704 }
685705 }
686706 line.text += rightPlain ? right : right[0];
687 - left = right;
 707+ left = right;
688708 }
689709 if ( line != null ) {
 710+ if ( right ) {
 711+ for ( j = 1; j < right.length; j++ ) {
 712+ this.handleAnnotation( 'close', right[j], line.annotations, i - offset );
 713+ }
 714+ }
690715 lines.push(line);
691716 }
692 - return lines;
 717+ return lines;
693718 };
694719
695720 /* Inheritance */

Status & tagging log