User:Fæ/ae fixes.js

/* AutoEd further fixes */ /* - put footnotes after punctuation rather than just before - use reflist if more than 2 references - use reflist|2 if more than 6 references - trim duplicate wlinks, leaving just first instance - remove default image right aligned option function FaeFixes(mytext){ var cmt='',mycount=0; // // Ensure footnotes are after punctuation // var fPattern=/(]*>([^>]*|[^>]*(-->){1}[^>]*)ref>)(\.|,|;)/g; if(mytext.match(fPattern)!=null){ mytext=mytext.replace(fPattern,'$4$1'); // Fix wrong ref punctuation cmt+='Fix inconsistent ref placement, see FN. '; }  //  // Ref tags, tidy footnote list // // Calc total no. of refs (must be closing tags otherwise over count multiple tags to same footnote) var refcount=mytext.match(/<\/ref>/g)!=null?mytext.match(/<\/ref>/g).length:0; // Convert older type tag if(mytext.match(//)!=null && refcount>2){ if(refcount>5){ mytext=mytext.replace(//,''); }else{ mytext=mytext.replace(//,''); }   cmt+='Standardize reflist. '; }  // Upgrade to 2+col if 6 or more footnotes if(refcount>5 && mytext.match(/\{\{reflist\}\}/gi)!=null){ mytext=mytext.replace(/\{\{reflist\}\}/gi,''); cmt+='Better reflist layout ('+refcount+' footnotes). '; }  //  // Remove odd newlines // mycount=0; while(mytext.match(/[\n\r]{3}/)!=null){ mytext=mytext.replace(/[\n\r]{3,}/,"\n\n"); mycount++; } if(mycount>0 && cmt.length<100){ cmt+=(mycount==1?'Rm unnecessary newline. ':'Rm '+mycount+' areas of unnecessary newlines. '); } //  // Remove duplicate w-links (leaving 1st instance) // //  // Things to park (duplicates to keep) mytext=mytext.replace(/\{\{(Further)\|\[\[/gi,"xxpark$1xx"); // Do the dup remove mycount=0; while(mycount<7 && mytext.match(/\[\[([\s_\w]+)(\|[^\]]*)?\]\][\w\W\n\r]*\[\[\1(\|[^\]]*)?\]\]/gim)!=null){ var mymatch=mytext.match(/\[\[([\s_\w]+)(\|[^\]]*)?\]\]([\w\W\n\r]*)\[\[(\1)(\|[^\]]*)?\]\]/im)[0] mytext=mytext.replace(/\[\[([\s_\w]+)(\|[^\]]*)?\]\]([\w\W\n\r]*)\[\[(\1)(\|[^\]]*)?\]\]/im,"$1$2$3!!xmx!!$4!!xnx!!$5!!xox!!"); var mymatch=mytext.match(/!!xmx!!.*?!!xox!!/)[0]; var myaltname=mymatch.split('!!')[4].replace('|',''); // Use the alternative link text rather than the w-link itself if(myaltname==){mytext=mytext.replace(/!!xmx!!/,);mytext=mytext.replace(/!!xnx!!!!xox!!/,)}else{mytext=mytext.replace(/!!xmx!!.*?!!xnx!!\|/,);mytext=mytext.replace(/!!xox!!/,'')} mycount++; } if(mycount>6){ // en-mass for large pages otherwise may cause excessive wait mytext=mytext.replace(/\[\[([\s_\w]+)(\|[^\]]*)?\]\]([\w\W\n\r]*)\[\[(\1)(\|[^\]]*)?\]\]/gim,"$1$2$3!!xmx!!$4!!xnx!!$5!!xox!!"); var mymatch=mytext.match(/!!xmx!!.*?!!xox!!/)[0]; var myaltname=''; while(mymatch!=null){ myaltname=mymatch.split('!!')[4].replace('|',''); // Use the alternative link text rather than the w-link itself if(myaltname==){mytext=mytext.replace(/!!xmx!!/,);mytext=mytext.replace(/!!xnx!!!!xox!!/,)}else{mytext=mytext.replace(/!!xmx!!.*?!!xnx!!\|/,);mytext=mytext.replace(/!!xox!!/,'')} if(mytext.match(/!!xmx!!.*?!!xox!!/)!=null){var mymatch=mytext.match(/!!xmx!!.*?!!xox!!/)[0]}else{mymatch=null}; } }  // Unparking mytext=mytext.replace(/xxpark(\w+)xx/g,"{{$1|OVERLINK. ';   }else{      cmt+='Rm ';      if(mycount<7){        cmt+=mycount.toString;      }else{        cmt+='many';      }      cmt+=' duplicate w-links, see OVERLINK. ';    }  }  //  // Tidy unneeded quotes on ref names  //  var rnPattern=/()/g;  if(mytext.match(rnPattern)!=null){    mytext=mytext.replace(rnPattern,"$1=$2$3$4"); // Tidy up surplus spacing in refs  }  //  // Tidy surplus template spaces  //  mytext=mytext.replace(/\{\{ +/g,"{{");  mytext=mytext.replace(/(\{\{[^\{^\}]+) +\}\}/g,"$1}}");  mytext=mytext.replace(/(<.ref>)[\s]+(<ref)/g,"$1$2"); // Rm odd spacing between footnotes  mytext=mytext.replace(/(\.|,|;) (<ref)/g,"$1$2"); // Rm odd spacing before footnotes  //  // Remove image right option from thumbnail images (default value)  //  mytext=mytext.replace(/(\[\[image[^\]]*)(thumb[^\]]*)\|right/gi,'$1$2'); mytext=mytext.replace(/(\[\[image[^\]]*)\|right([^\]]*thumb)/gi,'$1$2'); // // Final output // return mytext; }