~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/media/common/edit_area/regexp.js

  • Committer: William Grant
  • Date: 2008-07-07 01:45:11 UTC
  • mfrom: (unknown (missing))
  • Revision ID: wgrant@ugrad.unimelb.edu.au-20080707014511-xyy43p6y8jiqrsh9
Merge killall-editarea branch. We now use CodePress instead, which is
somewhat less slothful.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
        /*EditArea.prototype.comment_or_quotes= function(v0, v1, v2, v3, v4,v5,v6,v7,v8,v9, v10){
2
 
                new_class="quotes";
3
 
                if(v6 && v6 != undefined && v6!="")
4
 
                        new_class="comments";
5
 
                return "µ__"+ new_class +"__µ"+v0+"µ_END_µ";
6
 
 
7
 
        };*/
8
 
        
9
 
/*      EditArea.prototype.htmlTag= function(v0, v1, v2, v3, v4,v5,v6,v7,v8,v9, v10){
10
 
                res="<span class=htmlTag>"+v2;
11
 
                alert("v2: "+v2+" v3: "+v3);
12
 
                tab=v3.split("=");
13
 
                attributes="";
14
 
                if(tab.length>1){
15
 
                        attributes="<span class=attribute>"+tab[0]+"</span>=";
16
 
                        for(i=1; i<tab.length-1; i++){
17
 
                                cut=tab[i].lastIndexOf("&nbsp;");                               
18
 
                                attributes+="<span class=attributeVal>"+tab[i].substr(0,cut)+"</span>";
19
 
                                attributes+="<span class=attribute>"+tab[i].substr(cut)+"</span>=";
20
 
                        }
21
 
                        attributes+="<span class=attributeVal>"+tab[tab.length-1]+"</span>";
22
 
                }               
23
 
                res+=attributes+v5+"</span>";
24
 
                return res;             
25
 
        };*/
26
 
        
27
 
        // determine if the selected text if a comment or a quoted text
28
 
        EditArea.prototype.comment_or_quote= function(){
29
 
                var new_class="";
30
 
                var close_tag="";
31
 
                for(var i in parent.editAreaLoader.syntax[editArea.current_code_lang]["quotes"]){
32
 
                        if(EditArea.prototype.comment_or_quote.arguments[0].indexOf(i)==0){
33
 
                                new_class="quotesmarks";
34
 
                                close_tag=parent.editAreaLoader.syntax[editArea.current_code_lang]["quotes"][i];
35
 
                        }
36
 
                }
37
 
                if(new_class.length==0)
38
 
                {
39
 
                        for(var i in parent.editAreaLoader.syntax[editArea.current_code_lang]["comments"]){
40
 
                                if(EditArea.prototype.comment_or_quote.arguments[0].indexOf(i)==0){
41
 
                                        new_class="comments";
42
 
                                        close_tag=parent.editAreaLoader.syntax[editArea.current_code_lang]["comments"][i];
43
 
                                }
44
 
                        }
45
 
                }
46
 
                // for single line comment the \n must not be included in the span tags
47
 
                if(close_tag=="\n"){
48
 
                        return "µ__"+ new_class +"__µ"+EditArea.prototype.comment_or_quote.arguments[0].replace(/(\r?\n)?$/m, "µ_END_µ$1");
49
 
                }else{
50
 
                        // the closing tag must be set only if the comment or quotes is closed 
51
 
                        reg= new RegExp(parent.editAreaLoader.get_escaped_regexp(close_tag)+"$", "m");
52
 
                        if(EditArea.prototype.comment_or_quote.arguments[0].search(reg)!=-1)
53
 
                                return "µ__"+ new_class +"__µ"+EditArea.prototype.comment_or_quote.arguments[0]+"µ_END_µ";
54
 
                        else
55
 
                                return "µ__"+ new_class +"__µ"+EditArea.prototype.comment_or_quote.arguments[0];
56
 
                }
57
 
        };
58
 
        
59
 
/*
60
 
        // apply special tags arround text to highlight
61
 
        EditArea.prototype.custom_highlight= function(){
62
 
                res= EditArea.prototype.custom_highlight.arguments[1]+"µ__"+ editArea.reg_exp_span_tag +"__µ" + EditArea.prototype.custom_highlight.arguments[2]+"µ_END_µ";
63
 
                if(EditArea.prototype.custom_highlight.arguments.length>5)
64
 
                        res+= EditArea.prototype.custom_highlight.arguments[ EditArea.prototype.custom_highlight.arguments.length-3 ];
65
 
                return res;
66
 
        };
67
 
        */
68
 
        
69
 
        // return identication that allow to know if revalidating only the text line won't make the syntax go mad
70
 
        EditArea.prototype.get_syntax_trace= function(text){
71
 
                if(this.settings["syntax"].length>0 && parent.editAreaLoader.syntax[this.settings["syntax"]]["syntax_trace_regexp"])
72
 
                        return text.replace(parent.editAreaLoader.syntax[this.settings["syntax"]]["syntax_trace_regexp"], "$3");
73
 
        };
74
 
        
75
 
                
76
 
        EditArea.prototype.colorize_text= function(text){
77
 
                //text="<div id='result' class='area' style='position: relative; z-index: 4; height: 500px; overflow: scroll;border: solid black 1px;'> ";
78
 
          /*            
79
 
                if(this.nav['isOpera']){        
80
 
                        // opera can't use pre element tabulation cause a tab=6 chars in the textarea and 8 chars in the pre 
81
 
                        text= this.replace_tab(text);
82
 
                }*/
83
 
                
84
 
                text= " "+text; // for easier regExp
85
 
                
86
 
                /*if(this.do_html_tags)
87
 
                        text= text.replace(/(<[a-z]+ [^>]*>)/gi, '[__htmlTag__]$1[_END_]');*/
88
 
                if(this.settings["syntax"].length>0)
89
 
                        text= this.apply_syntax(text, this.settings["syntax"]);
90
 
                /*for(var lang in this.settin){
91
 
                        text=this.apply_syntax(text, lang);
92
 
                }*/
93
 
                
94
 
                text= text.substr(1);   // remove the first space added         
95
 
                text= text.replace(/&/g,"&amp;");
96
 
                text= text.replace(/</g,"&lt;");
97
 
                text= text.replace(/>/g,"&gt;");        // no need if there is no <             
98
 
                //text= text.replace(/ /g,"&nbsp;");
99
 
                text= text.replace(/µ_END_µ/g,"</span>");
100
 
                text= text.replace(/µ__([a-zA-Z0-9]+)__µ/g,"<span class='$1'>");
101
 
                
102
 
                
103
 
                //text= text.replace(//gi, "<span class='quote'>$1</span>");
104
 
                //alert("text: \n"+text);
105
 
                
106
 
                return text;
107
 
        };
108
 
        
109
 
        EditArea.prototype.apply_syntax= function(text, lang){
110
 
                this.current_code_lang=lang;
111
 
        
112
 
                if(!parent.editAreaLoader.syntax[lang])
113
 
                        return text;
114
 
        
115
 
                /*alert(typeof(text)+"\n"+text.length);
116
 
                
117
 
                var parse_index=0;
118
 
                for(var script_start in this.code[lang]["script_delimiters"]){
119
 
                        var pos_start= text.indexOf(script_start);
120
 
                        var pos_end= text.length;       // MUST BE SET TO CORRECT VAL!!!
121
 
                        if(pos_start!=-1){
122
 
                                var start_text=text.substr(0, pos_start);
123
 
                                var middle_text= text.substring(pos_start, pos_end);
124
 
                                var end_text= text.substring(pos_end);
125
 
                                if(this.code[lang]["comment_or_quote_reg_exp"]){
126
 
                                        //setTimeout("document.getElementById('debug_area').value=editArea.comment_or_quote_reg_exp;", 500);
127
 
                                        middle_text= middle_text.replace(this.code[lang]["comment_or_quote_reg_exp"], this.comment_or_quote);
128
 
                                }
129
 
                                
130
 
                                if(this.code[lang]["keywords_reg_exp"]){
131
 
                                        for(var i in this.code[lang]["keywords_reg_exp"]){      
132
 
                                                this.reg_exp_span_tag=i;
133
 
                                                middle_text= middle_text.replace(this.code[lang]["keywords_reg_exp"][i], this.custom_highlight);                        
134
 
                                        }                       
135
 
                                }
136
 
                                
137
 
                                if(this.code[lang]["delimiters_reg_exp"]){
138
 
                                        middle_text= middle_text.replace(this.code[lang]["delimiters_reg_exp"], 'µ__delimiters__µ$1µ_END_µ');
139
 
                                }               
140
 
                                
141
 
                                if(this.code[lang]["operators_reg_exp"]){
142
 
                                        middle_text= middle_text.replace(this.code[lang]["operators_reg_exp"], 'µ__operators__µ$1µ_END_µ');
143
 
                                }
144
 
                        }
145
 
                        text= start_text+ middle_text + end_text;
146
 
                }*/
147
 
                if(parent.editAreaLoader.syntax[lang]["custom_regexp"]['before']){
148
 
                        for( var i in parent.editAreaLoader.syntax[lang]["custom_regexp"]['before']){
149
 
                                var convert="$1µ__"+ parent.editAreaLoader.syntax[lang]["custom_regexp"]['before'][i]['class'] +"__µ$2µ_END_µ$3";
150
 
                                text= text.replace(parent.editAreaLoader.syntax[lang]["custom_regexp"]['before'][i]['regexp'], convert);
151
 
                        }
152
 
                }
153
 
                
154
 
                if(parent.editAreaLoader.syntax[lang]["comment_or_quote_reg_exp"]){
155
 
                        //setTimeout("document.getElementById('debug_area').value=editArea.comment_or_quote_reg_exp;", 500);
156
 
                        text= text.replace(parent.editAreaLoader.syntax[lang]["comment_or_quote_reg_exp"], this.comment_or_quote);
157
 
                }
158
 
                
159
 
                if(parent.editAreaLoader.syntax[lang]["keywords_reg_exp"]){
160
 
                        for(var i in parent.editAreaLoader.syntax[lang]["keywords_reg_exp"]){   
161
 
                                /*this.reg_exp_span_tag=i;
162
 
                                text= text.replace(parent.editAreaLoader.syntax[lang]["keywords_reg_exp"][i], this.custom_highlight);                   
163
 
                                */
164
 
                                text= text.replace(parent.editAreaLoader.syntax[lang]["keywords_reg_exp"][i], 'µ__'+i+'__µ$2µ_END_µ');
165
 
                        }                       
166
 
                }
167
 
                
168
 
                if(parent.editAreaLoader.syntax[lang]["delimiters_reg_exp"]){
169
 
                        text= text.replace(parent.editAreaLoader.syntax[lang]["delimiters_reg_exp"], 'µ__delimiters__µ$1µ_END_µ');
170
 
                }               
171
 
                
172
 
                if(parent.editAreaLoader.syntax[lang]["operators_reg_exp"]){
173
 
                        text= text.replace(parent.editAreaLoader.syntax[lang]["operators_reg_exp"], 'µ__operators__µ$1µ_END_µ');
174
 
                }
175
 
                
176
 
                if(parent.editAreaLoader.syntax[lang]["custom_regexp"]['after']){
177
 
                        for( var i in parent.editAreaLoader.syntax[lang]["custom_regexp"]['after']){
178
 
                                var convert="$1µ__"+ parent.editAreaLoader.syntax[lang]["custom_regexp"]['after'][i]['class'] +"__µ$2µ_END_µ$3";
179
 
                                text= text.replace(parent.editAreaLoader.syntax[lang]["custom_regexp"]['after'][i]['regexp'], convert);                 
180
 
                        }
181
 
                }
182
 
                        
183
 
                return text;
184
 
        };