Changeset 1862

Show
Ignore:
Timestamp:
2008-04-01 11:14:57 (4 months ago)
Author:
wwalc
Message:

Fix for #1003: improved lists parsing.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • MediaWiki/trunk/plugins/mediawiki/fckplugin.js

    r1861 r1862  
    234234                                                case 'ol' : 
    235235                                                case 'ul' : 
    236                                                         var isFirstLevel = !htmlNode.parentNode.nodeName.IEquals( 'ul', 'ol', 'li' ) ; 
     236                                                        var isFirstLevel = !htmlNode.parentNode.nodeName.IEquals( 'ul', 'ol', 'li', 'dl', 'dt', 'dd' ) ; 
    237237 
    238238                                                        this._AppendChildNodes( htmlNode, stringBuilder, prefix ) ; 
     
    246246                                                case 'li' : 
    247247 
    248                                                         var listPrefix = '' ; 
     248                                                        if( stringBuilder.length > 1) 
     249                                                        { 
     250                                                                var sLastStr = stringBuilder[ stringBuilder.length - 1 ] ; 
     251                                                                if ( sLastStr != ";" && sLastStr != ":" && sLastStr != "#" && sLastStr != "*") 
     252                                                                        stringBuilder.push( '\n' + prefix ) ; 
     253                                                        } 
     254                                                         
    249255                                                        var parent = htmlNode.parentNode ; 
    250  
     256                                                        var listType = "#" ; 
     257                                                         
    251258                                                        while ( parent ) 
    252259                                                        { 
    253260                                                                if ( parent.nodeName.toLowerCase() == 'ul' ) 
    254                                                                         listPrefix = '*' + listPrefix ; 
     261                                                                { 
     262                                                                        listType = "*" ; 
     263                                                                        break ; 
     264                                                                } 
    255265                                                                else if ( parent.nodeName.toLowerCase() == 'ol' ) 
    256                                                                         listPrefix = '#' + listPrefix ; 
    257                                                                 else if ( parent.nodeName.toLowerCase() == 'dt' ) 
    258                                                                         listPrefix = ';' + listPrefix ; 
    259                                                                 else if ( parent.nodeName.toLowerCase() == 'dd' ) 
    260                                                                         listPrefix = ':' + listPrefix ; 
     266                                                                { 
     267                                                                        listType = "#" ; 
     268                                                                        break ; 
     269                                                                } 
    261270                                                                else if ( parent.nodeName.toLowerCase() != 'li' ) 
    262271                                                                        break ; 
     
    264273                                                                parent = parent.parentNode ; 
    265274                                                        } 
    266  
    267                                                         var sChildTag = '' ; 
    268                                                          
    269                                                         if ( htmlNode.childNodes.length == 1 && htmlNode.childNodes[0].tagName ) 
    270                                                                 sChildTag = htmlNode.childNodes[0].tagName.toLowerCase(); 
    271                                                         else if ( htmlNode.childNodes.length == 2 && htmlNode.childNodes[1].nodeType == 3 && htmlNode.childNodes[1].nodeValue == "\n") 
    272                                                                 sChildTag = htmlNode.childNodes[0].tagName.toLowerCase(); 
    273                                                          
    274                                                         var sbLen = stringBuilder.length ; 
    275                                                         if (sChildTag != 'ul' && sChildTag != 'ol')  
    276                                                         { 
    277                                                                 if ( sbLen > 1 && stringBuilder[ sbLen - 1 ] != "*" && stringBuilder[ sbLen - 1 ] != "#") { 
    278                                                                         stringBuilder.push( '\n' ) ; 
    279                                                                 } 
    280                                                                 stringBuilder.push( listPrefix ) ; 
    281                                                                 stringBuilder.push( ' ' ) ; 
    282                                                         } 
    283                                                         this._AppendChildNodes( htmlNode, stringBuilder, listPrefix ) ; 
    284  
     275                                                         
     276                                                        stringBuilder.push( listType ) ; 
     277                                                        this._AppendChildNodes( htmlNode, stringBuilder, prefix + listType ) ; 
     278                                                         
    285279                                                        break ; 
    286280 
     
    316310                                                         
    317311                                                case 'dl' : 
     312                                                 
    318313                                                        this._AppendChildNodes( htmlNode, stringBuilder, prefix ) ; 
    319                                                         var isFirstLevel = !htmlNode.parentNode.nodeName.IEquals( 'ul', 'ol', 'li', 'dl', 'dd' ) ; 
    320                                                         if (isFirstLevel) 
     314                                                        var isFirstLevel = !htmlNode.parentNode.nodeName.IEquals( 'ul', 'ol', 'li', 'dl', 'dd', 'dt' ) ; 
     315                                                        if ( isFirstLevel ) 
    321316                                                                stringBuilder.push( '\n') ; 
     317                                                         
    322318                                                        break ; 
    323319 
    324320                                                case 'dt' : 
    325                                                         if( stringBuilder.length > 1 && stringBuilder[ stringBuilder.length - 1 ] != ";" && stringBuilder[ stringBuilder.length - 1 ] != ":" ) 
    326                                                         { 
    327                                                                 stringBuilder.push( '\n' + prefix ) ; 
     321                                                 
     322                                                        if( stringBuilder.length > 1) 
     323                                                        { 
     324                                                                var sLastStr = stringBuilder[ stringBuilder.length - 1 ] ; 
     325                                                                if ( sLastStr != ";" && sLastStr != ":" && sLastStr != "#" && sLastStr != "*" ) 
     326                                                                        stringBuilder.push( '\n' + prefix ) ; 
    328327                                                        } 
    329328                                                        stringBuilder.push( ';' ) ; 
    330                                                         this._AppendChildNodes( htmlNode, stringBuilder, prefix ) ; 
     329                                                        this._AppendChildNodes( htmlNode, stringBuilder, prefix + ";") ; 
     330                                                         
    331331                                                        break ; 
    332332 
    333333                                                case 'dd' : 
    334                                                         if ( stringBuilder.length > 1 && stringBuilder[ stringBuilder.length - 1 ] != ":" ) 
    335                                                         { 
    336                                                                 stringBuilder.push( '\n' + prefix ) ; 
     334                                                 
     335                                                        if( stringBuilder.length > 1) 
     336                                                        { 
     337                                                                var sLastStr = stringBuilder[ stringBuilder.length - 1 ] ; 
     338                                                                if ( sLastStr != ";" && sLastStr != ":" && sLastStr != "#" && sLastStr != "*" ) 
     339                                                                        stringBuilder.push( '\n' + prefix ) ; 
    337340                                                        } 
    338341                                                        stringBuilder.push( ':' ) ; 
    339342                                                        this._AppendChildNodes( htmlNode, stringBuilder, prefix + ":" ) ; 
     343                                                         
    340344                                                        break ; 
    341345