User:Yair rand/autoformat.js

// throwing together a bunch of potentially useful autoformatting regexes // sort language sections, add s, move interwikis to the bottom, tbalance, use {t} templates var w=document.getElementById("wpTextbox1"); var s = w.value.replace(/==(Translingual|English)==/g,"==    $1==").match(/==[\s\S]+?(?=(\n+|\n+==[^=]|$))/g).sort if(s[0].indexOf("==    English==")==0 && s[1] && s[1].indexOf("==     Translingual==")==0){s[0] = [s[1],s[1]=s[0]][0]} w.value=(w.value.substr(0,w.value.indexOf("=="))+s.join("\n\n\n\n")).replace(/==    (Translingual|English)==/g,"==$1==")

w.value=w.value.replace("",""); if(w.value.indexOf("[")==-1){w.value+="\n"}

s=RegExp("\\n\\[\\[[a-z]{2,3}(ple|-rup|-min-nan)?:"+util.escapeRe(wgPageName)+"\\]\\]","g") w.value = w.value.match(s)?w.value.replace(s,) + w.value.match(s).join():w.value; w.value = w.value.replace(/\n{3,}/g,'\n\n');

w.value = w.value.replace(/\{\{trans-mid\}\}\n/g,'').replace(/\{\{trans-top[\s\S]+?(?=\n\{\{trans-bottom\}\})/g,function(z){ z=z.replace(RegExp("(([\\s\\S]*?\\n\\*){"+Math.floor(z.split("\n\*").length/2)+"}[\\s\\S]*?(?=\\n\\*(?![\\:\\*])|$))"),'$1\n'); z=z.replace(/(\* \[?\[?([^\:\]]+)\]?\]?: )\[\[([^\]\|]+)\]\]/g, '$1{\{t|{\{subst:langrev/$2}}|$3}}'); z=z.replace(/(\{\{t[\-\+ø]?\|[^\|]+\|[^\{\}]+)\}\} \{\{(m|f|n|c)\}\}/g,'$1|$2}}'); return z });