User:Obsuser/js/hlist.js

function hlist_queryString(p) { var re = RegExp('[&?]' + p + '=([^&]*)'); var matches; if (matches = re.exec(document.location)) { try { return decodeURI(matches[1]); } catch (e) { } }   return null; }

//Add a 'hlist edit' tab if(mw.config.get('wgNamespaceNumber') == 10 && mw.config.get('wgArticleId') != 0) { $( function hlistEditButton {       mw.util.addPortletLink('p-cactions', mw.util.getUrl(null,{action:'edit',hlist:true}), 'Navbox', 'p-hlist', 'Start script for formatting of navigational box lists [hlist]');   } )} if(mw.config.get('wgAction') == 'edit' && hlist_queryString('hlist') == 'true') { $(function qscale {       var myContent = document.getElementById('wpTextbox1').value;        myContent = myContent.replace(/\<\!--\(reduces gap between wrapped lines\)--\>/g,'');

//Fix italics and bold when only set at start & end of line while( myContent.search(/(?:[\n]|=|\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|(?:\&nbsp\;|[ ]+)(?:·|•|\&bull\;|\-|–|\&ndash\;|—|\&mdash\;|\||\&\#124\;)|\{\{nowrap[_ ]begin\}\})[ ]*(\'?\'\')(?:[^\'\n]|[^\'\n]\')*(?:\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|(?:\&nbsp\;|[ ]+)(?:·|•|\&bull\;|\-|–|\&ndash\;|—|\&mdash\;|\||\&\#124\;))[ ]*\1/gi) >= 0 ) { myContent = myContent.replace(/((?:[\n]|=|\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|(?:\&nbsp\;|[ ]+)(?:·|•|\&bull\;|\-|–|\&ndash\;|—|\&mdash\;|\||\&\#124\;)|\{\{nowrap[_ ]begin\}\})[ ]*)(\'?\'\')((?:[^\'\n]|[^\'\n]\')*)((?:\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|(?:\&nbsp\;|[ ]+)(?:·|•|\&bull\;|\-|–|\&ndash\;|—|\&mdash\;|\||\&\#124\;)))[ ]*\2/gi, '$1$2$3$2$4'); } while( myContent.search(/(?:[\n]|=|\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|(?:\&nbsp\;|[ ]+)(?:·|•|\&bull\;|\-|–|\&ndash\;|—|\&mdash\;|\||\&\#124\;)|\{\{nowrap[_ ]begin\}\})[ ]*\'?\'\'(?:[^\'\n]|[^\'\n]\')*(?:\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|(?:\&nbsp\;|[ ]+)(?:·|•|\&bull\;|\-|–|\&ndash\;|—|\&mdash\;|\||\&\#124\;))/gi) >= 0 ) { myContent = myContent.replace(/((?:[\n]|=|\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|(?:\&nbsp\;|[ ]+)(?:·|•|\&bull\;|\-|–|\&ndash\;|—|\&mdash\;|\||\&\#124\;)|\{\{nowrap[_ ]begin\}\})[ ]*)(\'?\'\')((?:[^\'\n]|[^\'\n]\')*)((?:\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|(?:\&nbsp\;|[ ]+)(?:·|•|\&bull\;|\-|–|\&ndash\;|—|\&mdash\;|\||\&\#124\;)))/gi, '$1$2$3$2$4$2'); }

myContent = myContent.replace(/\&nbsp\;-/g,' -');

myContent = myContent.replace(/\{\{[_ ]*[Nn]owrap[_ ]begin[_ ]*\}\}\n?/g,'\n* ');

myContent = myContent.replace(/\{\{[_ ]*[Nn]owrap\|[_ ]*/g,'* '); myContent = myContent.replace(/\{\{[_ ]*•[_ ]*\}\}\}\}[ ]*/g,''); myContent = myContent.replace(/\{\{[_ ]*·[_ ]*\}\}\}\}[ ]*/g,'');

myContent = myContent.replace(/\{\{[_ ]*•wrap[_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*•wrap[_ ]*\}\}[ ]*/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*•w[_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*•w[_ ]*\}\}[ ]*/g,'\n* ');

myContent = myContent.replace(/\{\{[_ ]*·wrap[_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*·wrap[_ ]*\}\}\'\'[ ]*/g,'\n* \'\''); myContent = myContent.replace(/\{\{[_ ]*·wrap[_ ]*\}\}[ ]*/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*·w[_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*·w[_ ]*\}\}\'\'[ ]*/g,'\n* \'\''); myContent = myContent.replace(/\{\{[_ ]*·w[_ ]*\}\}[ ]*/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*·[_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*·[_ ]*\}\}[ ]*/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*,[_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*,[_ ]*\}\}[ ]*/g,'\n* ');

myContent = myContent.replace(/\{\{[_ ]*•[_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*•[_ ]*\}\}[ ]*/g,'\n* ');

myContent = myContent.replace(/\{\{[_ ]*\*[_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*\*[_ ]*\}\}[ ]*/g,'\n* ');

myContent = myContent.replace(/[ ]*\&bull\;[ ]*/g,'\n* ');

myContent = myContent.replace(/\{\{[_ ]*![_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*![_ ]*\}\}\}\}[ ]*/g,''); myContent = myContent.replace(/\{\{[_ ]*![_ ]*\}\}[ ]*/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*!w[_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*!w[_ ]*\}\}[ ]*/g,'\n* ');

myContent = myContent.replace(/\&nbsp\;•[ ]*/g,'\n* '); myContent = myContent.replace(/\&nbsp\;\&\#124\;[ ]*/g,'\n* '); myContent = myContent.replace(/\&nbsp\;\|[ ]*/g,'\n* ');

// myContent = myContent.replace(/[ ]*\&bull\;[ ]*\n/g,'\n* '); // myContent = myContent.replace(/[ ]*\&bull\;[ ]*/g,'\n* ');

myContent = myContent.replace(/(\|[ ]*(?:list\d*|САДРЖАЈ|battles|notes|below)[ ]*=)[ ]*([^\n\{])/g,'$1\n* $2');//      ⟶ Add '* ' to the first hlist item below = sign. myContent = myContent.replace(/(\|[ ]*(?:list\d*|САДРЖАЈ|battles|notes|below)[ ]*=)[ ]*\n+[ ]*([^\*])/g,'$1\n* $2');// ⟶ Add '* ' to the first hlist item below = sign.

myContent = myContent.replace(/(\|[ ]*(?:list\d*|САДРЖАЈ|battles|notes|below)[ ]*=[ ]*)\n*\/g,'$1'); myContent = myContent.replace(/\n\<\/div\>[ ]*\n/g,'\n');

myContent = myContent.replace(/\}\} \{\{nowrap\|[ ]*/g,''); myContent = myContent.replace(/\* \{\{nowrap\|/g,'* ');

myContent = myContent.replace(/\&nbsp\;· /g,'\n* '); myContent = myContent.replace(/ · /g,'\n* '); myContent = myContent.replace(/\&nbsp\;\&\#124\; /g,'\n* '); myContent = myContent.replace(/ \&\#124\; /g,'\n* '); myContent = myContent.replace(/\&nbsp\;\| /g,'\n* '); myContent = myContent.replace(/[ ]*•[ ]*\}\}[ ]*/g,'\n* '); myContent = myContent.replace(/[ ]*\|[ ]*\}\}[ ]*[^\}][ ]*/g,'\n* ');

myContent = myContent.replace(/\][ ]*,[ ]*\[/g,']\n* ['); myContent = myContent.replace(/[ ]*•[ ]*/g,'\n* '); myContent = myContent.replace(/[ ]*\&\#124\;[ ]*/g,'\n* ');

//New separators to be replaced with new line and * [+ format spacing] are added here

//very high risk:       myContent = myContent.replace(/([^\=\n])(?:[ ]*\&nbsp\;|[ ]+)\|[ ]+([^\=])/g,'$1\n* $2');

myContent = myContent.replace(/(?:[ ]*\&nbsp\;(?:\-|–|—|\&ndash\;|\&mdash\;)[ ]*|[ ]*(?:\-|–|\&ndash\;|\&mdash\;)[ ]+|[ ]+(?:-|–|\&ndash\;|\&mdash\;)[ ]*)/g,'\n* ');

myContent = myContent.replace(/[ ]*(?:\&nbsp\;)?(?:\|\|\<\/br\>)[ ]*/g,'\n* ');

//End for newly added separators

myContent = myContent.replace(/\n\* \*[ ]*/g,'\n* '); myContent = myContent.replace(/\n\* [ ]*/g,'\n* '); myContent = myContent.replace(/\n\* \&nbsp\;/g,'\n* '); myContent = myContent.replace(/\n\* \}\} \* /g,'\n* '); myContent = myContent.replace(/\n\*[ ]*\}\}[ ]*\n\* /g,'\n'); myContent = myContent.replace(/\n\*[ ]*\n/g,'\n* ');

myContent = myContent.replace(/\{\{[Nn]owrap end\}\}[ ]*/g,'');

// myContent = myContent.replace(/\:\&nbsp\;/g,': '); // myContent = myContent.replace(/\&nbsp\;/g,'');

myContent = myContent.replace(/\* \*[ ]*/g,'* ');

myContent = myContent.replace(/(\[\[.+\|.*\d+)[ ]*x[ ]*(\d+)[ ]*м(.+\]\])/g,'$1 × $2 м$3');// Change '4 x 100 м' to '4 × 100 м'. myContent = myContent.replace(/(\*[ ]*\[\[^\n]+\d\d\d\d)\.?([^\n]*\]\])/g,'$1.$2');// Change '[[Италија на Европском првенству у атлетици на отвореном 1954.|Берн 1954' to 'Берн 1954.'.

//       myContent = myContent.replace(/(\|[ ]*име[ ]*=[^\n]+)/g,'$1\n|bodyclass = hlist');// Add '|bodyclass = hlist' below '|име=' parameter and its content.

// Start script for sr:Шаблон:Навигација са сликом

myContent = myContent.replace(/\{\{[ ]*[Нн]авигација са сликом[ ]*/g,'\{\{Navbox');// Change '{{Навигација са сликом' to '{{Navbox'

myContent = myContent.replace(/\|[ ]*име[ ]*\=[ ]*/g,'\|name \= ');// Change '|име = ' to '|name = ' myContent = myContent.replace(/\|[ ]*НАСЛОВ[ ]*\=[ ]*/g,'\|title \= ');// Change '|НАСЛОВ = ' to '|title = ' myContent = myContent.replace(/\|[ ]*СЛИКА[ ]*\=[ ]*/g,'\|image \= ');// Change '|СЛИКА = ' to '|image = ' myContent = myContent.replace(/\|[ ]*СЛИКАЛЕВО[ ]*\=[ ]*/g,'\|imageleft \= ');// Change '|СЛИКАЛЕВО = ' to '|imageleft = ' myContent = myContent.replace(/\|[ ]*САДРЖАЈ[ ]*\=[ ]*/g,'\|list1 \=');// Change '|САДРЖАЈ = ' to '|list1 ='

// End script for sr:Шаблон:Навигација са сликом

// Start script for spacing

myContent = myContent.replace(/[ ]*\|[ ]*((?:name|title|titlestyle|state|above|image|imageleft|battles|notes|below))[ ]*\=[ ]*/g,'\|$1 \= ');// Change ' | name=' to '|name = ' for e.g.

// End script for spacing

// Start extra scripts

myContent = myContent.replace(/\*[ ]*\}\}/g,'\}\}');// Change '* }}' to '}}'

myContent = myContent.replace(/((?:\[\[)?)(\d\d\d\d)\.?((?:\]\])?)\.?((?:\.|\?|\!|\,|\;|\:|—|\)|\.\.\.|\…|\/))/g,'$1$2$3$4');// Change '2016.)' to '2016)'

// End extra scripts

if(document.getElementById('wpTextbox1').value != myContent) {

myContent = myContent.replace(/\|\{\{PAGENAME\}\}\]\]/g,']]');

var idx1 = 0; var idx2 = 0; var listclass = "listclass"; var bodyclass = "bodyclass";

if ( myContent.indexOf("avbox Musical artist",idx1)+myContent.indexOf("avbox musical artist",idx1) > 0 ) { if ( myContent.indexOf("| above",idx1)+myContent.indexOf("|above",idx1) > 0 ) { listclass = "bodyclass"; } }

idx1 = myContent.search(/\|[ ]*title[ ]*=/) if( idx1 > 0 ) { idx2 = myContent.indexOf("\n",idx1); } if( idx2 > 0 ) { myContent = myContent.substring(0,idx2+0)+" \|"+bodyclass+" = hlist"+myContent.substring(idx2,myContent.length); }

idx1 = 0; idx2 = 0; idx1 = myContent.search(/\|[ ]*capital[ ]*=/) if( idx1 > 0 ) { idx2 = myContent.indexOf("\n",idx1); } if( idx2 > 0 ) { myContent = myContent.substring(0,idx2+0)+" \|"+bodyclass+" = hlist"+myContent.substring(idx2,myContent.length); }

idx1 = 0; idx2 = 0; idx1 = myContent.search(/\|[ ]*template_name[ ]*=/) if( idx1 > 0 ) { idx2 = myContent.indexOf("\n",idx1); } if( idx2 > 0 ) { myContent = myContent.substring(0,idx2+0)+" \| "+bodyclass+" = hlist"+myContent.substring(idx2,myContent.length); }

idx1 = 0; idx2 = 0; idx1 = myContent.search(/\|[ ]*raw_name[ ]*=/) if( idx1 > 0 ) { idx2 = myContent.indexOf("\n",idx1); } if( idx2 > 0 ) { myContent = myContent.substring(0,idx2+0)+" \| "+bodyclass+" = hlist"+myContent.substring(idx2,myContent.length); }

// Error checks myContent = myContent.replace(/([\r\n](?:[^\'\r\n]|[^\'\r\n]\')*\'\'(?:[^\'\r\n]|[^\'\r\n]\')*)([\r\n])/gi, '$1$2'); myContent = myContent.replace(/([\r\n](?:[^\'\r\n]|[^\'\r\n]\')*\'\'\'(?:[^\'\r\n]|[^\'\r\n]\')*)([\r\n])/gi, '$1$2'); if( myContent.search(//gi) >= 0 ) { myContent = "\n" + myContent; }

document.getElementById('wpTextbox1').value=myContent; document.getElementById('wpSummary').value='semi-automatic conversion into hlist using script hlist.js'; };   } )}