Index: trunk/parsers/wikidom/lib/es/es.Content.js |
— | — | @@ -658,23 +658,29 @@ |
659 | 659 | * |
660 | 660 | * @method |
661 | 661 | */ |
662 | | -es.Content.prototype.handleAnnotation = function( bias, stack, index, annotation ) { |
| 662 | +es.Content.prototype.handleAnnotation = function( bias, line, index, annotation ) { |
663 | 663 | if ( bias === 'open' ) { |
664 | 664 | var newAnnotation = es.copyObject( annotation ); |
665 | 665 | newAnnotation.range = { |
666 | 666 | start: index |
667 | 667 | }; |
668 | | - stack.push( newAnnotation ); |
| 668 | + if ( !line.annotations ) { |
| 669 | + line.annotations = [ newAnnotation ]; |
| 670 | + } else { |
| 671 | + line.annotations.push( newAnnotation ); |
| 672 | + } |
669 | 673 | } else { |
670 | | - for ( var i = stack.length - 1; i >= 0; i-- ) { |
671 | | - if ( !stack[i].range.end ) { |
672 | | - if ( annotation ) { |
673 | | - if ( stack[i].type === annotation.type && es.compareObjects( stack[i].data, annotation.data ) ) { |
674 | | - stack[i].range.end = index; |
675 | | - break; |
| 674 | + if ( line.annotations ) { |
| 675 | + for ( var i = line.annotations.length - 1; i >= 0; i-- ) { |
| 676 | + if ( !line.annotations[i].range.end ) { |
| 677 | + if ( annotation ) { |
| 678 | + if ( line.annotations[i].type === annotation.type && es.compareObjects( line.annotations[i].data, annotation.data ) ) { |
| 679 | + line.annotations[i].range.end = index; |
| 680 | + break; |
| 681 | + } |
| 682 | + } else { |
| 683 | + line.annotations[i].range.end = index; |
676 | 684 | } |
677 | | - } else { |
678 | | - stack[i].range.end = index; |
679 | 685 | } |
680 | 686 | } |
681 | 687 | } |
— | — | @@ -700,7 +706,7 @@ |
701 | 707 | for ( i = 0; i < this.data.length; i++ ) { |
702 | 708 | |
703 | 709 | if ( line == null ) { |
704 | | - line = { text : '', annotations : [] }; |
| 710 | + line = { text : '' }; |
705 | 711 | } |
706 | 712 | |
707 | 713 | right = this.data[i]; |
— | — | @@ -708,7 +714,7 @@ |
709 | 715 | rightPlain = typeof right === 'string'; |
710 | 716 | |
711 | 717 | if ( rightPlain && right == "\n" ) { |
712 | | - this.handleAnnotation( 'close', line.annotations, i - offset ); |
| 718 | + this.handleAnnotation( 'close', line, i - offset ); |
713 | 719 | lines.push(line); |
714 | 720 | line = null; |
715 | 721 | offset = i + 1; |
— | — | @@ -718,22 +724,22 @@ |
719 | 725 | |
720 | 726 | if ( !leftPlain && rightPlain ) { |
721 | 727 | // [formatted][plain] pair, close any annotations for left |
722 | | - this.handleAnnotation( 'close', line.annotations, i - offset ); |
| 728 | + this.handleAnnotation( 'close', line, i - offset ); |
723 | 729 | } else if ( leftPlain && !rightPlain ) { |
724 | 730 | // [plain][formatted] pair, open any annotations for right |
725 | 731 | for ( j = 1; j < right.length; j++ ) { |
726 | | - this.handleAnnotation( 'open', line.annotations, i - offset, right[j] ); |
| 732 | + this.handleAnnotation( 'open', line, i - offset, right[j] ); |
727 | 733 | } |
728 | 734 | } else if ( !leftPlain && !rightPlain ) { |
729 | 735 | // [formatted][formatted] pair, open/close any differences |
730 | 736 | for ( j = 1; j < left.length; j++ ) { |
731 | 737 | if ( this.indexOfAnnotation( i , left[j], true ) === -1 ) { |
732 | | - this.handleAnnotation( 'close', line.annotations, i - offset, left[j] ); |
| 738 | + this.handleAnnotation( 'close', line, i - offset, left[j] ); |
733 | 739 | } |
734 | 740 | } |
735 | 741 | for ( j = 1; j < right.length; j++ ) { |
736 | 742 | if ( this.indexOfAnnotation( i - 1, right[j], true ) === -1 ) { |
737 | | - this.handleAnnotation( 'open', line.annotations, i - offset, right[j] ); |
| 743 | + this.handleAnnotation( 'open', line, i - offset, right[j] ); |
738 | 744 | } |
739 | 745 | } |
740 | 746 | } |
— | — | @@ -743,7 +749,7 @@ |
744 | 750 | } |
745 | 751 | |
746 | 752 | if ( line != null ) { |
747 | | - this.handleAnnotation( 'close', line.annotations, i - offset ); |
| 753 | + this.handleAnnotation( 'close', line, i - offset ); |
748 | 754 | lines.push( line ); |
749 | 755 | } |
750 | 756 | return lines; |