跳转到内容

维基百科:AutoEd/links.js

维基百科,自由的百科全书

//

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

    var m = str.match(/\[?\[[^\]]*?\]\]?/g);
    if (m)
    {
      for (var i = 0; i < m.length; i++)
      {
        var x = m[i].toString();
        var y = x;
 
        if ( !y.match(/^\[?\[http:\/\//i) && !y.match(/^\[?\[image:/i) )
        {
          if (y.indexOf(":") == -1 && y.substr(0,3) != "[[_" && y.indexOf("|_") == -1)
          {
            if (y.indexOf("|") == -1)
              y = y.replace(/_/g, " ");
            else
              y = y.replace( y.substr(0, y.indexOf("|")), y.substr(0, y.indexOf("|")).replace(/_/g, " "));
          }  
 
          y = y.replace(/ ?\| ?/, "|").replace("|]]", "| ]]");
 
        }
 
        str = str.replace(x, y);
      }
    }
 
    //repair bad internal links
    //str = str.replace(/\[\[ ?([^\]]*?) ?\]\]/g, "[[$1]]"); Commented out for now per [[WT:AutoEd]]
    str = str.replace(/\[\[([^\]]*?)( |_)#([^\]]*?)\]\]/g, "[[$1#$3]]");
 
    //repair bad external links
    str = str.replace(/\[?\[http:\/\/([^\]\n]*?)\]\]?/gi, "[http://$1]");
    str = str.replace(/\[http:\/\/([^\]]*?)\|([^\]]*?)\]/gi, "[http://$1 $2]");

    return str;
}

//