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(" "); |
---|
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="", close_tag="", sy, arg, i; |
---|
30 | sy = parent.editAreaLoader.syntax[editArea.current_code_lang]; |
---|
31 | arg = EditArea.prototype.comment_or_quote.arguments[0]; |
---|
32 | |
---|
33 | for( i in sy["quotes"] ){ |
---|
34 | if(arg.indexOf(i)==0){ |
---|
35 | new_class="quotesmarks"; |
---|
36 | close_tag=sy["quotes"][i]; |
---|
37 | } |
---|
38 | } |
---|
39 | if(new_class.length==0) |
---|
40 | { |
---|
41 | for(var i in sy["comments"]){ |
---|
42 | if( arg.indexOf(i)==0 ){ |
---|
43 | new_class="comments"; |
---|
44 | close_tag=sy["comments"][i]; |
---|
45 | } |
---|
46 | } |
---|
47 | } |
---|
48 | // for single line comment the \n must not be included in the span tags |
---|
49 | if(close_tag=="\n"){ |
---|
50 | return "µ__"+ new_class +"__µ"+ arg.replace(/(\r?\n)?$/m, "µ_END_µ$1"); |
---|
51 | }else{ |
---|
52 | // the closing tag must be set only if the comment or quotes is closed |
---|
53 | reg= new RegExp(parent.editAreaLoader.get_escaped_regexp(close_tag)+"$", "m"); |
---|
54 | if( arg.search(reg)!=-1 ) |
---|
55 | return "µ__"+ new_class +"__µ"+ arg +"µ_END_µ"; |
---|
56 | else |
---|
57 | return "µ__"+ new_class +"__µ"+ arg; |
---|
58 | } |
---|
59 | }; |
---|
60 | |
---|
61 | /* |
---|
62 | // apply special tags arround text to highlight |
---|
63 | EditArea.prototype.custom_highlight= function(){ |
---|
64 | res= EditArea.prototype.custom_highlight.arguments[1]+"µ__"+ editArea.reg_exp_span_tag +"__µ" + EditArea.prototype.custom_highlight.arguments[2]+"µ_END_µ"; |
---|
65 | if(EditArea.prototype.custom_highlight.arguments.length>5) |
---|
66 | res+= EditArea.prototype.custom_highlight.arguments[ EditArea.prototype.custom_highlight.arguments.length-3 ]; |
---|
67 | return res; |
---|
68 | }; |
---|
69 | */ |
---|
70 | |
---|
71 | // return identication that allow to know if revalidating only the text line won't make the syntax go mad |
---|
72 | EditArea.prototype.get_syntax_trace= function(text){ |
---|
73 | if(this.settings["syntax"].length>0 && parent.editAreaLoader.syntax[this.settings["syntax"]]["syntax_trace_regexp"]) |
---|
74 | return text.replace(parent.editAreaLoader.syntax[this.settings["syntax"]]["syntax_trace_regexp"], "$3"); |
---|
75 | }; |
---|
76 | |
---|
77 | |
---|
78 | EditArea.prototype.colorize_text= function(text){ |
---|
79 | //text="<div id='result' class='area' style='position: relative; z-index: 4; height: 500px; overflow: scroll;border: solid black 1px;'> "; |
---|
80 | /* |
---|
81 | if(this.isOpera){ |
---|
82 | // opera can't use pre element tabulation cause a tab=6 chars in the textarea and 8 chars in the pre |
---|
83 | text= this.replace_tab(text); |
---|
84 | }*/ |
---|
85 | |
---|
86 | text= " "+text; // for easier regExp |
---|
87 | |
---|
88 | /*if(this.do_html_tags) |
---|
89 | text= text.replace(/(<[a-z]+ [^>]*>)/gi, '[__htmlTag__]$1[_END_]');*/ |
---|
90 | if(this.settings["syntax"].length>0) |
---|
91 | text= this.apply_syntax(text, this.settings["syntax"]); |
---|
92 | |
---|
93 | // remove the first space added |
---|
94 | return text.substr(1).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/µ_END_µ/g,"</span>").replace(/µ__([a-zA-Z0-9]+)__µ/g,"<span class='$1'>"); |
---|
95 | }; |
---|
96 | |
---|
97 | EditArea.prototype.apply_syntax= function(text, lang){ |
---|
98 | var sy; |
---|
99 | this.current_code_lang=lang; |
---|
100 | |
---|
101 | if(!parent.editAreaLoader.syntax[lang]) |
---|
102 | return text; |
---|
103 | |
---|
104 | sy = parent.editAreaLoader.syntax[lang]; |
---|
105 | if(sy["custom_regexp"]['before']){ |
---|
106 | for( var i in sy["custom_regexp"]['before']){ |
---|
107 | var convert="$1µ__"+ sy["custom_regexp"]['before'][i]['class'] +"__µ$2µ_END_µ$3"; |
---|
108 | text= text.replace(sy["custom_regexp"]['before'][i]['regexp'], convert); |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | if(sy["comment_or_quote_reg_exp"]){ |
---|
113 | //setTimeout("_$('debug_area').value=editArea.comment_or_quote_reg_exp;", 500); |
---|
114 | text= text.replace(sy["comment_or_quote_reg_exp"], this.comment_or_quote); |
---|
115 | } |
---|
116 | |
---|
117 | if(sy["keywords_reg_exp"]){ |
---|
118 | for(var i in sy["keywords_reg_exp"]){ |
---|
119 | text= text.replace(sy["keywords_reg_exp"][i], 'µ__'+i+'__µ$2µ_END_µ'); |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | if(sy["delimiters_reg_exp"]){ |
---|
124 | text= text.replace(sy["delimiters_reg_exp"], 'µ__delimiters__µ$1µ_END_µ'); |
---|
125 | } |
---|
126 | |
---|
127 | if(sy["operators_reg_exp"]){ |
---|
128 | text= text.replace(sy["operators_reg_exp"], 'µ__operators__µ$1µ_END_µ'); |
---|
129 | } |
---|
130 | |
---|
131 | if(sy["custom_regexp"]['after']){ |
---|
132 | for( var i in sy["custom_regexp"]['after']){ |
---|
133 | var convert="$1µ__"+ sy["custom_regexp"]['after'][i]['class'] +"__µ$2µ_END_µ$3"; |
---|
134 | text= text.replace(sy["custom_regexp"]['after'][i]['regexp'], convert); |
---|
135 | } |
---|
136 | } |
---|
137 | |
---|
138 | return text; |
---|
139 | }; |
---|