Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
if(autosummary==null)varautosummary=true;//generate a short summaryif(showdiff==null)varshowdiff=false;//show diff after pressing buttonif(markminor==null)varmarkminor=true;//mark as minorfunctiontidy(str){vartxt=document.editform.wpTextbox1;// Fill an array with one entry per each recognized citation templatevaroriginalTemplates=txt.value.match(/\{\{[Cc]it(ation|e [A-Za-z ]+) *\n? *\|[^}]+\}\}/g);// Duplicate the array, for editing. We need to keep the original strings for the replacement stepvartweakedTemplates=originalTemplates.slice();for(vari=0;i<originalTemplates.length;i++){// Fill an array with one entry per each parameter for this citation templatevaroriginalParams=originalTemplates[i].match(/ *\n? *\| *\n? *([a-zA-Z1-9]+|[a-zA-Z1-9]+ [a-zA-Z1-9]+) *= */g);// Create array to be filled with the cleaned-up parameters.// We need to keep the original strings for the replacement step.vartweakedParams=[];if(str=="horizontal"||str=="crammed"||str=="roomy"){// Remove newlinestweakedTemplates[i]=tweakedTemplates[i].replace(/\n/g,"");// Normalize spaces around the pipes and equal signsswitch(str){case"horizontal":tweakedTemplates[i]=tweakedTemplates[i].replace(/ *\| *([a-zA-Z1-9]+|[a-zA-Z1-9]+ [a-zA-Z1-9]+) *= */g," |$1=");break;case"crammed":tweakedTemplates[i]=tweakedTemplates[i].replace(/ *\| *([a-zA-Z1-9]+) *= */g,"|$1=");break;case"roomy":tweakedTemplates[i]=tweakedTemplates[i].replace(/ *\| *([a-zA-Z1-9]+) *= */g," | $1 = ");break;}// Remove potential extra spaces before template endstweakedTemplates[i]=tweakedTemplates[i].replace(/ *\}\}$/,"}}");txt.value=txt.value.replace(originalTemplates[i],tweakedTemplates[i]);}elseif(str=="vertical"){varmaxWidth=0;for(varj=0;j<originalParams.length;j++){// Get rid of the delimiters and spaces, keep only the parameter stringtweakedParams[j]=originalParams[j].match(/[a-zA-Z1-9]+/)[0];// Calculate the length of the longest parametermaxWidth=(tweakedParams[j].length>maxWidth)?tweakedParams[j].length:maxWidth;}maxWidth++;// We need an extra one because Array(n).join(' ') will produce a string with n-1 chars// Generate the aligned versions of the parameters (with padding before the equal signs)for(vark=0;k<originalParams.length;k++){varnumSpaces=maxWidth-tweakedParams[k].length;varalignedParam="\n | "+tweakedParams[k]+newArray(numSpaces).join(" ")+" = ";// Replace the original parameters with the tweakes onestweakedTemplates[i]=tweakedTemplates[i].replace(originalParams[k],alignedParam);}// Also align the }}tweakedTemplates[i]=tweakedTemplates[i].replace(/ *\n? *\}\}/g,"\n}}");// Replace the original templates with the tweaked versionstxt.value=txt.value.replace(originalTemplates[i],tweakedTemplates[i]);}if(autosummary)edit_summary();if(showdiff)diff();if(markminor)document.editform.wpMinoredit.checked=true;}}functionedit_summary(){varsum=document.editform.wpSummary;varsummary="Harmonize whitespace in citation templates";summary+=" (using [[User:Meteor sandwich yum/Tidy citations.js|a script]])";if(sum.value.indexOf(summary)==-1){if(sum.value.match(/[^\*\/\s][^\/\s]?\s*$/)){sum.value+=" | ";}sum.value+=summary;}}functiondiff(){document.editform.wpDiff.click();}$(function(){if(document.forms.editform){mw.util.addPortletLink('p-tb','javascript:tidy("horizontal")','\{\{Tidy\}\}','ca-formatcitations','Format citations: tidy whitespace');mw.util.addPortletLink('p-tb','javascript:tidy("vertical")','\{\{Tidy\}\} (vertically)','ca-formatcitations-vertical','Formats citations & tidy whitespace (vertically)');mw.util.addPortletLink('p-tb','javascript:tidy("crammed")','\{\{Crammed\}\}','ca-formatcitations-crammed','Formats citations without any whitespace whatsoever');mw.util.addPortletLink('p-tb','javascript:tidy("roomy")','\{\{Roomy\}\}','ca-formatcitations-roomy','Formats citations with a lot of whitespace');}});//for dummy edits add more or less to end of this line