X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/db6d2feee32d100fb893b389421bda2fd65a89cd..d9f6aab0486a302a211c6d9c77394daa501c7216:/project/static/js/regexp.js diff --git a/project/static/js/regexp.js b/project/static/js/regexp.js new file mode 100755 index 00000000..907063a6 --- /dev/null +++ b/project/static/js/regexp.js @@ -0,0 +1,139 @@ + /*EditArea.prototype.comment_or_quotes= function(v0, v1, v2, v3, v4,v5,v6,v7,v8,v9, v10){ + new_class="quotes"; + if(v6 && v6 != undefined && v6!="") + new_class="comments"; + return "µ__"+ new_class +"__µ"+v0+"µ_END_µ"; + + };*/ + +/* EditArea.prototype.htmlTag= function(v0, v1, v2, v3, v4,v5,v6,v7,v8,v9, v10){ + res=""+v2; + alert("v2: "+v2+" v3: "+v3); + tab=v3.split("="); + attributes=""; + if(tab.length>1){ + attributes=""+tab[0]+"="; + for(i=1; i"; + attributes+=""+tab[i].substr(cut)+"="; + } + attributes+=""+tab[tab.length-1]+""; + } + res+=attributes+v5+""; + return res; + };*/ + + // determine if the selected text if a comment or a quoted text + EditArea.prototype.comment_or_quote= function(){ + var new_class="", close_tag="", sy, arg, i; + sy = parent.editAreaLoader.syntax[editArea.current_code_lang]; + arg = EditArea.prototype.comment_or_quote.arguments[0]; + + for( i in sy["quotes"] ){ + if(arg.indexOf(i)==0){ + new_class="quotesmarks"; + close_tag=sy["quotes"][i]; + } + } + if(new_class.length==0) + { + for(var i in sy["comments"]){ + if( arg.indexOf(i)==0 ){ + new_class="comments"; + close_tag=sy["comments"][i]; + } + } + } + // for single line comment the \n must not be included in the span tags + if(close_tag=="\n"){ + return "µ__"+ new_class +"__µ"+ arg.replace(/(\r?\n)?$/m, "µ_END_µ$1"); + }else{ + // the closing tag must be set only if the comment or quotes is closed + reg= new RegExp(parent.editAreaLoader.get_escaped_regexp(close_tag)+"$", "m"); + if( arg.search(reg)!=-1 ) + return "µ__"+ new_class +"__µ"+ arg +"µ_END_µ"; + else + return "µ__"+ new_class +"__µ"+ arg; + } + }; + +/* + // apply special tags arround text to highlight + EditArea.prototype.custom_highlight= function(){ + res= EditArea.prototype.custom_highlight.arguments[1]+"µ__"+ editArea.reg_exp_span_tag +"__µ" + EditArea.prototype.custom_highlight.arguments[2]+"µ_END_µ"; + if(EditArea.prototype.custom_highlight.arguments.length>5) + res+= EditArea.prototype.custom_highlight.arguments[ EditArea.prototype.custom_highlight.arguments.length-3 ]; + return res; + }; + */ + + // return identication that allow to know if revalidating only the text line won't make the syntax go mad + EditArea.prototype.get_syntax_trace= function(text){ + if(this.settings["syntax"].length>0 && parent.editAreaLoader.syntax[this.settings["syntax"]]["syntax_trace_regexp"]) + return text.replace(parent.editAreaLoader.syntax[this.settings["syntax"]]["syntax_trace_regexp"], "$3"); + }; + + + EditArea.prototype.colorize_text= function(text){ + //text="
"; + /* + if(this.isOpera){ + // opera can't use pre element tabulation cause a tab=6 chars in the textarea and 8 chars in the pre + text= this.replace_tab(text); + }*/ + + text= " "+text; // for easier regExp + + /*if(this.do_html_tags) + text= text.replace(/(<[a-z]+ [^>]*>)/gi, '[__htmlTag__]$1[_END_]');*/ + if(this.settings["syntax"].length>0) + text= this.apply_syntax(text, this.settings["syntax"]); + + // remove the first space added + return text.substr(1).replace(/&/g,"&").replace(//g,">").replace(/µ_END_µ/g,"").replace(/µ__([a-zA-Z0-9]+)__µ/g,""); + }; + + EditArea.prototype.apply_syntax= function(text, lang){ + var sy; + this.current_code_lang=lang; + + if(!parent.editAreaLoader.syntax[lang]) + return text; + + sy = parent.editAreaLoader.syntax[lang]; + if(sy["custom_regexp"]['before']){ + for( var i in sy["custom_regexp"]['before']){ + var convert="$1µ__"+ sy["custom_regexp"]['before'][i]['class'] +"__µ$2µ_END_µ$3"; + text= text.replace(sy["custom_regexp"]['before'][i]['regexp'], convert); + } + } + + if(sy["comment_or_quote_reg_exp"]){ + //setTimeout("_$('debug_area').value=editArea.comment_or_quote_reg_exp;", 500); + text= text.replace(sy["comment_or_quote_reg_exp"], this.comment_or_quote); + } + + if(sy["keywords_reg_exp"]){ + for(var i in sy["keywords_reg_exp"]){ + text= text.replace(sy["keywords_reg_exp"][i], 'µ__'+i+'__µ$2µ_END_µ'); + } + } + + if(sy["delimiters_reg_exp"]){ + text= text.replace(sy["delimiters_reg_exp"], 'µ__delimiters__µ$1µ_END_µ'); + } + + if(sy["operators_reg_exp"]){ + text= text.replace(sy["operators_reg_exp"], 'µ__operators__µ$1µ_END_µ'); + } + + if(sy["custom_regexp"]['after']){ + for( var i in sy["custom_regexp"]['after']){ + var convert="$1µ__"+ sy["custom_regexp"]['after'][i]['class'] +"__µ$2µ_END_µ$3"; + text= text.replace(sy["custom_regexp"]['after'][i]['regexp'], convert); + } + } + + return text; + };