Index: trunk/parsers/wikidom/lib/es/es.Content.js |
— | — | @@ -559,4 +559,69 @@ |
560 | 560 | }; |
561 | 561 | }; |
562 | 562 | |
| 563 | +Content.prototype.getLines = function() { |
| 564 | + var lines = [], |
| 565 | + line = null, |
| 566 | + offset = 0, |
| 567 | + left = '', |
| 568 | + right = '', |
| 569 | + leftPlain, |
| 570 | + rightPlain; |
| 571 | + |
| 572 | + for ( var i = 0; i < this.data.length; i++ ) { |
| 573 | + |
| 574 | + if ( line == null ) { |
| 575 | + line = { |
| 576 | + text : '', |
| 577 | + annotations : [] |
| 578 | + }; |
| 579 | + } |
| 580 | + |
| 581 | + if ( this.data[i] == "\n" ) { |
| 582 | + lines.push(line); |
| 583 | + line = null; |
| 584 | + offset = i + 1; |
| 585 | + continue; |
| 586 | + } |
| 587 | + |
| 588 | + right = this.data[i]; |
| 589 | + leftPlain = typeof left === 'string'; |
| 590 | + rightPlain = typeof right === 'string'; |
| 591 | + |
| 592 | + for ( var j = 1; j < left.length; j++ ) { |
| 593 | + if (rightPlain || this.indexOfAnnotation( i, left[j], true ) === -1) { |
| 594 | + for ( var k = line.annotations.length - 1; k >= 0; k--) { |
| 595 | + if ( line.annotations[k].type === left[j].type ) { |
| 596 | + if ( Content.compareObjects( line.annotations[k].data, left[j].data ) ) { |
| 597 | + line.annotations[k].range.end = i - offset; |
| 598 | + break; |
| 599 | + } |
| 600 | + } |
| 601 | + } |
| 602 | + } |
| 603 | + } |
| 604 | + |
| 605 | + for ( var j = 1; j < right.length; j++ ) { |
| 606 | + if (leftPlain || this.indexOfAnnotation( i - 1, right[j], true ) === -1) { |
| 607 | + var annotation = Content.copyObject( right[j] ); |
| 608 | + annotation.range = { |
| 609 | + start : i - offset, |
| 610 | + end : i + 1 - offset |
| 611 | + }; |
| 612 | + line.annotations.push( annotation ); |
| 613 | + } |
| 614 | + } |
| 615 | + |
| 616 | + left = right; |
| 617 | + |
| 618 | + if ( rightPlain ) { |
| 619 | + line.text += this.data[i]; |
| 620 | + } else { |
| 621 | + line.text += this.data[i][0]; |
| 622 | + } |
| 623 | + } |
| 624 | + |
| 625 | + return lines; |
| 626 | +}; |
| 627 | + |
563 | 628 | extend( Content, EventEmitter ); |