User:Isochrone/AutoEd/extrabreaks.js

Source: Wikipedia, the free encyclopedia.
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.
//<syntaxhighlight lang=javascript>
 
function autoEdExtraBreaks(str) { //MAIN FUNCTION describes list of fixes
 
//Usually unneeded BR tags from ends of image descriptions and wikilinks (]]), templates (}}), template parameters (|)
str = str.replace(/[\t ]*<[\s\/\.]*br[\s\/\.]*>[\t ]*([\t\n ]*?)(\]\]|}}|\|)/gim, '$1$2');
//BR tag before a list item
str = str.replace(/[\t ]*<[\s\/\.]*br[\s\/\.]*>[\t ]*([\s]*?[\n]\*)/gim, '$1');
//BR tag followed by at least two newlines
str = str.replace(/[\t ]*<[\s\/\.]*br[\s\/\.]*>[\t ]*([\n])[\t ]*([\n])/gim, '$1$2');
 
return str;
}
 
//</syntaxhighlight>