r91769 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91768‎ | r91769 | r91770 >
Date:23:04, 8 July 2011
Author:inez
Status:deferred
Tags:
Comment:
Basic implementation of convertAnnotations function
Modified paths:
  • /trunk/parsers/wikidom/tests/annotations/test.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/tests/annotations/test.js
@@ -44,15 +44,15 @@
4545 {
4646 "type": "italic",
4747 "range": {
48 - "offset": 0,
49 - "length": 4
 48+ "start": 0,
 49+ "stop": 4
5050 }
5151 },
5252 {
5353 "type": "xlink",
5454 "range": {
55 - "offset": 8,
56 - "length": 6
 55+ "start": 8,
 56+ "stop": 14
5757 },
5858 "data": {
5959 "url": "http://www.a.com"
@@ -61,8 +61,8 @@
6262 {
6363 "type": "bold",
6464 "range": {
65 - "offset": 10,
66 - "length": 4
 65+ "start": 10,
 66+ "stop": 14
6767 }
6868 }
6969 ]
@@ -73,21 +73,39 @@
7474 {
7575 "type": "italic",
7676 "range": {
77 - "offset": 11,
78 - "length": 3
 77+ "start": 11,
 78+ "stop": 14
7979 }
8080 },
8181 {
8282 "type": "bold",
8383 "range": {
84 - "offset": 20,
85 - "length": 4
 84+ "start": 20,
 85+ "stop": 24
8686 }
8787 }
8888 ]
8989 }
9090 ];
9191
 92+function convertAnnotations( lines ) {
 93+ for ( var i in lines ) {
 94+ var line = lines[i];
 95+ line.charAnnotations = [];
 96+ for ( var j in line.annotations ) {
 97+ var annotation = line.annotations[j];
 98+ for ( var k = annotation.range.start; k <= annotation.range.stop; k++ ) {
 99+ if ( !line.charAnnotations[k] ) {
 100+ line.charAnnotations[k] = [];
 101+ }
 102+ line.charAnnotations[k].push( annotation );
 103+ }
 104+ }
 105+ }
 106+}
 107+
 108+convertAnnotations( lines );
 109+
92110 /* Tests */
93111
94112 test( 'Dummy test', function() {

Status & tagging log