[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/include/fckeditor/editor/_source/internals/ -> fckcodeformatter.js (source)

   1  /*
   2   * FCKeditor - The text editor for internet
   3   * Copyright (C) 2003-2005 Frederico Caldeira Knabben
   4   * 
   5   * Licensed under the terms of the GNU Lesser General Public License:
   6   *         http://www.opensource.org/licenses/lgpl-license.php
   7   * 
   8   * For further information visit:
   9   *         http://www.fckeditor.net/
  10   * 
  11   * "Support Open Source software. What about a donation today?"
  12   * 
  13   * File Name: fckcodeformatter.js
  14   *     Format the HTML.
  15   * 
  16   * File Authors:
  17   *         Frederico Caldeira Knabben (fredck@fckeditor.net)
  18   */
  19  
  20  var FCKCodeFormatter ;
  21  
  22  if ( !( FCKCodeFormatter = NS.FCKCodeFormatter ) )
  23  {
  24      FCKCodeFormatter = NS.FCKCodeFormatter = new Object() ;
  25  
  26      FCKCodeFormatter.Regex = new Object() ;
  27  
  28      // Regex for line breaks.
  29      FCKCodeFormatter.Regex.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 ;
  30      FCKCodeFormatter.Regex.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 ;
  31  
  32      FCKCodeFormatter.Regex.NewLineTags    = /\<(BR|HR)[^\>]\>/gi ;
  33  
  34      FCKCodeFormatter.Regex.MainTags = /\<\/?(HTML|HEAD|BODY|FORM|TABLE|TBODY|THEAD|TR)[^\>]*\>/gi ;
  35  
  36      FCKCodeFormatter.Regex.LineSplitter = /\s*\n+\s*/g ;
  37  
  38      // Regex for indentation.
  39      FCKCodeFormatter.Regex.IncreaseIndent = /^\<(HTML|HEAD|BODY|FORM|TABLE|TBODY|THEAD|TR|UL|OL)[ \/\>]/i ;
  40      FCKCodeFormatter.Regex.DecreaseIndent = /^\<\/(HTML|HEAD|BODY|FORM|TABLE|TBODY|THEAD|TR|UL|OL)[ \>]/i ;
  41      FCKCodeFormatter.Regex.FormatIndentatorRemove = new RegExp( FCKConfig.FormatIndentator ) ;
  42  
  43      FCKCodeFormatter.Regex.ProtectedTags = /(<PRE[^>]*>)([\s\S]*?)(<\/PRE>)/gi ;
  44  
  45      FCKCodeFormatter._ProtectData = function( outer, opener, data, closer )
  46      {
  47          return opener + '___FCKpd___' + FCKCodeFormatter.ProtectedData.addItem( data ) + closer ;
  48      }
  49  
  50      FCKCodeFormatter.Format = function( html )
  51      {
  52          // Protected content that remain untouched during the
  53          // process go in the following array.
  54          FCKCodeFormatter.ProtectedData = new Array() ;
  55          
  56          var sFormatted = html.replace( this.Regex.ProtectedTags, FCKCodeFormatter._ProtectData ) ;
  57      
  58          // Line breaks.
  59           sFormatted        = sFormatted.replace( this.Regex.BlocksOpener, '\n$&' ) ; ;
  60          sFormatted        = sFormatted.replace( this.Regex.BlocksCloser, '$&\n' ) ;
  61          sFormatted        = sFormatted.replace( this.Regex.NewLineTags, '$&\n' ) ;
  62          sFormatted        = sFormatted.replace( this.Regex.MainTags, '\n$&\n' ) ;
  63          
  64          // Indentation.
  65          var sIndentation = '' ;
  66          
  67          var asLines = sFormatted.split( this.Regex.LineSplitter ) ;
  68          sFormatted = '' ;
  69          
  70          for ( var i = 0 ; i < asLines.length ; i++ )
  71          {
  72              var sLine = asLines[i] ;
  73              
  74              if ( sLine.length == 0 )
  75                  continue ;
  76              
  77              if ( this.Regex.DecreaseIndent.test( sLine ) )
  78                  sIndentation = sIndentation.replace( this.Regex.FormatIndentatorRemove, '' ) ;
  79  
  80              sFormatted += sIndentation + sLine + '\n' ;
  81              
  82              if ( this.Regex.IncreaseIndent.test( sLine ) )
  83                  sIndentation += FCKConfig.FormatIndentator ;
  84          }
  85          
  86          // Now we put back the protected data.
  87          for ( var i = 0 ; i < FCKCodeFormatter.ProtectedData.length ; i++ )
  88          {
  89              var oRegex = new RegExp( '___FCKpd___' + i ) ;
  90              sFormatted = sFormatted.replace( oRegex, FCKCodeFormatter.ProtectedData[i] ) ;
  91          }
  92  
  93          return sFormatted.trim() ;
  94      }
  95  }


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7