Index: trunk/parsers/wikidom/tests/serializers/test.js |
— | — | @@ -284,6 +284,38 @@ |
285 | 285 | { 'line': { 'text': '2' } } |
286 | 286 | ] |
287 | 287 | } ] } |
| 288 | + }, |
| 289 | + { |
| 290 | + 'subject': 'mixed-style nested lists (3)', |
| 291 | + 'dom': { 'blocks': [ { |
| 292 | + 'type': 'list', |
| 293 | + 'style': 'number', |
| 294 | + 'items': [ |
| 295 | + { |
| 296 | + 'lists' : [ |
| 297 | + { |
| 298 | + 'style': 'number', |
| 299 | + 'items': [ |
| 300 | + { |
| 301 | + 'lists' : [ |
| 302 | + { |
| 303 | + 'style': 'number', |
| 304 | + 'items': [ |
| 305 | + { |
| 306 | + 'line' : { |
| 307 | + 'text' : 'test' |
| 308 | + } |
| 309 | + } |
| 310 | + ] |
| 311 | + } |
| 312 | + ] |
| 313 | + } |
| 314 | + ] |
| 315 | + } |
| 316 | + ] |
| 317 | + } |
| 318 | + ] |
| 319 | + } ] } |
288 | 320 | } |
289 | 321 | ], true ); |
290 | 322 | } ); |
Index: trunk/parsers/wikidom/lib/es/es.ListBlock.js |
— | — | @@ -42,12 +42,22 @@ |
43 | 43 | return new es.ListBlock( es.ListBlockList.newFromWikiDomList( wikidomListBlock ) ); |
44 | 44 | }; |
45 | 45 | |
46 | | -es.ListBlock.prototype.renderContent = function( offset ) { |
47 | | - this.list.renderContent( offset ); |
| 46 | +es.ListBlock.wikiDomPushPop = function( stack ) { |
| 47 | + if ( stack[stack.length - 2].items.length === 0 ) { |
| 48 | + stack[stack.length - 2].items.push( { 'lists' : [] } ); |
| 49 | + } else if( !stack[stack.length - 2].items[stack[stack.length - 2].items.length - 1].lists ) { |
| 50 | + stack[stack.length - 2].items[stack[stack.length - 2].items.length - 1].lists = []; |
| 51 | + } |
| 52 | + stack[stack.length - 2].items[stack[stack.length - 2].items.length - 1].lists.push( stack.pop() ); |
| 53 | + return stack; |
48 | 54 | }; |
49 | 55 | |
50 | 56 | /* Public Methods */ |
51 | 57 | |
| 58 | +es.ListBlock.prototype.renderContent = function( offset ) { |
| 59 | + this.list.renderContent( offset ); |
| 60 | +}; |
| 61 | + |
52 | 62 | es.ListBlock.prototype.enumerate = function() { |
53 | 63 | var itemLevel, |
54 | 64 | levels = []; |
— | — | @@ -363,66 +373,44 @@ |
364 | 374 | for ( var i = 0; i < items.length; i++ ) { |
365 | 375 | var item = items[i]; |
366 | 376 | var itemLevel = item.getLevel(); |
367 | | - |
368 | | - if ( itemLevel + 1 === stack.length ) { |
369 | | - if ( lastStyle !== null && lastStyle != item.getStyle() ) { |
370 | | - if ( stack[stack.length - 2].items.length === 0 ) { |
371 | | - stack[stack.length - 2].items.push( { |
372 | | - 'lists' : [] |
373 | | - } ); |
374 | | - } else if( !stack[stack.length - 2].items[stack[stack.length - 2].items.length - 1].lists ) { |
375 | | - stack[stack.length - 2].items[stack[stack.length - 2].items.length - 1].lists = []; |
376 | | - } |
377 | | - stack[stack.length - 2].items[stack[stack.length - 2].items.length - 1].lists.push( stack.pop() ); |
378 | | - stack.push( { |
379 | | - 'style' : item.getStyle(), |
380 | | - 'items' : [] |
381 | | - } ); |
382 | | - //lastStyle = item.getStyle(); |
383 | | - } |
| 377 | + |
| 378 | + // if the current element level is the same as the previous one, but its style is different |
| 379 | + if ( itemLevel + 1 === stack.length && lastStyle != item.getStyle() ) { |
| 380 | + stack = es.ListBlock.wikiDomPushPop( stack ); |
| 381 | + stack.push( { |
| 382 | + 'style' : item.getStyle(), |
| 383 | + 'items' : [] |
| 384 | + } ); |
384 | 385 | } |
385 | 386 | |
| 387 | + // if the current element level is higher than the previous one |
386 | 388 | if ( itemLevel + 1 > stack.length ) { |
387 | | - for( var j = stack.length; j < itemLevel + 1; j++ ) { |
| 389 | + for ( var j = stack.length; j < itemLevel + 1; j++ ) { |
388 | 390 | stack.push( { |
389 | 391 | 'style' : item.getStyle(j), |
390 | 392 | 'items' : [] |
391 | 393 | } ); |
392 | 394 | } |
393 | 395 | } |
394 | | - |
| 396 | + |
| 397 | + // if the current element level is lower then the previous one |
395 | 398 | if ( itemLevel + 1 < stack.length ) { |
396 | | - for( var j = stack.length; j > itemLevel + 1; j-- ) { |
397 | | - if ( stack[stack.length - 2].items.length === 0 ) { |
398 | | - stack[stack.length - 2].items.push( { |
399 | | - 'lists' : [] |
400 | | - } ); |
401 | | - } else if( !stack[stack.length - 2].items[stack[stack.length - 2].items.length - 1].lists ) { |
402 | | - stack[stack.length - 2].items[stack[stack.length - 2].items.length - 1].lists = []; |
403 | | - } |
404 | | - stack[stack.length - 2].items[stack[stack.length - 2].items.length - 1].lists.push( stack.pop() ); |
| 399 | + for ( var j = stack.length; j > itemLevel + 1; j-- ) { |
| 400 | + stack = es.ListBlock.wikiDomPushPop( stack ); |
405 | 401 | } |
406 | 402 | } |
407 | 403 | |
| 404 | + // if the current element level is the same as the previous one |
408 | 405 | if ( itemLevel + 1 === stack.length ) { |
409 | | - stack[stack.length - 1].items.push( { |
410 | | - 'line' : item.content.getWikiDomLines()[0] } |
411 | | - ); |
| 406 | + stack[stack.length - 1].items.push( { 'line' : item.content.getWikiDomLines()[0] } ); |
412 | 407 | lastStyle = item.getStyle(); |
413 | 408 | } |
414 | 409 | } |
415 | | - |
416 | | - for( var i = stack.length; i > 1; i-- ) { |
417 | | - if ( stack[stack.length - 2].items.length === 0 ) { |
418 | | - stack[stack.length - 2].items.push( { |
419 | | - 'lists' : [] |
420 | | - } ); |
421 | | - } else if( !stack[stack.length - 2].items[stack[stack.length - 2].items.length - 1].lists ) { |
422 | | - stack[stack.length - 2].items[stack[stack.length - 2].items.length - 1].lists = []; |
423 | | - } |
424 | | - stack[stack.length - 2].items[stack[stack.length - 2].items.length - 1].lists.push( stack.pop() ); |
| 410 | + |
| 411 | + for ( var i = stack.length; i > 1; i-- ) { |
| 412 | + stack = es.ListBlock.wikiDomPushPop( stack ); |
425 | 413 | } |
426 | | - |
| 414 | + |
427 | 415 | stack[0].type = 'list'; |
428 | 416 | return stack[0]; |
429 | 417 | }; |