~ubuntu-branches/ubuntu/oneiric/moin/oneiric-security

« back to all changes in this revision

Viewing changes to wiki/htdocs/applets/FCKeditor/editor/_source/internals/fckcodeformatter.js

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2010-03-30 12:55:34 UTC
  • mfrom: (0.1.17 sid)
  • Revision ID: james.westby@ubuntu.com-20100330125534-4c2ufc1rok24447l
Tags: 1.9.2-2ubuntu1
* Merge from Debian testing (LP: #521834). Based on work by Stefan Ebner.
  Remaining changes:
 - Remove python-xml from Suggests field, the package isn't anymore in
   sys.path.
 - Demote fckeditor from Recommends to Suggests; the code was previously
   embedded in moin, but it was also disabled, so there's no reason for us
   to pull this in by default currently. Note: This isn't necessary anymore
   but needs a MIR for fckeditor, so postpone dropping this change until
   lucid+1
* debian/rules:
  - Replace hardcoded python2.5 with python* and hardcore python2.6 for ln
* debian/control.in: drop versioned depends on cdbs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
 
 * Copyright (C) 2003-2009 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
 
 * Format the HTML.
22
 
 */
23
 
 
24
 
var FCKCodeFormatter = new Object() ;
25
 
 
26
 
FCKCodeFormatter.Init = function()
27
 
{
28
 
        var oRegex = this.Regex = new Object() ;
29
 
 
30
 
        // Regex for line breaks.
31
 
        oRegex.BlocksOpener = /\<(P|DIV|H1|H2|H3|H4|H5|H6|ADDRESS|PRE|OL|UL|LI|DL|DT|DD|TITLE|META|LINK|BASE|SCRIPT|LINK|TD|TH|AREA|OPTION)[^\>]*\>/gi ;
32
 
        oRegex.BlocksCloser = /\<\/(P|DIV|H1|H2|H3|H4|H5|H6|ADDRESS|PRE|OL|UL|LI|DL|DT|DD|TITLE|META|LINK|BASE|SCRIPT|LINK|TD|TH|AREA|OPTION)[^\>]*\>/gi ;
33
 
 
34
 
        oRegex.NewLineTags      = /\<(BR|HR)[^\>]*\>/gi ;
35
 
 
36
 
        oRegex.MainTags = /\<\/?(HTML|HEAD|BODY|FORM|TABLE|TBODY|THEAD|TR)[^\>]*\>/gi ;
37
 
 
38
 
        oRegex.LineSplitter = /\s*\n+\s*/g ;
39
 
 
40
 
        // Regex for indentation.
41
 
        oRegex.IncreaseIndent = /^\<(HTML|HEAD|BODY|FORM|TABLE|TBODY|THEAD|TR|UL|OL|DL)[ \/\>]/i ;
42
 
        oRegex.DecreaseIndent = /^\<\/(HTML|HEAD|BODY|FORM|TABLE|TBODY|THEAD|TR|UL|OL|DL)[ \>]/i ;
43
 
        oRegex.FormatIndentatorRemove = new RegExp( '^' + FCKConfig.FormatIndentator ) ;
44
 
 
45
 
        oRegex.ProtectedTags = /(<PRE[^>]*>)([\s\S]*?)(<\/PRE>)/gi ;
46
 
}
47
 
 
48
 
FCKCodeFormatter._ProtectData = function( outer, opener, data, closer )
49
 
{
50
 
        return opener + '___FCKpd___' + ( FCKCodeFormatter.ProtectedData.push( data ) - 1 ) + closer ;
51
 
}
52
 
 
53
 
FCKCodeFormatter.Format = function( html )
54
 
{
55
 
        if ( !this.Regex )
56
 
                this.Init() ;
57
 
 
58
 
        // Protected content that remain untouched during the
59
 
        // process go in the following array.
60
 
        FCKCodeFormatter.ProtectedData = new Array() ;
61
 
 
62
 
        var sFormatted = html.replace( this.Regex.ProtectedTags, FCKCodeFormatter._ProtectData ) ;
63
 
 
64
 
        // Line breaks.
65
 
        sFormatted              = sFormatted.replace( this.Regex.BlocksOpener, '\n$&' ) ;
66
 
        sFormatted              = sFormatted.replace( this.Regex.BlocksCloser, '$&\n' ) ;
67
 
        sFormatted              = sFormatted.replace( this.Regex.NewLineTags, '$&\n' ) ;
68
 
        sFormatted              = sFormatted.replace( this.Regex.MainTags, '\n$&\n' ) ;
69
 
 
70
 
        // Indentation.
71
 
        var sIndentation = '' ;
72
 
 
73
 
        var asLines = sFormatted.split( this.Regex.LineSplitter ) ;
74
 
        sFormatted = '' ;
75
 
 
76
 
        for ( var i = 0 ; i < asLines.length ; i++ )
77
 
        {
78
 
                var sLine = asLines[i] ;
79
 
 
80
 
                if ( sLine.length == 0 )
81
 
                        continue ;
82
 
 
83
 
                if ( this.Regex.DecreaseIndent.test( sLine ) )
84
 
                        sIndentation = sIndentation.replace( this.Regex.FormatIndentatorRemove, '' ) ;
85
 
 
86
 
                sFormatted += sIndentation + sLine + '\n' ;
87
 
 
88
 
                if ( this.Regex.IncreaseIndent.test( sLine ) )
89
 
                        sIndentation += FCKConfig.FormatIndentator ;
90
 
        }
91
 
 
92
 
        // Now we put back the protected data.
93
 
        for ( var j = 0 ; j < FCKCodeFormatter.ProtectedData.length ; j++ )
94
 
        {
95
 
                var oRegex = new RegExp( '___FCKpd___' + j ) ;
96
 
                sFormatted = sFormatted.replace( oRegex, FCKCodeFormatter.ProtectedData[j].replace( /\$/g, '$$$$' ) ) ;
97
 
        }
98
 
 
99
 
        return sFormatted.Trim() ;
100
 
}