MediaWiki:Common.js: Difference between revisions

are you happy now epyep?
(cycling)
(are you happy now epyep?)
Line 60: Line 60:


function parseFormatCodes (text) {
function parseFormatCodes (text) {
   var spans = 0;
   let spans = 0;
   var res = '';
   let res = '';
   for (var i = 0; i < text.length; i++) {
   for (var i = 0; i < text.length; i++) {
     if ((text[i] == '&') && /[0-9a-fl-or]/.test(text[i + 1])) continue;
     if (text[i] == '\\') {
     else if (text[i] == '/') {
      res += text[i+1];
      i++;
    } else if (/&[0-9a-fl-o]/.test(text.substring(i,i+2))) {
      res += '<span class="format-' + text[i+1] + '">';
      spans++;
      i++;
    } else if (text.substring(i,i+2) == '&r') {
      res += '</span>'.repeat(spans);
      spans = 0;
      i++;
    } else if (/&#[0-9A-Fa-f]{6}/.test(text.substring(i,i+8))) {
      res += '<span style="color: ' + text.substring(i+1,i+8) + '">';
      spans++;
      i += 7;
     } else if (text[i] == '/') {
       res += '<br>';
       res += '<br>';
       continue;
    } else {
       res += text[i];
     }
     }
    else if ((text[i - 1] == '&') && /[0-9a-fl-or]/.test(text[i])) {
      if (text[i] == 'r') {
        res += '</span>'.repeat(spans);
        spans = 0;
      } else {
        res += '<span class="format-' + text[i] + '">';
        spans++;
      }
    } else res += text[i];
   }
   }
   return res + '</span>'.repeat(spans);
   return res + '</span>'.repeat(spans);
}
}
184

edits