Jump to content

Wikipedia:AutoEd/whitespace.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Plastikspork (talk | contribs) at 02:15, 15 August 2012 (Commenting one of the more aggressive whitespace removers, and modifying the heading whitespace code (per multiple requests on my talk page)). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

//

function autoEdWhitespace(str) { //MAIN FUNCTION describes list of fixes

    str = str.replace(/\t/g, " ");
 
    str = str.replace(/^ ? ? \n/gm, "\n");
    str = str.replace(/(\n\n)\n+/g, "$1");
    str = str.replace(/== ? ?\n\n==/g, "==\n==");
    str = str.replace(/\n\n(\* ?\[?http)/g, "\n$1");
 
    str = str.replace(/^ ? ? \n/gm, "\n");
    str = str.replace(/\n\n\*/g, "\n*");
//  str = str.replace(/[ \t][ \t]+/g, " ");
    str = str.replace(/([=\n]\n)\n+/g, "$1");
    str = str.replace(/ \n/g, "\n");
 
    //* bullet points
    str = str.replace(/^([\*#]+:*) /gm, "$1");
    str = str.replace(/^([\*#]+:*)/gm, "$1 ");
 
    //==Headings==
    str = str.replace(/^(={1,4} )[ ]*([^= ][^=]*[^= ])[ ]*( ={1,4})$/gm, "$1$2$3");
    str = str.replace(/^(={1,4})([^= ][^=]*[^= ])[ ]+(={1,4})$/gm, "$1$2$3");
    str = str.replace(/^(={1,4})[ ]+([^= ][^=]*[^= ])(={1,4})$/gm, "$1$2$3");

    return str;
}

//