[ Index ] |
|
Code source de FCKeditor 2.4 |
1 /* 2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 3 * Copyright (C) 2003-2007 Frederico Caldeira Knabben 4 * 5 * == BEGIN LICENSE == 6 * 7 * Licensed under the terms of any of the following licenses at your 8 * choice: 9 * 10 * - GNU General Public License Version 2 or later (the "GPL") 11 * http://www.gnu.org/licenses/gpl.html 12 * 13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 14 * http://www.gnu.org/licenses/lgpl.html 15 * 16 * - Mozilla Public License Version 1.1 or later (the "MPL") 17 * http://www.mozilla.org/MPL/MPL-1.1.html 18 * 19 * == END LICENSE == 20 * 21 * File Name: fckcodeformatter.js 22 * Format the HTML. 23 * 24 * File Authors: 25 * Frederico Caldeira Knabben (www.fckeditor.net) 26 */ 27 28 var FCKCodeFormatter = new Object() ; 29 30 FCKCodeFormatter.Init = function() 31 { 32 var oRegex = this.Regex = new Object() ; 33 34 // Regex for line breaks. 35 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 ; 36 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 ; 37 38 oRegex.NewLineTags = /\<(BR|HR)[^\>]*\>/gi ; 39 40 oRegex.MainTags = /\<\/?(HTML|HEAD|BODY|FORM|TABLE|TBODY|THEAD|TR)[^\>]*\>/gi ; 41 42 oRegex.LineSplitter = /\s*\n+\s*/g ; 43 44 // Regex for indentation. 45 oRegex.IncreaseIndent = /^\<(HTML|HEAD|BODY|FORM|TABLE|TBODY|THEAD|TR|UL|OL)[ \/\>]/i ; 46 oRegex.DecreaseIndent = /^\<\/(HTML|HEAD|BODY|FORM|TABLE|TBODY|THEAD|TR|UL|OL)[ \>]/i ; 47 oRegex.FormatIndentatorRemove = new RegExp( '^' + FCKConfig.FormatIndentator ) ; 48 49 oRegex.ProtectedTags = /(<PRE[^>]*>)([\s\S]*?)(<\/PRE>)/gi ; 50 } 51 52 FCKCodeFormatter._ProtectData = function( outer, opener, data, closer ) 53 { 54 return opener + '___FCKpd___' + FCKCodeFormatter.ProtectedData.AddItem( data ) + closer ; 55 } 56 57 FCKCodeFormatter.Format = function( html ) 58 { 59 if ( !this.Regex ) 60 this.Init() ; 61 62 // Protected content that remain untouched during the 63 // process go in the following array. 64 FCKCodeFormatter.ProtectedData = new Array() ; 65 66 var sFormatted = html.replace( this.Regex.ProtectedTags, FCKCodeFormatter._ProtectData ) ; 67 68 // Line breaks. 69 sFormatted = sFormatted.replace( this.Regex.BlocksOpener, '\n$&' ) ; 70 sFormatted = sFormatted.replace( this.Regex.BlocksCloser, '$&\n' ) ; 71 sFormatted = sFormatted.replace( this.Regex.NewLineTags, '$&\n' ) ; 72 sFormatted = sFormatted.replace( this.Regex.MainTags, '\n$&\n' ) ; 73 74 // Indentation. 75 var sIndentation = '' ; 76 77 var asLines = sFormatted.split( this.Regex.LineSplitter ) ; 78 sFormatted = '' ; 79 80 for ( var i = 0 ; i < asLines.length ; i++ ) 81 { 82 var sLine = asLines[i] ; 83 84 if ( sLine.length == 0 ) 85 continue ; 86 87 if ( this.Regex.DecreaseIndent.test( sLine ) ) 88 sIndentation = sIndentation.replace( this.Regex.FormatIndentatorRemove, '' ) ; 89 90 sFormatted += sIndentation + sLine + '\n' ; 91 92 if ( this.Regex.IncreaseIndent.test( sLine ) ) 93 sIndentation += FCKConfig.FormatIndentator ; 94 } 95 96 // Now we put back the protected data. 97 for ( var j = 0 ; j < FCKCodeFormatter.ProtectedData.length ; j++ ) 98 { 99 var oRegex = new RegExp( '___FCKpd___' + j ) ; 100 sFormatted = sFormatted.replace( oRegex, FCKCodeFormatter.ProtectedData[j].replace( /\$/g, '$$$$' ) ) ; 101 } 102 103 return sFormatted.Trim() ; 104 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 15:28:05 2007 | par Balluche grâce à PHPXref 0.7 |