User:Skynxnex/autoed.js

// Custom AutoEd configuration based on AutoEd/complete.js. // Maybe move this to its own file sometime?

var AutoEd_baseurl = 'https://en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=Wikipedia:AutoEd/'; //Import individual modules for use mw.loader.load(AutoEd_baseurl + 'unicodify.js'); // autoEdUnicodify converts HTML entities to WikiText mw.loader.load(AutoEd_baseurl + 'isbn.js'); // autoEdISBN fixes ISBN syntax so that WikiMagic can work // mw.loader.load(AutoEd_baseurl + 'whitespace.js'); // autoEdWhitespace cleans up whitespace //mw.loader.load(AutoEd_baseurl + 'wikilinks.js'); // autoEdWikilinks simplifies and shortens wikilinks where appropriate mw.loader.load(AutoEd_baseurl + 'htmltowikitext.js'); // autoEdHTMLtoWikitext converts HTML to wikitext mw.loader.load(AutoEd_baseurl + 'headlines.js'); // autoEdHeadlines fixes common headline errors and renames some headers mw.loader.load(AutoEd_baseurl + 'unicodecontrolchars.js'); // autoEdUnicodeControlChars converts HTML to wikitext mw.loader.load(AutoEd_baseurl + 'unicodehex.js'); // autoEdUnicodeHex converts hex encoded characters to unicode mw.loader.load(AutoEd_baseurl + 'templates.js'); // autoEdTemplates cleans up templates mw.loader.load(AutoEd_baseurl + 'tablestowikitext.js'); // autoEdTablestoWikitext replaces HTML tables with wikitables mw.loader.load(AutoEd_baseurl + 'extrabreaks.js'); // autoEdExtraBreaks removes extra BR tags //mw.loader.load(AutoEd_baseurl + 'links.js'); // autoEdLinks cleans up common link errors importScript('User:Jerome_Frank_Disciple/curlyfixer.js');

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

str = str.replace(/\t/g, " "); str = str.replace(/^ ? ? \n/gm, "\n");

// Extra newlines 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+/gm, "$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"); str = str.replace(/^ ? ? \n/gm, "\n"); 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"); // Don't remove extra white space after =s ??? //   str = str.replace(/ \n/g, "\n"); str = str.replace(/([^=]) +\n/g, "$1\n");

//* bullet points if(str.search(/\uE000/g) < 0) { // see Private Use Area str = str.replace(/^(\#)(REDIRECT)/gi, '$1\uE000$2'); // Mark redirects // don't remove space after bullet //     str = str.replace(/^([\*#]+:*) /gm, "$1"); // don't always add a space after a bullet //     str = str.replace(/^([\*#]+:*)/gm, "$1 "); str = str.replace(/[\t ]*\uE000[\t ]*/g, ''); // Unmark redirects }   //==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; }

function autoEdRefSpace(str) { str = str.replace(/([^=|\s]) +(<ref)/g, "$1$2"); return str; }

function autoEdFunctions { //Activates individual modules when "auto ed" tab is clicked var $textbox = $( '#wpTextbox1' ); var txt = $textbox.textSelection('getContents'); var prev = txt; var changes = []; txt = autoEdUnicodify(txt); if (txt !== prev) { changes.push("unicodify"); } prev = txt; txt = autoEdISBN(txt); if (txt !== prev) { changes.push("ISBN"); } prev = txt; txt = autoEdWhitespace(txt); if (txt !== prev) { changes.push("whitespace"); } prev = txt; txt = autoEdUnicodeHex(txt); if (txt !== prev) { changes.push("unicode hex"); } //   prev = txt; //   txt = autoEdWikilinks(txt); //   if (txt !== prev) { changes.push("wiki links"); } prev = txt; txt = autoEdHTMLtoWikitext(txt); if (txt !== prev) { changes.push("HTML to wikitext"); } prev = txt; txt = autoEdHeadlines(txt); if (txt !== prev) { changes.push("headlines"); } prev = txt; txt = autoEdUnicodeControlChars(txt); if (txt !== prev) { changes.push("unicode control chars"); } prev = txt; txt = autoEdTemplates(txt); if (txt !== prev) { changes.push("templates"); } prev = txt; txt = autoEdTablestoWikitext(txt); if (txt !== prev) { changes.push("tables to wikitext"); } prev = txt; txt = autoEdExtraBreaks(txt); if (txt !== prev) { changes.push("extra breaks"); } //   prev = txt; //   txt = autoEdLinks(txt); //   if (txt !== prev) { changes.push("links"); } prev = txt; txt = autoEdCurlyFixer(txt); if (txt !== prev) { changes.push("curly quotes"); } prev = txt; // mine: txt = autoEdRefSpace(txt); if (txt !== prev) { changes.push("ref spacing"); } prev = txt; if (changes) { window.autoEdTag = "Cleaned up using AutoEd | " + "fixes: " + changes.join(', '); }   $textbox.textSelection('setContents', txt); }

$.when( $.ready, mw.loader.using( 'jquery.textSelection' ) ).then(function { mw.loader.load(AutoEd_baseurl + 'core.js'); //Imports the "framework" script needed to make this function });