پرش به محتوا

مدیاویکی:Gadget-Extra-Editbuttons-autoed.js: تفاوت میان نسخه‌ها

از دانشنامه علوم انسانی
imported>Ebrahim
جز Ebraminio صفحهٔ مدیاویکی:Gadget-Extra-Editbuttons-MoreFunctions.js را بدون برجای‌گذاشتن تغییرمسیر به مدیاویکی:Gadget-Extra-Editbuttons-autoed.js منتقل کرد
imported>Yamaha5
+ Replace <ol><li> with # and Replace <ul><li> with *
 
(۲۲ نسخهٔ میانی ویرایش شده توسط ۴ کاربر نشان داده نشد)
خط ۱: خط ۱:
/*global mw*/
//Selected from [[:en:WP:AutoEd]] scripts
//Selected from [[:en:WP:AutoEd]] scripts
 
var autoEd = (function () {
//---------------------isbn.js--------------------------------------
    "use strict";
function autoEdISBN(str) { //MAIN FUNCTION describes list of fixes
    //---------------------isbn.js--------------------------------------
    function autoEdISBN(str) { //MAIN FUNCTION describes list of fixes


         //Allows WikiMagic to work with ISBNs
         //Allows WikiMagic to work with ISBNs
         str = str.replace(/ISBN-10:|ISBN-13:|ISBN-10|ISBN-13|ISBN:/gi, 'ISBN');
         str = str.replace(/ISBN *\-10:|ISBN *\-13:|ISBN *\-10|ISBN *\-13|ISBN:/gi, "ISBN");
        //ISSN regexs from [[:en:Wikipedia:AutoWikiBrowser/Settings/ISSN]]
        str = str.replace(/ISSN\s*(\d)/gi,"ISSN $1");
        str = str.replace(/ISSN (\d)(\d)(\d)(\d)[\.\: ~\=]*(\d)(\d)(\d)([\dx])/gi,"ISSN $1$2$3$4-$5$6$7$8 ");
        str = str.replace(/ISSN (\d)(\d)(\d)(\d)\-(\d)(\d)(\d)x/gi,"ISSN $1$2$3$4-$5$6$7X");
        str = str.replace(/ISSN (\d)(\d)(\d)(\d)\-(\d)(\d)(\d)x/gi,"ISSN $1$2$3$4-$5$6$7X");


         return str;
        //ISBN regexs from [[:Wikipedia:AutoWikiBrowser/Settings/ISBN-hyph]]
        str = str.replace(/ISBN(\d)/gi,"ISBN $1");
        str = str.replace(/\[\[ *(ISBN [\d\-x]{10,13}) *\]\]/gi,"$1");
        str = str.replace(/\[\[ISBN\|(ISBN\s*[^\]]*)\]\]/gi,"$1");
        str = str.replace(/\[*ISBN\]*\:*[ \t]+([0-9X\-]+)/gi,"ISBN $1");
        str = str.replace(/ISBN +([\d-]{1,9}) (\d+|X\W)/gi,"ISBN $1$2");
        str = str.replace(/\[*ISBN\]*\:* *\[\[Special\:Booksources\/\d*\|([\dxX\- ]+)\]\]/gi,"ISBN $1");
        str = str.replace(/\[isbn\]\:* *(\d)/gi,"ISBN $1");
        str = str.replace(/ISBN (\d{10,10}) - *(\d)/gi,"ISBN $1 ,$2");
        var loopcount = 0;
        while (loopcount<10) { //'
            str = str.replace(/ISBN (\d{1,9}) (\d|x)/gi,"ISBN $1$2");
            loopcount++;
        }
        str = str.replace(/ISBN (\d{1,9})(x)/gi,"ISBN $1X");
        str = str.replace(/ISBN (\d\d\d\d\d\d\d\d\d(\d|x)) +(\d)/gi,"ISBN $1, $3");
        str = str.replace(/ISBN ([\d-]{12,12}) (\d|x)/gi,"ISBN $1-$2");
        /* broken ISBNs with hyphens */
        // autoFormatter.js > cleanISBNs
        str = str.replace(
            /(^|[\s#'(*>|])(?:(ISBN\d?\s*=\s*)|ISBN(?:-?1[03]\b| *1[03]:)?:?\s*)(9-?7-?[89]-?)?([013][\d\u2010-\u2012\u2212-]{8,}[\dX]\b)/gim,
            function( $0, $1, $2, $3, $4 ) {
                return $1 + ( $2 || 'ISBN ' ) + ( $3 || '' ).replace( /^9\D*7\D*(\d)\D*/, '97$1-' ) + $4
                    /* Remove all dashes */
                    .replace( /[^\dX]+/gi, '' )
                    /* Group 0 for English books */
                    .replace( /^0([01]\d)(\d{6})\B/, '0$1-$2-' )
                    .replace( /^0([2-6]\d\d)(\d{5})\B/, '0$1-$2-' )
                    .replace( /^0(7\d{3}|8[0-4]\d\d)(\d{4})\B/, '0$1-$2-' )
                    .replace( /^0(8[5-9]\d{3})(\d{3})\B/, '0$1-$2-' )
                    .replace( /^0(9[0-4]\d{4})(\d\d)\B/, '0$1-$2-' )
                    .replace( /^0(9[5-9]\d{5})(\d)\B/, '0$1-$2-' )
                    /* Group 1 for English books */
                    .replace( /^1(0\d)(\d{6})\B/, '1$1-$2-' )
                    .replace( /^1([1-3]\d\d)(\d{5})\B/, '1$1-$2-' )
                    .replace( /^1(4\d{3}|5[0-4]\d\d)(\d{4})\B/, '1$1-$2-' )
                    .replace( /^1(5[5-9]\d{3}|[67]\d{4}|8[0-5]\d{3}|86[0-8]\d\d|869[0-7]\d)(\d{3})\B/, '1$1-$2-' )
                    .replace( /^1(869[89]\d\d|8[7-9]\d{4}|9[0-8]\d{4}|99[0-8]\d{3})(\d\d)\B/, '1$1-$2-' )
                    .replace( /^1(999\d{4})(\d)\B/, '1$1-$2-' )
                    /* Group 3 for German books */
                    .replace( /^3(0[0-24-9]|1\d)(\d{6})\B/, '3$1-$2-' )
                    .replace( /^3(03[0-3]|[2-6]\d\d)(\d{5})\B/, '3$1-$2-' )
                    .replace( /^3(03[4-6]\d|7\d{3}|8[0-4]\d\d)(\d{4})\B/, '3$1-$2-' )
                    .replace( /^3(03[7-9]\d\d|8[5-9]\d{3}|95[4-9]\d\d|9[69]\d{3})(\d{3})\B/, '3$1-$2-' )
                    .replace( /^3(9[0-4]\d{4})(\d\d)\B/, '3$1-$2-' )
                    .replace( /^3(95[0-3]\d{4}|9[78]\d{5})(\d)\B/, '3$1-$2-' )
                    /* Add missing dash after group */
                    .replace( /^([0-57]|6\d\d|8\d|9[0-4]|9[5-8]\d|99[0-8]\d|999\d\d)\B/, '$1-' );
            }
        );
         return str
     }
     }


//---------------------whitespace.js--------------------------------
    //---------------------whitespace.js--------------------------------
function autoEdWhitespace(str) { //MAIN FUNCTION describes list of fixes
    function autoEdWhitespace(str) { //MAIN FUNCTION describes list of fixes


         str = str.replace(/\t/g, " ");
         str = str.replace(/\t/g, " ");
خط ۲۵: خط ۸۲:
         str = str.replace(/([=\n]\n)\n+/g, "$1");
         str = str.replace(/([=\n]\n)\n+/g, "$1");
         str = str.replace(/ \n/g, "\n");
         str = str.replace(/ \n/g, "\n");
        //* bullet points
        str = str.replace(/^([\*#]+:*) /gm, "$1");
        str = str.replace(/^([\*#]+:*)/gm, "$1 ");


         //==Headings==
         //==Headings==
خط ۳۸: خط ۹۱:
     }
     }


//---------------------wikilinks.js-------------------------------
     //---------------------htmltowikitext.js--------------------------------
// Credits: A modification of [[Wikipedia:WikiProject User scripts/Scripts/Formatter]]
    //Convert HTML to wikitext
function autoEdWikilinks(str) { //MAIN FUNCTION describes list of fixes
    function autoEdHTMLtoWikitext(str) {
 
    //Get the list of all wikilinks with underscores
    var m = str.match(/\[\[[^\[\]]*_[^\[\]]*\]\]/g);
    if (m) {
        //For each wikilink in the list
        for (var i = 0; i < m.length; i++) {
            var x = m[i].toString() // Contains the entire wikilink
                // Exclude URLs and leading underscores
            if (!x.match(/^\[\[[\t ]*(?:http|ftp|https):/i) && !x.match(/^\[\[_[^\[\]]*\]\]/)) {
                var x_arr = x.match(/^(\[\[[^\[\]\|]*)(\|?[^\[\]]*?\]\])$/);
                var a = x_arr[1]; // Everything before the pipe (or everything minus ]])
                var b = x_arr[2]; // Everything after the pipe (or ]])
 
                // Replace underscores with spaces
                a = a.replace(/_/g, ' ');
                // Do the replacement
                str = str.replace(x, a + b);
            }
        }
    }
 
    //Fix links which have no target
    str = str.replace(/\[\[[\t ]*\|/gi, '[[');
 
    //Leading and trailing space before the pipe inside wikilinks
    str = str.replace(/(\[\[)[\t ]+([^\[\]\|]*?)(\|)/g, '$1$2$3');
    str = str.replace(/(\[\[)([^\[\]\|]*?)[\t ]+(\|)/g, '$1$2$3');
    //Leading space after the pipe (or in an unpiped) wikilink
    str = str.replace(/^(\[\[[^\[\]\|]*?\||\[\[)[\t ]+([^\[\]\|\t ][^\[\]\|]*?)(\]\])/g, '$1$2$3');
    str = str.replace(/(\[\[[^\[\]\|]*?\||\[\[)[\t ]+([^\[\]\|\t ][^\[\]\|]*?)(\]\])/g, ' $1$2$3');
    //Trailing space after the pipe (or in an unpiped) wikilink
    str = str.replace(/(\[\[[^\[\]\|]*?\||\[\[)([^\[\]\|\t ][^\[\]\|]*?)[\t ]+(\]\])([^A-Za-z])/gi, '$1$2$3 $4');
    str = str.replace(/(\[\[[^\[\]\|]*?\||\[\[)([^\[\]\|]*?)[\t ]+(\]\])$/gi, '$1$2$3');
 
    //Get the list of all piped wikilinks
    var m = str.match(/\[\[[^\[]*?\|[^\[]*?\]\]/g);
    if (m) {
        //For each piped wikilink in the list
        for (var i = 0; i < m.length; i++) {
            var n_arr = m[i].toString().match(/\[\[[ ]*([^\[]*?)\|[ ]*([^\[]*?)\]\]/);
            var n = n_arr[0]; // Contains the entire piped link
            var a = n_arr[1]; // Contains everything before pipe
            var b = n_arr[2]; // Contains everything after pipe
            var c = b.replace(/[\.,:; ]*$/); // Same as b, but without trailing punctuation
            //Is the display name a leading substring of the wikilink?
            if (b.indexOf(a) == 0 || b.indexOf(autoEd_first2lower(a)) == 0) {
                //Create a simplified replacement string
                var k = n.replace(/\[\[([^\]\|]*?)\|(\1)([\w]*?)\]\]/i, "[[$2]]$3");
                //And do the replacement
                str = str.replace(n, k);
            }
            if (c.indexOf(a) == 0 || c.indexOf(autoEd_first2lower(a)) == 0) {
                // Create a simplified replacement string
                var k = n.replace(/\[\[([^\]\|]*?)\|(\1)([\w\.,:;]*?)\]\]/i, "[[$2]]$3");
                // And do the replacement
                str = str.replace(n, k);
            }
        }
    }
 
    //Push trailing characters into display string of piped wikilinks
    str = str.replace(/\[\[([^\[\]\|]+)\|([^\[\]\|]+)\]\]([a-z]+)/g, "[[$1|$2$3]]");
 
    //Removes links to current article
    var p1 = wgPageName; // PAGENAME including underscores
    var p2 = wgPageName.replace('_', ' '); // PAGENAME without underscores
    var p3 = autoEd_first2lower(p1); // First character lowercase PAGENAME including underscores
    var p4 = autoEd_first2lower(p2); // First character lowercase PAGENAME without underscores
    // Standard wikilinks
    str = str.replace(new RegExp('\\[\\[(' + p1 + '|' + p2 + '|' + p3 + '|' + p4 + ')\\]\\]', 'g'), '$1');
    // Piped wikilinks
    str = str.replace(new RegExp('\\[\\[(?:' + p1 + '|' + p2 + '|' + p3 + '|' + p4 + ')\\|([^\\]\\|]*)\\]\\]', 'g'), '$1');
 
    //Shorten interwiki links
    str = str.replace(/\[\[WIKTIONARY:/gi, '[[wikt:');
    str = str.replace(/\[\[WIKINEWS:/gi, '[[n:');
     str = str.replace(/\[\[WIKIBOOKS:/gi, '[[b:');
    str = str.replace(/\[\[WIKIQUOTE:/gi, '[[q:');
    str = str.replace(/\[\[WIKISOURCE:/gi, '[[s:');
    str = str.replace(/\[\[WIKISPECIES:/gi, '[[species:');
    str = str.replace(/\[\[WIKIVERSITY:/gi, '[[v:');
    str = str.replace(/\[\[(?:WIKIMEDIA|FOUNDATION):/gi, '[[wmf:');
    str = str.replace(/\[\[METAWIKIPEDIA:/gi, '[[m:');
 
    //Replace [[Foo #bar]] -> [[Foo#bar]]
    str = str.replace(/\[\[([^\]]*?)( |_)+#([^\]]*?)\]\]/g, '[[$1#$3]]');
 
    //Replace [[Foo|Foo]] -> [[Foo| ]]
    str = str.replace(/\|\]\]/g, '| ]]');
 
    return str;
}
 
// Converts the first character in a string to lower case
// Notes: Used by autoEdWikilinks
function autoEd_first2lower(str) {
    if (str != "") {
        var letter = str.substr(0, 1);
        return letter.toLowerCase() + str.substr(1, str.length);
    } else {
        return "";
    }
}
 
//---------------------htmltowikitext.js--------------------------------
//Convert HTML to wikitext
function autoEdHTMLtoWikitext(str) {
         // <b>, <strong>, <i>, and <em> tags
         // <b>, <strong>, <i>, and <em> tags
         str = str.replace(/<(B|STRONG)[ ]*>((?:[^<>]|<[a-z][^<>]*\/>|<([a-z]+)(?:| [^<>]*)>[^<>]*<\/\3>)*?)<\/\1[ ]*>/gi, "'''$2'''");
         str = str.replace(/<(B|STRONG)[ ]*>((?:[^<>]|<[a-z][^<>]*\/>|<([a-z]+)(?:| [^<>]*)>[^<>]*<\/\3>)*?)<\/\1[ ]*>/gi, "'''$2'''");
         str = str.replace(/<(I|EM)[ ]*>((?:[^<>]|<[a-z][^<>]*\/>|<([a-z]+)(?:| [^<>]*)>[^<>]*<\/\3>)*?)<\/\1[ ]*>/gi, "''$2''");
         str = str.replace(/<(I|EM)[ ]*>((?:[^<>]|<[a-z][^<>]*\/>|<([a-z]+)(?:| [^<>]*)>[^<>]*<\/\3>)*?)<\/\1[ ]*>/gi, "''$2''");
         // </br>, <\br>, <br\>, <BR />, ...
         // </br>, <\br>, <br\>, <BR />, ...
         str = str.replace(/<[\\\/]+BR[\\\/\s]*>/gim, '<br />');
         str = str.replace(/<[\\\/]+BR[\\\/\s]*>/gim, "<br />");
         str = str.replace(/<[\\\/\s]*BR[\s]*[\\\/]+[\s]*>/gim, '<br />');
         str = str.replace(/<[\\\/\s]*BR[\s]*[\\\/]+[\s]*>/gim, "<br />");
         // <.br>, <br.>, <Br>, ...
         // <.br>, <br.>, <Br>, ...
         str = str.replace(/<[\s\.]*BR[\s\.]*>/gim, '<br>');
         str = str.replace(/<[\s\.]*BR[\s\.]*>/gim, "<br>");
         // <br>>, <<br />, <<br >> ...
         // <br>>, <<br />, <<br >> ...
         str = str.replace(/<[\s]*(<br[\s\/]*>)/gim, '$1');
         str = str.replace(/<[\s]*(<br[\s\/]*>)/gim, "$1");
         str = str.replace(/(<br[\s\/]*>)[\s]*>/gim, '$1');
         str = str.replace(/(<br[\s\/]*>)[\s]*>/gim, "$1");
        // <hr>
 
        str = str.replace(/([\r\n])[\t ]*<[\\\/\. ]*HR[\\\/\. ]*>/gi, '$1----');
         str = str.replace(/<[\\\/\s]*REFERENCES[\\\/\s]*>/gim, "<references />");
        str = str.replace(/(.)<[\\\/\. ]*HR[\\\/\. ]*>/gi, '$1\n----');
        // Not really an HTML-to-wikitext fix, but close enough
         str = str.replace(/<[\\\/\s]*REFERENCES[\\\/\s]*>/gim, '<references />');
         // Repeated references tag
         // Repeated references tag
         str = str.replace(/(<references \/>)[\s]*\1/gim, '$1');
         str = str.replace(/(<references \/>)[\s]*\1/gim, "$1");
         // Make sure <H1>, ..., <H6> is after a newline
         // Make sure <H1>, ..., <H6> is after a newline
         str = str.replace(/([^\r\n ])[\t ]*(<H[1-6][^<>]*>)/gim, '$1\n$2');
         str = str.replace(/([^\r\n ])[\t ]*(<H[1-6][^<>]*>)/gim, "$1\n$2");
         // Make sure </H1>, ..., </H6> is before a newline
         // Make sure </H1>, ..., </H6> is before a newline
         str = str.replace(/(<\/H[1-6][^<>]*>)[\t ]*([^\r\n ])/gim, '$1\n$2');
         str = str.replace(/(<\/H[1-6][^<>]*>)[\t ]*([^\r\n ])/gim, "$1\n$2");
         // Remove newlines from inside <H1>, ..., <H6>
         // Remove newlines from inside <H1>, ..., <H6>
         var loopcount = 0;
         var loopcount = 0;
         while (str.search(/<H([1-6])[^<>]*>(?:[^<>]|<\/?[^\/h\r\n][^<>]*>)*?<\/H\1[^<>]*>/gim) >= 0 && loopcount <= 10) {
         while (str.search(/<H([1-6])[^<>]*>(?:[^<>]|<\/?[^\/h\r\n][^<>]*>)*?<\/H\1[^<>]*>/gim) >= 0 && loopcount <= 10) {
             str = str.replace(/(<H)([1-6])([^<>]*>(?:[^<>]|<\/?[^\/h\r\n][^<>]*>)*?)[\r\n]((?:[^<>]|<\/?[^\/h\r\n][^<>]*>)*?<\/H)\2([^<>]*>)/gim, '$1$2$3 $4$2$5');
             str = str.replace(/(<H)([1-6])([^<>]*>(?:[^<>]|<\/?[^\/h\r\n][^<>]*>)*?)[\r\n]((?:[^<>]|<\/?[^\/h\r\n][^<>]*>)*?<\/H)\2([^<>]*>)/gim, "$1$2$3 $4$2$5");
             loopcount++;
             loopcount++;
         }
         }
خط ۱۸۳: خط ۱۲۶:
         str = str.replace(/(^|[\r\n])[\t ]*<H5[^<>]*>([^\r\n]*?)<\/H5[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1=====$2=====$3');
         str = str.replace(/(^|[\r\n])[\t ]*<H5[^<>]*>([^\r\n]*?)<\/H5[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1=====$2=====$3');
         str = str.replace(/(^|[\r\n])[\t ]*<H6[^<>]*>([^\r\n]*?)<\/H6[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1======$2======$3');
         str = str.replace(/(^|[\r\n])[\t ]*<H6[^<>]*>([^\r\n]*?)<\/H6[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1======$2======$3');
        //Replace <ol><li> with #
        str = str.replace(
                    /(\<ol\>[\s\S]+\<\/ol\>)/g,
                    function($1) {
                        return $1.replace(/[\r\n] *\<li\>/g,'\n# ').replace(/\<\/li\>/g,'');
                    }
                ).replace(/\n\<\/?ol\>/g,'')
        //Replace <ul><li> with *
        str = str.replace(
                    /(\<ul\>[\s\S]+\<\/ul\>)/g,
                    function($1) {
                        return $1.replace(/[\r\n] *\<li\>/g,'\n* ').replace(/\<\/li\>/g,'');
                    }
                ).replace(/\n\<\/?ul\>/g,'')


         return str;
         return str;
     }
     }


//---------------------headlines.js--------------------------------
    //---------------------headlines.js--------------------------------
function autoEdHeadlines(str) { //MAIN FUNCTION describes list of fixes
    function autoEdHeadlines(str) { //MAIN FUNCTION describes list of fixes


    // Remove bold from section headings
        // Remove bold from section headings
    var loopcount = 0;
        var loopcount = 0;
    while (str.search(/^[=]{1,5}[^=\r\n]*'''[^=\r\n]*[=]{1,5}/gim) >= 0 && loopcount <= 10) { //'
        while (str.search(/^[=]{1,5}[^=\r\n]*'''[^=\r\n]*[=]{1,5}/gim) >= 0 && loopcount <= 10) { //'
        str = str.replace(/(^[=]{1,5}[^=\r\n]*)'''([^=\r\n]*[=]{1,5})[\t ]*/gim, '$1$2'); //'
            str = str.replace(/(^[=]{1,5}[^=\r\n]*)'''([^=\r\n]*[=]{1,5})[\t ]*/gim, "$1$2"); //'
        loopcount++;
            loopcount++;
    }
        }


    // Remove trailing colon from section headings
        // Remove trailing colon from section headings
    str = str.replace(/(^[=]{1,5}[^=\r\n]*)[:]([\t ]*[=]{1,5})[\t ]*/gim, '$1$2');
        str = str.replace(/(^[=]{1,5}[^=\r\n]*)[:]([\t ]*[=]{1,5})[\t ]*/gim, "$1$2");


    // Correct caps in "See also" section
        // Correct caps in "See also" section
    str = str.replace(/(==[\t ]*)see also([\t ]*==)/gi, "$1See also$2");
        str = str.replace(/(==[\t ]*)see also([\t ]*==)/gi, "$1See also$2");


    // Change common synonyms for "See also" to "See also", but only if "See also" doesn't exist
        // Change common synonyms for "See also" to "See also", but only if "See also" doesn't exist
    if (!str.match(/=[\t ]*See also[\t ]*=/gi)) {
        if (!str.match(/=[\t ]*See also[\t ]*=/gi)) {
        str = str.replace(/(==[\t ]*)(?:related topics|related articles|internal links|also see)([\t ]*==)/gi, "$1See also$2");
            str = str.replace(/(==[\t ]*)(?:related topics|related articles|internal links|also see)([\t ]*==)/gi, "$1See also$2");
    }
        }
    // Common synonyms for "External links"
        // Common synonyms for "External links"
    str = str.replace(/(==[\t ]*)(?:external links?|outside links?|web ?links?|exterior links?)([\t ]*==)/gi, "$1External links$2");
        str = str.replace(/(==[\t ]*)(?:external links?|outside links?|web ?links?|exterior links?)([\t ]*==)/gi, "$1External links$2");


    // Capitalization and/or plural of "References", "Sources", "Further reading"
        // Capitalization and/or plural of "References", "Sources", "Further reading"
    str = str.replace(/(==[\t ]*)references([\t ]*==)/gi, "$1References$2");
        str = str.replace(/(==[\t ]*)references([\t ]*==)/gi, "$1References$2");
    str = str.replace(/(==[\t ]*)sources([\t ]*==)/gi, "$1Sources$2");
        str = str.replace(/(==[\t ]*)sources([\t ]*==)/gi, "$1Sources$2");
    str = str.replace(/(==[\t ]*)further readings?([\t ]*==)/gi, "$1Further reading$2");
        str = str.replace(/(==[\t ]*)further readings?([\t ]*==)/gi, "$1Further reading$2");


    return str;
        return str;
}
    }




//---------------------tablestowikitext.js--------------------------------
    //---------------------tablestowikitext.js--------------------------------
function autoEdTablestoWikitext(str) { //MAIN FUNCTION describes list of fixes
    function autoEdTablestoWikitext(str) { //MAIN FUNCTION describes list of fixes


         // Remove newlines from inside table specific tags
         // Remove newlines from inside table specific tags
         var loopcount = 0;
         var loopcount = 0;
         while (str.search(/(?:<\/?table|<\/?tr|<\/?td|<\/?th)[^<>]*[\r\n]/gi) >= 0 && loopcount <= 10) {
         while (str.search(/(?:<\/?table|<\/?tr|<\/?td|<\/?th)[^<>]*[\r\n]/gi) >= 0 && loopcount <= 10) {
             str.replace(/((?:<\/?table|<\/?tr|<\/?td|<\/?th)[^<>]*)[\r\n]/gi, '$1 ')
             str = str.replace(/((?:<\/?table|<\/?tr|<\/?td|<\/?th)[^<>]*)[\r\n]/gi, "$1 ");
             loopcount++;
             loopcount++;
         }
         }
         // Remove extra whitespace from inside table specific tags
         // Remove extra whitespace from inside table specific tags
         str = str.replace(/(<table|<tr|<td|<th)([^<>]*?)[\s]+(>)/gim, '$1$2$3');
         str = str.replace(/(<table|<tr|<td|<th)([^<>]*?)[\s]+(>)/gim, "$1$2$3");
         str = str.replace(/(<table|<tr|<td|<th)([^<>]*?)[\s][\s]+/gim, '$1$2 ');
         str = str.replace(/(<table|<tr|<td|<th)([^<>]*?)[\s][\s]+/gim, "$1$2 ");
         // Remove any extra junk </tr>, </td>, </th>, </table>
         // Remove any extra junk </tr>, </td>, </th>, </table>
         str = str.replace(/(<\/table|<\/tr|<\/td|<\/th)[^<>]+(>)/gim, '$1$2');
         str = str.replace(/(<\/table|<\/tr|<\/td|<\/th)[^<>]+(>)/gim, "$1$2");
         // Remove space whitespace after </tr>, </td>, </th>, <table>
         // Remove space whitespace after </tr>, </td>, </th>, <table>
         str = str.replace(/(<\/tr>|<\/td>|<\/th>|<table[^<>]*>)[\s]+/gim, '$1');
         str = str.replace(/(<\/tr>|<\/td>|<\/th>|<table[^<>]*>)[\s]+/gim, "$1");
         // Remove space before <tr>, <td>, <th>, </table>
         // Remove space before <tr>, <td>, <th>, </table>
         str = str.replace(/[\s]+(<\/table>|<tr[^<>]*>|<td[^<>]*>|<th[^<>]*>)/gim, '$1');
         str = str.replace(/[\s]+(<\/table>|<tr[^<>]*>|<td[^<>]*>|<th[^<>]*>)/gim, "$1");
         // Replace '<table>' with '{|'
         // Replace '<table>' with '{|'
         str = str.replace(/<table( [^<>]*|)>[\s]*/gim, '{|$1\n');
         str = str.replace(/<table( [^<>]*|)>[\s]*/gim, "{|$1\n");
         // Replace '</table>' with '|}'
         // Replace '</table>' with '|}'
         str = str.replace(/[\s]*<\/table>/gi, '\n|}');
         str = str.replace(/[\s]*<\/table>/gi, "\n|}");
         // Replace '</td><td>' with '||'
         // Replace '</td><td>' with '||'
         str = str.replace(/<\/td[\s]*>[\s]*<td[\s]*>/gim, '||');
         str = str.replace(/<\/td[\s]*>[\s]*<td[\s]*>/gim, "||");
         str = str.replace(/<\/td[\s]*>[\s]*<td ([^<>]+)>/gim, '|| $1 |');
         str = str.replace(/<\/td[\s]*>[\s]*<td ([^<>]+)>/gim, "|| $1 |");
         // Replace '</th><th>' with '!!'
         // Replace '</th><th>' with '!!'
         str = str.replace(/<\/th[\s]*>[\s]*<th[\s]*>/gim, '!!');
         str = str.replace(/<\/th[\s]*>[\s]*<th[\s]*>/gim, "!!");
         str = str.replace(/<\/th[\s]*>[\s]*<th ([^<>]+)>/gim, '!! $1 |');
         str = str.replace(/<\/th[\s]*>[\s]*<th ([^<>]+)>/gim, "!! $1 |");
         // Replace '</td></tr>' and '</th></tr>' with EOL
         // Replace '</td></tr>' and '</th></tr>' with EOL
         str = str.replace(/<\/(?:td|th)>[\s]*<\/tr>[\s]/gim, '\n');
         str = str.replace(/<\/(?:td|th)>[\s]*<\/tr>[\s]/gim, "\n");
         // Replace '</td>', '</th>', '</tr>' with EOL
         // Replace '</td>', '</th>', '</tr>' with EOL
         str = str.replace(/<\/(?:td|th|tr)>[\s]*/gim, '\n');
         str = str.replace(/<\/(?:td|th|tr)>[\s]*/gim, "\n");
         // Replace '<tr>' with '|-'
         // Replace '<tr>' with '|-'
         str = str.replace(/[\s]*<tr>[\s]*/gim, '\n|-\n');
         str = str.replace(/[\s]*<tr>[\s]*/gim, "\n|-\n");
         str = str.replace(/[\s]*<tr ([^<>]*)>[\s]*/gim, '\n|- $1\n');
         str = str.replace(/[\s]*<tr ([^<>]*)>[\s]*/gim, "\n|- $1\n");
         // Replace '<td>' with '|'
         // Replace '<td>' with "|"
         str = str.replace(/[\s]*<td>([^\s])/gim, '\n| $1');
         str = str.replace(/[\s]*<td>([^\s])/gim, "\n| $1");
         str = str.replace(/[\s]*<td>([\s])/gim, '\n|$1');
         str = str.replace(/[\s]*<td>([\s])/gim, "\n|$1");
         str = str.replace(/[\s]*<td[\s]*([^<>]*?)[\s]*>([^\s])/gim, '\n| $1 | $2');
         str = str.replace(/[\s]*<td[\s]*([^<>]*?)[\s]*>([^\s])/gim, "\n| $1 | $2");
         str = str.replace(/[\s]*<td[\s]*([^<>]*?)[\s]*>([\s])/gim, '\n| $1 |$2');
         str = str.replace(/[\s]*<td[\s]*([^<>]*?)[\s]*>([\s])/gim, "\n| $1 |$2");
         // Replace '<th>' with '!'
         // Replace '<th>' with '!'
         str = str.replace(/[\s]*<th>([^\s])/gim, '\n! $1');
         str = str.replace(/[\s]*<th>([^\s])/gim, "\n! $1");
         str = str.replace(/[\s]*<th>([\s])/gim, '\n!$1');
         str = str.replace(/[\s]*<th>([\s])/gim, "\n!$1");
         str = str.replace(/[\s]*<th[\s]*([^<>]*?)[\s]*>([^\s])/gim, '\n! $1 | $2');
         str = str.replace(/[\s]*<th[\s]*([^<>]*?)[\s]*>([^\s])/gim, "\n! $1 | $2");
         str = str.replace(/[\s]*<th[\s]*([^<>]*?)[\s]*>([^\s])/gim, '\n! $1 |$2');
         str = str.replace(/[\s]*<th[\s]*([^<>]*?)[\s]*>([^\s])/gim, "\n! $1 |$2");


         return str;
         return str;
     }
     }


//---------------------extrabreaks.js--------------------------------
    //---------------------extrabreaks.js--------------------------------
function autoEdExtraBreaks(str) { //MAIN FUNCTION describes list of fixes
    function autoEdExtraBreaks(str) { //MAIN FUNCTION describes list of fixes


         //Usually unneeded BR tags from ends of image descriptions and wikilinks (]]), templates (}}), template parameters (|)
         //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');
         str = str.replace(/[\t ]*<[\s\/\.]*br[\s\/\.]*>[\t ]*([\t\n ]*?)(\]\]|}}|\|)/gim, "$1$2");
         //BR tag before a list item
         //BR tag before a list item
         str = str.replace(/[\t ]*<[\s\/\.]*br[\s\/\.]*>[\t ]*([\s]*?[\n]\*)/gim, '$1');
         str = str.replace(/[\t ]*<[\s\/\.]*br[\s\/\.]*>[\t ]*([\s]*?[\n]\*)/gim, "$1");
         //BR tag followed by at least two newlines
         //BR tag followed by at least two newlines
         str = str.replace(/[\t ]*<[\s\/\.]*br[\s\/\.]*>[\t ]*([\n])[\t ]*([\n])/gim, '$1$2');
         str = str.replace(/[\t ]*<[\s\/\.]*br[\s\/\.]*>[\t ]*([\n])[\t ]*([\n])/gim, "$1$2");


         return str;
         return str;
     }
     }
 
   
//---------------------links.js--------------------------------
    return {
function autoEdLinks(str) { //MAIN FUNCTION describes list of fixes
        autoEdISBN: autoEdISBN,
 
        autoEdWhitespace: autoEdWhitespace,
    str = str.replace(/\]\[/g, "] [");
        autoEdHTMLtoWikitext: autoEdHTMLtoWikitext,
 
        autoEdHeadlines: autoEdHeadlines,
    //repair bad external links
        autoEdTablestoWikitext: autoEdTablestoWikitext,
    str = str.replace(/\[?\[http:\/\/([^\]\n]*?)\]\]?/gi, "[http://$1]");
        autoEdExtraBreaks: autoEdExtraBreaks
    //str = str.replace(/\[http:\/\/([^\]]*?)\|([^\]]*?)\]/gi, "[http://$1 $2]");
    };
 
}());
     return str;
if (typeof window !== "undefined") {
     window.autoEd = autoEd;
}
}

نسخهٔ کنونی تا ۱ فوریهٔ ۲۰۱۷، ساعت ۱۵:۰۵

/*global mw*/
//Selected from [[:en:WP:AutoEd]] scripts
var autoEd = (function () {
    "use strict";
    //---------------------isbn.js--------------------------------------
    function autoEdISBN(str) { //MAIN FUNCTION describes list of fixes

        //Allows WikiMagic to work with ISBNs
        str = str.replace(/ISBN *\-10:|ISBN *\-13:|ISBN *\-10|ISBN *\-13|ISBN:/gi, "ISBN");
        //ISSN regexs from [[:en:Wikipedia:AutoWikiBrowser/Settings/ISSN]]
        str = str.replace(/ISSN\s*(\d)/gi,"ISSN $1");
        str = str.replace(/ISSN (\d)(\d)(\d)(\d)[\.\: ~\=]*(\d)(\d)(\d)([\dx])/gi,"ISSN $1$2$3$4-$5$6$7$8 ");
        str = str.replace(/ISSN (\d)(\d)(\d)(\d)\-(\d)(\d)(\d)x/gi,"ISSN $1$2$3$4-$5$6$7X");
        str = str.replace(/ISSN (\d)(\d)(\d)(\d)\-(\d)(\d)(\d)x/gi,"ISSN $1$2$3$4-$5$6$7X");

        //ISBN regexs from [[:Wikipedia:AutoWikiBrowser/Settings/ISBN-hyph]]
        str = str.replace(/ISBN(\d)/gi,"ISBN $1");
        str = str.replace(/\[\[ *(ISBN [\d\-x]{10,13}) *\]\]/gi,"$1");
        str = str.replace(/\[\[ISBN\|(ISBN\s*[^\]]*)\]\]/gi,"$1");
        str = str.replace(/\[*ISBN\]*\:*[ \t]+([0-9X\-]+)/gi,"ISBN $1");
        str = str.replace(/ISBN +([\d-]{1,9}) (\d+|X\W)/gi,"ISBN $1$2");
        str = str.replace(/\[*ISBN\]*\:* *\[\[Special\:Booksources\/\d*\|([\dxX\- ]+)\]\]/gi,"ISBN $1");
        str = str.replace(/\[isbn\]\:* *(\d)/gi,"ISBN $1");
        str = str.replace(/ISBN (\d{10,10}) - *(\d)/gi,"ISBN $1 ,$2");
        var loopcount = 0;
        while (loopcount<10) { //'
            str = str.replace(/ISBN (\d{1,9}) (\d|x)/gi,"ISBN $1$2");
            loopcount++;
        }
        str = str.replace(/ISBN (\d{1,9})(x)/gi,"ISBN $1X");
        str = str.replace(/ISBN (\d\d\d\d\d\d\d\d\d(\d|x)) +(\d)/gi,"ISBN $1, $3");
        str = str.replace(/ISBN ([\d-]{12,12}) (\d|x)/gi,"ISBN $1-$2");
        /* broken ISBNs with hyphens */
        // autoFormatter.js > cleanISBNs 
        str = str.replace(
            /(^|[\s#'(*>|])(?:(ISBN\d?\s*=\s*)|ISBN(?:-?1[03]\b| *1[03]:)?:?\s*)(9-?7-?[89]-?)?([013][\d\u2010-\u2012\u2212-]{8,}[\dX]\b)/gim,
            function( $0, $1, $2, $3, $4 ) {
                return $1 + ( $2 || 'ISBN ' ) + ( $3 || '' ).replace( /^9\D*7\D*(\d)\D*/, '97$1-' ) + $4
                    /* Remove all dashes */
                    .replace( /[^\dX]+/gi, '' )
                    /* Group 0 for English books */
                    .replace( /^0([01]\d)(\d{6})\B/, '0$1-$2-' )
                    .replace( /^0([2-6]\d\d)(\d{5})\B/, '0$1-$2-' )
                    .replace( /^0(7\d{3}|8[0-4]\d\d)(\d{4})\B/, '0$1-$2-' )
                    .replace( /^0(8[5-9]\d{3})(\d{3})\B/, '0$1-$2-' )
                    .replace( /^0(9[0-4]\d{4})(\d\d)\B/, '0$1-$2-' )
                    .replace( /^0(9[5-9]\d{5})(\d)\B/, '0$1-$2-' )
                    /* Group 1 for English books */
                    .replace( /^1(0\d)(\d{6})\B/, '1$1-$2-' )
                    .replace( /^1([1-3]\d\d)(\d{5})\B/, '1$1-$2-' )
                    .replace( /^1(4\d{3}|5[0-4]\d\d)(\d{4})\B/, '1$1-$2-' )
                    .replace( /^1(5[5-9]\d{3}|[67]\d{4}|8[0-5]\d{3}|86[0-8]\d\d|869[0-7]\d)(\d{3})\B/, '1$1-$2-' )
                    .replace( /^1(869[89]\d\d|8[7-9]\d{4}|9[0-8]\d{4}|99[0-8]\d{3})(\d\d)\B/, '1$1-$2-' )
                    .replace( /^1(999\d{4})(\d)\B/, '1$1-$2-' )
                    /* Group 3 for German books */
                    .replace( /^3(0[0-24-9]|1\d)(\d{6})\B/, '3$1-$2-' )
                    .replace( /^3(03[0-3]|[2-6]\d\d)(\d{5})\B/, '3$1-$2-' )
                    .replace( /^3(03[4-6]\d|7\d{3}|8[0-4]\d\d)(\d{4})\B/, '3$1-$2-' )
                    .replace( /^3(03[7-9]\d\d|8[5-9]\d{3}|95[4-9]\d\d|9[69]\d{3})(\d{3})\B/, '3$1-$2-' )
                    .replace( /^3(9[0-4]\d{4})(\d\d)\B/, '3$1-$2-' )
                    .replace( /^3(95[0-3]\d{4}|9[78]\d{5})(\d)\B/, '3$1-$2-' )
                    /* Add missing dash after group */
                    .replace( /^([0-57]|6\d\d|8\d|9[0-4]|9[5-8]\d|99[0-8]\d|999\d\d)\B/, '$1-' );
            }
        );
        return str
    }

    //---------------------whitespace.js--------------------------------
    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");

        //==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;
    }

    //---------------------htmltowikitext.js--------------------------------
    //Convert HTML to wikitext
    function autoEdHTMLtoWikitext(str) {
        // <b>, <strong>, <i>, and <em> tags
        str = str.replace(/<(B|STRONG)[ ]*>((?:[^<>]|<[a-z][^<>]*\/>|<([a-z]+)(?:| [^<>]*)>[^<>]*<\/\3>)*?)<\/\1[ ]*>/gi, "'''$2'''");
        str = str.replace(/<(I|EM)[ ]*>((?:[^<>]|<[a-z][^<>]*\/>|<([a-z]+)(?:| [^<>]*)>[^<>]*<\/\3>)*?)<\/\1[ ]*>/gi, "''$2''");
        // </br>, <\br>, <br\>, <BR />, ...
        str = str.replace(/<[\\\/]+BR[\\\/\s]*>/gim, "<br />");
        str = str.replace(/<[\\\/\s]*BR[\s]*[\\\/]+[\s]*>/gim, "<br />");
        // <.br>, <br.>, <Br>, ...
        str = str.replace(/<[\s\.]*BR[\s\.]*>/gim, "<br>");
        // <br>>, <<br />, <<br >> ...
        str = str.replace(/<[\s]*(<br[\s\/]*>)/gim, "$1");
        str = str.replace(/(<br[\s\/]*>)[\s]*>/gim, "$1");

        str = str.replace(/<[\\\/\s]*REFERENCES[\\\/\s]*>/gim, "<references />");
        // Repeated references tag
        str = str.replace(/(<references \/>)[\s]*\1/gim, "$1");
        // Make sure <H1>, ..., <H6> is after a newline
        str = str.replace(/([^\r\n ])[\t ]*(<H[1-6][^<>]*>)/gim, "$1\n$2");
        // Make sure </H1>, ..., </H6> is before a newline
        str = str.replace(/(<\/H[1-6][^<>]*>)[\t ]*([^\r\n ])/gim, "$1\n$2");
        // Remove newlines from inside <H1>, ..., <H6>
        var loopcount = 0;
        while (str.search(/<H([1-6])[^<>]*>(?:[^<>]|<\/?[^\/h\r\n][^<>]*>)*?<\/H\1[^<>]*>/gim) >= 0 && loopcount <= 10) {
            str = str.replace(/(<H)([1-6])([^<>]*>(?:[^<>]|<\/?[^\/h\r\n][^<>]*>)*?)[\r\n]((?:[^<>]|<\/?[^\/h\r\n][^<>]*>)*?<\/H)\2([^<>]*>)/gim, "$1$2$3 $4$2$5");
            loopcount++;
        }
        // Replace <H1>, ..., <H6> with wikified section headings
        str = str.replace(/(^|[\r\n])[\t ]*<H1[^<>]*>([^\r\n]*?)<\/H1[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1=$2=$3');
        str = str.replace(/(^|[\r\n])[\t ]*<H2[^<>]*>([^\r\n]*?)<\/H2[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1==$2==$3');
        str = str.replace(/(^|[\r\n])[\t ]*<H3[^<>]*>([^\r\n]*?)<\/H3[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1===$2===$3');
        str = str.replace(/(^|[\r\n])[\t ]*<H4[^<>]*>([^\r\n]*?)<\/H4[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1====$2====$3');
        str = str.replace(/(^|[\r\n])[\t ]*<H5[^<>]*>([^\r\n]*?)<\/H5[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1=====$2=====$3');
        str = str.replace(/(^|[\r\n])[\t ]*<H6[^<>]*>([^\r\n]*?)<\/H6[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1======$2======$3');
        //Replace <ol><li> with #
        str = str.replace(
                    /(\<ol\>[\s\S]+\<\/ol\>)/g,
                    function($1) {
                        return $1.replace(/[\r\n] *\<li\>/g,'\n# ').replace(/\<\/li\>/g,'');
                    }
                ).replace(/\n\<\/?ol\>/g,'')
        //Replace <ul><li> with *
        str = str.replace(
                    /(\<ul\>[\s\S]+\<\/ul\>)/g,
                    function($1) {
                        return $1.replace(/[\r\n] *\<li\>/g,'\n* ').replace(/\<\/li\>/g,'');
                    }
                ).replace(/\n\<\/?ul\>/g,'')

        return str;
    }

    //---------------------headlines.js--------------------------------
    function autoEdHeadlines(str) { //MAIN FUNCTION describes list of fixes

        // Remove bold from section headings
        var loopcount = 0;
        while (str.search(/^[=]{1,5}[^=\r\n]*'''[^=\r\n]*[=]{1,5}/gim) >= 0 && loopcount <= 10) { //'
            str = str.replace(/(^[=]{1,5}[^=\r\n]*)'''([^=\r\n]*[=]{1,5})[\t ]*/gim, "$1$2"); //'
            loopcount++;
        }

        // Remove trailing colon from section headings
        str = str.replace(/(^[=]{1,5}[^=\r\n]*)[:]([\t ]*[=]{1,5})[\t ]*/gim, "$1$2");

        // Correct caps in "See also" section
        str = str.replace(/(==[\t ]*)see also([\t ]*==)/gi, "$1See also$2");

        // Change common synonyms for "See also" to "See also", but only if "See also" doesn't exist
        if (!str.match(/=[\t ]*See also[\t ]*=/gi)) {
            str = str.replace(/(==[\t ]*)(?:related topics|related articles|internal links|also see)([\t ]*==)/gi, "$1See also$2");
        }
        // Common synonyms for "External links"
        str = str.replace(/(==[\t ]*)(?:external links?|outside links?|web ?links?|exterior links?)([\t ]*==)/gi, "$1External links$2");

        // Capitalization and/or plural of "References", "Sources", "Further reading"
        str = str.replace(/(==[\t ]*)references([\t ]*==)/gi, "$1References$2");
        str = str.replace(/(==[\t ]*)sources([\t ]*==)/gi, "$1Sources$2");
        str = str.replace(/(==[\t ]*)further readings?([\t ]*==)/gi, "$1Further reading$2");

        return str;
    }


    //---------------------tablestowikitext.js--------------------------------
    function autoEdTablestoWikitext(str) { //MAIN FUNCTION describes list of fixes

        // Remove newlines from inside table specific tags
        var loopcount = 0;
        while (str.search(/(?:<\/?table|<\/?tr|<\/?td|<\/?th)[^<>]*[\r\n]/gi) >= 0 && loopcount <= 10) {
            str = str.replace(/((?:<\/?table|<\/?tr|<\/?td|<\/?th)[^<>]*)[\r\n]/gi, "$1 ");
            loopcount++;
        }
        // Remove extra whitespace from inside table specific tags
        str = str.replace(/(<table|<tr|<td|<th)([^<>]*?)[\s]+(>)/gim, "$1$2$3");
        str = str.replace(/(<table|<tr|<td|<th)([^<>]*?)[\s][\s]+/gim, "$1$2 ");
        // Remove any extra junk </tr>, </td>, </th>, </table>
        str = str.replace(/(<\/table|<\/tr|<\/td|<\/th)[^<>]+(>)/gim, "$1$2");
        // Remove space whitespace after </tr>, </td>, </th>, <table>
        str = str.replace(/(<\/tr>|<\/td>|<\/th>|<table[^<>]*>)[\s]+/gim, "$1");
        // Remove space before <tr>, <td>, <th>, </table>
        str = str.replace(/[\s]+(<\/table>|<tr[^<>]*>|<td[^<>]*>|<th[^<>]*>)/gim, "$1");
        // Replace '<table>' with '{|'
        str = str.replace(/<table( [^<>]*|)>[\s]*/gim, "{|$1\n");
        // Replace '</table>' with '|}'
        str = str.replace(/[\s]*<\/table>/gi, "\n|}");
        // Replace '</td><td>' with '||'
        str = str.replace(/<\/td[\s]*>[\s]*<td[\s]*>/gim, "||");
        str = str.replace(/<\/td[\s]*>[\s]*<td ([^<>]+)>/gim, "|| $1 |");
        // Replace '</th><th>' with '!!'
        str = str.replace(/<\/th[\s]*>[\s]*<th[\s]*>/gim, "!!");
        str = str.replace(/<\/th[\s]*>[\s]*<th ([^<>]+)>/gim, "!! $1 |");
        // Replace '</td></tr>' and '</th></tr>' with EOL
        str = str.replace(/<\/(?:td|th)>[\s]*<\/tr>[\s]/gim, "\n");
        // Replace '</td>', '</th>', '</tr>' with EOL
        str = str.replace(/<\/(?:td|th|tr)>[\s]*/gim, "\n");
        // Replace '<tr>' with '|-'
        str = str.replace(/[\s]*<tr>[\s]*/gim, "\n|-\n");
        str = str.replace(/[\s]*<tr ([^<>]*)>[\s]*/gim, "\n|- $1\n");
        // Replace '<td>' with "|"
        str = str.replace(/[\s]*<td>([^\s])/gim, "\n| $1");
        str = str.replace(/[\s]*<td>([\s])/gim, "\n|$1");
        str = str.replace(/[\s]*<td[\s]*([^<>]*?)[\s]*>([^\s])/gim, "\n| $1 | $2");
        str = str.replace(/[\s]*<td[\s]*([^<>]*?)[\s]*>([\s])/gim, "\n| $1 |$2");
        // Replace '<th>' with '!'
        str = str.replace(/[\s]*<th>([^\s])/gim, "\n! $1");
        str = str.replace(/[\s]*<th>([\s])/gim, "\n!$1");
        str = str.replace(/[\s]*<th[\s]*([^<>]*?)[\s]*>([^\s])/gim, "\n! $1 | $2");
        str = str.replace(/[\s]*<th[\s]*([^<>]*?)[\s]*>([^\s])/gim, "\n! $1 |$2");

        return str;
    }

    //---------------------extrabreaks.js--------------------------------
    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;
    }
    
    return {
        autoEdISBN: autoEdISBN,
        autoEdWhitespace: autoEdWhitespace,
        autoEdHTMLtoWikitext: autoEdHTMLtoWikitext,
        autoEdHeadlines: autoEdHeadlines,
        autoEdTablestoWikitext: autoEdTablestoWikitext,
        autoEdExtraBreaks: autoEdExtraBreaks
    };
}());
if (typeof window !== "undefined") {
    window.autoEd = autoEd;
}