Вход Регистрация
Файл: fckeditor/editor/_source/internals/fckcodeformatter.js
Строк: 118
<?php

/*
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 * Copyright (C) 2003-2008 Frederico Caldeira Knabben
 *
 * == BEGIN LICENSE ==
 *
 * Licensed under the terms of any of the following licenses at your
 * choice:
 *
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 *
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 *
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * == END LICENSE ==
 *
 * Format the HTML.
 */

var FCKCodeFormatter = new Object() ;

FCKCodeFormatter.Init = function()
{
    var 
oRegex this.Regex = new Object() ;

    
// Regex for line breaks.
    
oRegex.BlocksOpener = /<(P|DIV|H1|H2|H3|H4|H5|H6|ADDRESS|PRE|OL|UL|LI|TITLE|META|LINK|BASE|SCRIPT|LINK|TD|TH|AREA|OPTION)[^>]*>/gi ;
    
oRegex.BlocksCloser = /</(P|DIV|H1|H2|H3|H4|H5|H6|ADDRESS|PRE|OL|UL|LI|TITLE|META|LINK|BASE|SCRIPT|LINK|TD|TH|AREA|OPTION)[^>]*>/gi ;

    
oRegex.NewLineTags    = /<(BR|HR)[^>]*>/gi ;

    
oRegex.MainTags = /</?(HTML|HEAD|BODY|FORM|TABLE|TBODY|THEAD|TR)[^>]*>/gi ;

    
oRegex.LineSplitter = /s*n+s*/;

    
// Regex for indentation.
    
oRegex.IncreaseIndent = /^<(HTML|HEAD|BODY|FORM|TABLE|TBODY|THEAD|TR|UL|OL)[ />]/;
    
oRegex.DecreaseIndent = /^</(HTML|HEAD|BODY|FORM|TABLE|TBODY|THEAD|TR|UL|OL)[ >]/;
    
oRegex.FormatIndentatorRemove = new RegExp'^' FCKConfig.FormatIndentator ) ;

    
oRegex.ProtectedTags = /(<PRE[^>]*>)([sS]*?)(</PRE>)/gi ;
}

FCKCodeFormatter._ProtectData = function( outeropenerdatacloser )
{
    return 
opener '___FCKpd___' FCKCodeFormatter.ProtectedData.AddItemdata ) + closer ;
}

FCKCodeFormatter.Format = function( html )
{
    if ( !
this.Regex )
        
this.Init() ;

    
// Protected content that remain untouched during the
    // process go in the following array.
    
FCKCodeFormatter.ProtectedData = new Array() ;

    var 
sFormatted html.replacethis.Regex.ProtectedTagsFCKCodeFormatter._ProtectData ) ;

    
// Line breaks.
    
sFormatted        sFormatted.replacethis.Regex.BlocksOpener'n$&' ) ;
    
sFormatted        sFormatted.replacethis.Regex.BlocksCloser'$&n' ) ;
    
sFormatted        sFormatted.replacethis.Regex.NewLineTags'$&n' ) ;
    
sFormatted        sFormatted.replacethis.Regex.MainTags'n$&n' ) ;

    
// Indentation.
    
var sIndentation '' ;

    var 
asLines sFormatted.splitthis.Regex.LineSplitter ) ;
    
sFormatted '' ;

    for ( var 
asLines.length i++ )
    {
        var 
sLine asLines[i] ;

        if ( 
sLine.length == )
            continue ;

        if ( 
this.Regex.DecreaseIndent.testsLine ) )
            
sIndentation sIndentation.replacethis.Regex.FormatIndentatorRemove'' ) ;

        
sFormatted += sIndentation sLine 'n' ;

        if ( 
this.Regex.IncreaseIndent.testsLine ) )
            
sIndentation += FCKConfig.FormatIndentator ;
    }

    
// Now we put back the protected data.
    
for ( var FCKCodeFormatter.ProtectedData.length j++ )
    {
        var 
oRegex = new RegExp'___FCKpd___' ) ;
        
sFormatted sFormatted.replaceoRegexFCKCodeFormatter.ProtectedData[j].replace( /$/g'$$$$' ) ) ;
    }

    return 
sFormatted.Trim() ;
}
?>
Онлайн: 0
Реклама