Jump to content

User:Æk/advisor functions.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Æk (talk | contribs) at 08:23, 27 December 2009 (typos). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<source lang=javascript>
/* ported from [[Wikipedia:AutoEd/extrabreaks.js]] */

function aekAdvisorExtraBreaks(s) {

  var suggestions = [];
  var make_suggestions = function (m) {
    suggestions.push({
      start: m.index,
      end: m.index + m[0].length,
      replacement: m[1] + m[2],
      name: "extra-br",
      description: "Remove unneeded br tags"
    });
  };

  var regexes = [
    // templates (}}), template parameters (|)
    /[\t ]*<[\s\/\.]*br[\s\/\.]*>[\t ]*([\t\n ]*?)(\]\]|}}|\|)/gim,

    // BR tag followed by at least two newlines
    /[\t ]*<[\s\/\.]*br[\s\/\.]*>[\t ]*([\n])[\t ]*([\n])/gim
  ];
  regexes.map(function (r) {
    var matches = r.match(s);
    matches.map(make_suggestions);
  });

  var make_suggestions1 = function (m) {
    suggestions.push({
      start: m.index,
      end: m.index + m[0].length,
      replacement: m[1],
      name: "extra-br",
      description: "Remove unneeded br tags"
    });
  };
  var matches = /[\t ]*<[\s\/\.]*br[\s\/\.]*>[\t ]*([\s]*?[\n]\*)/gim.match(s);
  matches.map(make_suggestions1);

  return suggestions;
}

ct.rules.push(aekAdvisorExtraBreaks);