پرش به محتوا

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

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


//---------------------isbn.js--------------------------------------
        //Allows WikiMagic to work with ISBNs
function autoEdISBN(str) { //MAIN FUNCTION describes list of fixes
        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");


    //Allows WikiMagic to work with ISBNs
        //ISBN regexs from [[:Wikipedia:AutoWikiBrowser/Settings/ISBN-hyph]]
    str = str.replace(/ISBN-10:|ISBN-13:|ISBN-10|ISBN-13|ISBN:/gi, 'ISBN');
        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
    }


     return str;
     //---------------------whitespace.js--------------------------------
}
    function autoEdWhitespace(str) { //MAIN FUNCTION describes list of fixes
//---------------------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");


    str = str.replace(/\t/g, " ");
        //==Headings==
        str = str.replace(/^(={1,4} )[ ]*([^= ][^=]*[^= ])[ ]*( ={1,4})$/gm, "$1$2$3");
    str = str.replace(/^ ? ? \n/gm, "\n");
        str = str.replace(/^(={1,4})([^= ][^=]*[^= ])[ ]+(={1,4})$/gm, "$1$2$3");
    str = str.replace(/(\n\n)\n+/g, "$1");
        str = str.replace(/^(={1,4})[ ]+([^= ][^=]*[^= ])(={1,4})$/gm, "$1$2$3");
    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;
        return str;
}
    }
//---------------------wikilinks.js--------------------------------
//<source lang=javascript>


// Credits: A modification of [[Wikipedia:WikiProject User scripts/Scripts/Formatter]]
    //---------------------htmltowikitext.js--------------------------------
function autoEdWikilinks(str) { //MAIN FUNCTION describes list of fixes
    //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");


//Get the list of all wikilinks with underscores
        str = str.replace(/<[\\\/\s]*REFERENCES[\\\/\s]*>/gim, "<references />");
var m = str.match(/\[\[[^\[\]]*_[^\[\]]*\]\]/g);
        // Repeated references tag
if (m) {
        str = str.replace(/(<references \/>)[\s]*\1/gim, "$1");
  //For each wikilink in the list
        // Make sure <H1>, ..., <H6> is after a newline
  for (var i = 0; i < m.length; i++) {
        str = str.replace(/([^\r\n ])[\t ]*(<H[1-6][^<>]*>)/gim, "$1\n$2");
  var x = m[i].toString() // Contains the entire wikilink
        // Make sure </H1>, ..., </H6> is before a newline
  // Exclude URLs and leading underscores
        str = str.replace(/(<\/H[1-6][^<>]*>)[\t ]*([^\r\n ])/gim, "$1\n$2");
  if( !x.match(/^\[\[[\t ]*(?:http|ftp|https):/i) && !x.match(/^\[\[_[^\[\]]*\]\]/) ) {
        // Remove newlines from inside <H1>, ..., <H6>
    var x_arr = x.match(/^(\[\[[^\[\]\|]*)(\|?[^\[\]]*?\]\])$/);
        var loopcount = 0;
    var a = x_arr[1]; // Everything before the pipe (or everything minus ]])
        while (str.search(/<H([1-6])[^<>]*>(?:[^<>]|<\/?[^\/h\r\n][^<>]*>)*?<\/H\1[^<>]*>/gim) >= 0 && loopcount <= 10) {
    var b = x_arr[2]; // Everything after the pipe (or ]])
            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,'')


    // Replace underscores with spaces
        return str;
    a = a.replace(/_/g, ' ');
     }
     // Do the replacement
    str = str.replace(x, a+b);
  }
  }
}


//Fix links which have no target
    //---------------------headlines.js--------------------------------
str = str.replace(/\[\[[\t ]*\|/gi, '[[');
    function autoEdHeadlines(str) { //MAIN FUNCTION describes list of fixes
//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
        // Remove bold from section headings
var m = str.match(/\[\[[^\[]*?\|[^\[]*?\]\]/g);
        var loopcount = 0;
if (m) {
        while (str.search(/^[=]{1,5}[^=\r\n]*'''[^=\r\n]*[=]{1,5}/gim) >= 0 && loopcount <= 10) { //'
  //For each piped wikilink in the list
            str = str.replace(/(^[=]{1,5}[^=\r\n]*)'''([^=\r\n]*[=]{1,5})[\t ]*/gim, "$1$2"); //'
  for (var i = 0; i < m.length; i++) {
            loopcount++;
  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
        // Remove trailing colon from section headings
str = str.replace(/\[\[([^\[\]\|]+)\|([^\[\]\|]+)\]\]([a-z]+)/g, "[[$1|$2$3]]");
        str = str.replace(/(^[=]{1,5}[^=\r\n]*)[:]([\t ]*[=]{1,5})[\t ]*/gim, "$1$2");


//Removes links to current article
        // Correct caps in "See also" section
var p1 = wgPageName;                  // PAGENAME including underscores
        str = str.replace(/(==[\t ]*)see also([\t ]*==)/gi, "$1See also$2");
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
        // Change common synonyms for "See also" to "See also", but only if "See also" doesn't exist
str = str.replace(/\[\[WIKTIONARY:/gi, '[[wikt:');
        if (!str.match(/=[\t ]*See also[\t ]*=/gi)) {
str = str.replace(/\[\[WIKINEWS:/gi, '[[n:');
            str = str.replace(/(==[\t ]*)(?:related topics|related articles|internal links|also see)([\t ]*==)/gi, "$1See also$2");
str = str.replace(/\[\[WIKIBOOKS:/gi, '[[b:');
        }
str = str.replace(/\[\[WIKIQUOTE:/gi, '[[q:');
        // Common synonyms for "External links"
str = str.replace(/\[\[WIKISOURCE:/gi, '[[s:');
        str = str.replace(/(==[\t ]*)(?:external links?|outside links?|web ?links?|exterior links?)([\t ]*==)/gi, "$1External links$2");
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]]
        // Capitalization and/or plural of "References", "Sources", "Further reading"
str = str.replace(/\[\[([^\]]*?)( |_)+#([^\]]*?)\]\]/g, '[[$1#$3]]');
        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");


//Replace [[Foo|]] -> [[Foo| ]]
        return str;
str = str.replace(/\|\]\]/g, '| ]]');
    }


return str;
}


// Converts the first character in a string to lower case
    //---------------------tablestowikitext.js--------------------------------
// Notes: Used by autoEdWikilinks
    function autoEdTablestoWikitext(str) { //MAIN FUNCTION describes list of fixes
function autoEd_first2lower(str) {
if (str != "") {
  var letter = str.substr(0, 1);
  return letter.toLowerCase() + str.substr(1, str.length);
} else {
  return "";
}
}


//---------------------htmltowikitext.js--------------------------------
        // Remove newlines from inside table specific tags
//Convert HTML to wikitext
        var loopcount = 0;
function autoEdHTMLtoWikitext(str) {
        while (str.search(/(?:<\/?table|<\/?tr|<\/?td|<\/?th)[^<>]*[\r\n]/gi) >= 0 && loopcount <= 10) {
  // <b>, <strong>, <i>, and <em> tags
            str = str.replace(/((?:<\/?table|<\/?tr|<\/?td|<\/?th)[^<>]*)[\r\n]/gi, "$1 ");
  str = str.replace(/<(B|STRONG)[ ]*>((?:[^<>]|<[a-z][^<>]*\/>|<([a-z]+)(?:| [^<>]*)>[^<>]*<\/\3>)*?)<\/\1[ ]*>/gi, "'''$2'''");
            loopcount++;
  str = str.replace(/<(I|EM)[ ]*>((?:[^<>]|<[a-z][^<>]*\/>|<([a-z]+)(?:| [^<>]*)>[^<>]*<\/\3>)*?)<\/\1[ ]*>/gi,  "''$2''");
        }
  // </br>, <\br>, <br\>, <BR />, ...
        // Remove extra whitespace from inside table specific tags
  str = str.replace(/<[\\\/]+BR[\\\/\s]*>/gim, '<br />');
        str = str.replace(/(<table|<tr|<td|<th)([^<>]*?)[\s]+(>)/gim, "$1$2$3");
  str = str.replace(/<[\\\/\s]*BR[\s]*[\\\/]+[\s]*>/gim, '<br />');
        str = str.replace(/(<table|<tr|<td|<th)([^<>]*?)[\s][\s]+/gim, "$1$2 ");
  // <.br>, <br.>, <Br>, ...
        // Remove any extra junk </tr>, </td>, </th>, </table>
  str = str.replace(/<[\s\.]*BR[\s\.]*>/gim, '<br>');
        str = str.replace(/(<\/table|<\/tr|<\/td|<\/th)[^<>]+(>)/gim, "$1$2");
  // <br>>, <<br />, <<br >> ...
        // Remove space whitespace after </tr>, </td>, </th>, <table>
  str = str.replace(/<[\s]*(<br[\s\/]*>)/gim, '$1');
        str = str.replace(/(<\/tr>|<\/td>|<\/th>|<table[^<>]*>)[\s]+/gim, "$1");
  str = str.replace(/(<br[\s\/]*>)[\s]*>/gim, '$1');
        // Remove space before <tr>, <td>, <th>, </table>
  // <hr>
        str = str.replace(/[\s]+(<\/table>|<tr[^<>]*>|<td[^<>]*>|<th[^<>]*>)/gim, "$1");
  str = str.replace(/([\r\n])[\t ]*<[\\\/\. ]*HR[\\\/\. ]*>/gi, '$1----');
        // Replace '<table>' with '{|'
  str = str.replace(/(.)<[\\\/\. ]*HR[\\\/\. ]*>/gi, '$1\n----');
        str = str.replace(/<table( [^<>]*|)>[\s]*/gim, "{|$1\n");
  // Not really an HTML-to-wikitext fix, but close enough
        // Replace '</table>' with '|}'
  str = str.replace(/<[\\\/\s]*REFERENCES[\\\/\s]*>/gim, '<references />');
        str = str.replace(/[\s]*<\/table>/gi, "\n|}");
  // Repeated references tag
        // Replace '</td><td>' with '||'
  str = str.replace(/(<references \/>)[\s]*\1/gim, '$1');
        str = str.replace(/<\/td[\s]*>[\s]*<td[\s]*>/gim, "||");
  // Make sure <H1>, ..., <H6> is after a newline
        str = str.replace(/<\/td[\s]*>[\s]*<td ([^<>]+)>/gim, "|| $1 |");
  str = str.replace(/([^\r\n ])[\t ]*(<H[1-6][^<>]*>)/gim, '$1\n$2');
        // Replace '</th><th>' with '!!'
  // Make sure </H1>, ..., </H6> is before a newline
        str = str.replace(/<\/th[\s]*>[\s]*<th[\s]*>/gim, "!!");
  str = str.replace(/(<\/H[1-6][^<>]*>)[\t ]*([^\r\n ])/gim, '$1\n$2');
        str = str.replace(/<\/th[\s]*>[\s]*<th ([^<>]+)>/gim, "!! $1 |");
  // Remove newlines from inside <H1>, ..., <H6>
        // Replace '</td></tr>' and '</th></tr>' with EOL
  var loopcount = 0;
        str = str.replace(/<\/(?:td|th)>[\s]*<\/tr>[\s]/gim, "\n");
  while( str.search( /<H([1-6])[^<>]*>(?:[^<>]|<\/?[^\/h\r\n][^<>]*>)*?<\/H\1[^<>]*>/gim ) >= 0 && loopcount <= 10 ) {
        // Replace '</td>', '</th>', '</tr>' with EOL
    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(/<\/(?:td|th|tr)>[\s]*/gim, "\n");
    loopcount++;
        // Replace '<tr>' with '|-'
  }
        str = str.replace(/[\s]*<tr>[\s]*/gim, "\n|-\n");
  // Replace <H1>, ..., <H6> with wikified section headings
        str = str.replace(/[\s]*<tr ([^<>]*)>[\s]*/gim, "\n|- $1\n");
  str = str.replace(/(^|[\r\n])[\t ]*<H1[^<>]*>([^\r\n]*?)<\/H1[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1=$2=$3');
        // Replace '<td>' with "|"
  str = str.replace(/(^|[\r\n])[\t ]*<H2[^<>]*>([^\r\n]*?)<\/H2[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1==$2==$3');
        str = str.replace(/[\s]*<td>([^\s])/gim, "\n| $1");
  str = str.replace(/(^|[\r\n])[\t ]*<H3[^<>]*>([^\r\n]*?)<\/H3[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1===$2===$3');
        str = str.replace(/[\s]*<td>([\s])/gim, "\n|$1");
  str = str.replace(/(^|[\r\n])[\t ]*<H4[^<>]*>([^\r\n]*?)<\/H4[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1====$2====$3');
        str = str.replace(/[\s]*<td[\s]*([^<>]*?)[\s]*>([^\s])/gim, "\n| $1 | $2");
  str = str.replace(/(^|[\r\n])[\t ]*<H5[^<>]*>([^\r\n]*?)<\/H5[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1=====$2=====$3');
        str = str.replace(/[\s]*<td[\s]*([^<>]*?)[\s]*>([\s])/gim, "\n| $1 |$2");
  str = str.replace(/(^|[\r\n])[\t ]*<H6[^<>]*>([^\r\n]*?)<\/H6[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1======$2======$3');
        // 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;
        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;
}
//---------------------unicodecontrolchars.js--------------------------------
function autoEdUnicodeControlChars(str) { //MAIN FUNCTION describes list of fixes


  //Removes unneeded Unicode control characters
    //---------------------extrabreaks.js--------------------------------
  str = str.replace(new RegExp('\u200E|\uFEFF|\u200B', 'gi'), '');
    function autoEdExtraBreaks(str) { //MAIN FUNCTION describes list of fixes


  return str;
        //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");
//---------------------unicodehex.js--------------------------------
        //BR tag before a list item
function autoEdUnicodeHex(txt) { //MAIN FUNCTION describes list of fixes
        str = str.replace(/[\t ]*<[\s\/\.]*br[\s\/\.]*>[\t ]*([\s]*?[\n]\*)/gim, "$1");
if(txt.match(/\uE000/)) return(txt); // see [[Private Use Area]]
        //BR tag followed by at least two newlines
txt = txt.replace(/(\[\[[\:\s*]*(?:Image|File|پرونده|Media)\s*\:)/gi, "$1\uE000");
        str = str.replace(/[\t ]*<[\s\/\.]*br[\s\/\.]*>[\t ]*([\n])[\t ]*([\n])/gim, "$1$2");
if(m = txt.match(/\[\[[^\[\]\n\uE000]+\]\]/g)) {
  for(var i = 0; i < m.length; i++) {
  parts = m[i].split("|");
  link = parts[0];
  a = link.split("#")
  title = a[0];
  section = a[1];
  try {
    link = decodeURIComponent(title.replace(/\%(.[^0-9A-F]|[^0-9A-F].|$)/gi, "%25$1")
    ) + ( section ? ("#" + decodeURIComponent(section
          // change "." to "%" when followed by valid hex
          .replace(/\.([0-9A-F]{2})/gi, "%$1")
          .replace(/\%(.[^0-9A-F]|[^0-9A-F].|$)/gi, "%25$1")
        )
    ) : "" )
    } catch(e) { } // just do no decoding
      parts[0] = link;
      txt = txt.replace(m[i], parts.join("|"));
  }
  }
  return(txt.replace(/\uE000/g, ""));
}
//---------------------tablestowikitext.js--------------------------------
function autoEdTablestoWikitext(str) { //MAIN FUNCTION describes list of fixes


  // Remove newlines from inside table specific tags
        return str;
  var loopcount = 0;
    }
  while( str.search(/(?:<\/?table|<\/?tr|<\/?td|<\/?th)[^<>]*[\r\n]/gi) >= 0 && loopcount <= 10 ) {
      
     str.replace(/((?:<\/?table|<\/?tr|<\/?td|<\/?th)[^<>]*)[\r\n]/gi, '$1 ')
     return {
     loopcount++;
        autoEdISBN: autoEdISBN,
  }
        autoEdWhitespace: autoEdWhitespace,
  // Remove extra whitespace from inside table specific tags
        autoEdHTMLtoWikitext: autoEdHTMLtoWikitext,
  str=str.replace(/(<table|<tr|<td|<th)([^<>]*?)[\s]+(>)/gim, '$1$2$3');
        autoEdHeadlines: autoEdHeadlines,
  str=str.replace(/(<table|<tr|<td|<th)([^<>]*?)[\s][\s]+/gim, '$1$2 ');
        autoEdTablestoWikitext: autoEdTablestoWikitext,
  // Remove any extra junk </tr>, </td>, </th>, </table>
        autoEdExtraBreaks: autoEdExtraBreaks
  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');
if (typeof window !== "undefined") {
  // Remove space before <tr>, <td>, <th>, </table>
    window.autoEd = autoEd;
  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--------------------------------

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

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