Index: trunk/parsers/wikidom/tests/annotations/test.js |
— | — | @@ -44,15 +44,15 @@ |
45 | 45 | { |
46 | 46 | "type": "italic", |
47 | 47 | "range": { |
48 | | - "offset": 0, |
49 | | - "length": 4 |
| 48 | + "start": 0, |
| 49 | + "stop": 4 |
50 | 50 | } |
51 | 51 | }, |
52 | 52 | { |
53 | 53 | "type": "xlink", |
54 | 54 | "range": { |
55 | | - "offset": 8, |
56 | | - "length": 6 |
| 55 | + "start": 8, |
| 56 | + "stop": 14 |
57 | 57 | }, |
58 | 58 | "data": { |
59 | 59 | "url": "http://www.a.com" |
— | — | @@ -61,8 +61,8 @@ |
62 | 62 | { |
63 | 63 | "type": "bold", |
64 | 64 | "range": { |
65 | | - "offset": 10, |
66 | | - "length": 4 |
| 65 | + "start": 10, |
| 66 | + "stop": 14 |
67 | 67 | } |
68 | 68 | } |
69 | 69 | ] |
— | — | @@ -73,21 +73,39 @@ |
74 | 74 | { |
75 | 75 | "type": "italic", |
76 | 76 | "range": { |
77 | | - "offset": 11, |
78 | | - "length": 3 |
| 77 | + "start": 11, |
| 78 | + "stop": 14 |
79 | 79 | } |
80 | 80 | }, |
81 | 81 | { |
82 | 82 | "type": "bold", |
83 | 83 | "range": { |
84 | | - "offset": 20, |
85 | | - "length": 4 |
| 84 | + "start": 20, |
| 85 | + "stop": 24 |
86 | 86 | } |
87 | 87 | } |
88 | 88 | ] |
89 | 89 | } |
90 | 90 | ]; |
91 | 91 | |
| 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 | + |
92 | 110 | /* Tests */ |
93 | 111 | |
94 | 112 | test( 'Dummy test', function() { |