Wikipedia:AutoEd/whitespace.js: Difference between revisions

Content deleted Content added
Commenting one of the more aggressive whitespace removers, and modifying the heading whitespace code (per multiple requests on my talk page)
Pppery changed the content model of the page Wikipedia:AutoEd/whitespace.js from "wikitext" to "JavaScript"
 
(12 intermediate revisions by 2 users not shown)
Line 1:
//<source lang=javascript>
 
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");
// Extra newlines
str = str.replace(/== ? ?\n\n==/g, "==\n==");
if(str.search(/\uE000/g) < 0) { // see [[Private Use Area]]
// Mark spacing before stub templates
str = str.replace(/(\n)[ \t]*(\n)[ \t]*(\n\{\{[^{}]*\-stub\}\})/gm, "$1\uE000$2\uE000$3");
str = str.replace(/^(\n)[ \t]*#(\n\{\{[^{}]+:*\-stub\}\}) /gm, "$1\uE000$2");
// Remove extra newlines
str = str.replace(/(?:[\t ]*\n)+[\t ]*(\n\uE000\n\uE000\n)/gm, "$1");
str = str.replace(/(\n\n)\n+/ggm, "$1");
str = str.replace(/(\n[\t ]*\n)(?:[\t ]*\n)+/g, "$1");
// Unmark
str = str.replace(/\uE000/g, '');
}
 
// str = str.replace(/== ? ?\n\n==/g, "==\n==");
str = str.replace(/\n\n(\* ?\[?http)/g, "\n$1");
Line 13 ⟶ 23:
str = str.replace(/\n\n\*/g, "\n*");
// str = str.replace(/[ \t][ \t]+/g, " ");
str = str.replace(/([=\n[\t ]*\n[\t ]*\n)(?:[\t ]*\n)+/g, "$1");
str = str.replace(/ \n/g, "\n");
//* bullet points
if(str.search(/\uE000/g) < 0) { // see [[Private Use Area]]
str = str.replace(/^([\*#]+:*) /gm, "$1");
str = str.replace(/^([\*#]+:*)(REDIRECT)/gmgi, "'$1 "\uE000$2'); // Mark redirects
str = str.replace(/^([\*#]+:*) /gm, "$1");
str = str.replace(/^([\*#]+:*)/gm, "$1 ");
str = str.replace(/[\t ]*\uE000[\t ]*/g, ''); // Unmark redirects
}
//==Headings==
Line 27 ⟶ 41:
return str;
}
 
//</source>