User:Ohconfucius/script/formatgeneral.js: Difference between revisions

Content deleted Content added
df parameter in start-date template deprecated
align to test script\
Line 50:
 
regex(/(?:\| ?date= ?)(Cric\w{4,})(?=[|}])/gi, "|publisher=$1");
regex(/(\|\s*(?:\w+_|)colou?rs\s*=\s*[^{]*){{color ?(?:box|sample)\s?\|#?\w+}}\s?([^{]*){{color ?(?:box|sample)\s?\|#?\w+}}\s?([^{]*){{color ?(?:box|sample)\s?\|#?\w+}}([^{|]*)(?=\n?[|}])/gi, "$1$2$3$4");
regex(/(\|\s*(?:\w+_|)colou?rs\s*=\s*[^{]*){{color ?(?:box|sample)\s?\|#?\w+}}\s?([^{]*){{color ?(?:box|sample)\s?\|#?\w+}}([^{|]*)(?=\n?[|}])/gi, "$1$2$3");
regex(/(\|\s*(?:\w+_|)colou?rs\s*=\s*[^{]*){{color ?sample\s?\|#?\w+}}([^{|]*)(?=\n?[|{}])/gi, "$1$2");
 
}
Line 67:
regex(/(==[ ]*[\w]+? and )A(wards?|chievements?)(?=[ ]*=)/g, '$1a$2');
regex(/(==[ ]*[\w\s]+? )A(lbums?)(?=[ ]*=)/g, '$1a$2');
regex(/(==[ ]*[\w\s]+? )C(areer|hampionships|haracters|hart|ompetitions?|ompositions|redits)(?=[ ]*=)/g, '$1c$2');
regex(/(==[ ]*[\w\s]+? )(Capped [Pp]layers)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
regex(/(==[ ]*[A-Z]\w+ )((?:[A-Z]\w+ |and |)Destinations?)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
regex(/(==[ ]*[\w\s]+? )E(ducation)(?=[ ]*=)/g, '$1e$2');
Line 90 ⟶ 91:
regex(/(==[ ]*Campaign )C(redits)(?=[ ]*=)/g, '$1c$2');
regex(/(==[ ]*Combat )C(hronicle)(?=[ ]*=)/g, '$1c$2');
regex(/(\|\s*(?:\w+_|)colou?rs\s*=\s*[A-Z])([\w ,&]+)(?=[\n|}])/gi, '$1{{' + 'subst:' + 'lc:$2}}'); //downcase colours in infobox
regex(/(==\w+) M(atch(?:es|))\b/gi, '$1 m$2');
Line 104 ⟶ 107:
regex(/((?:'''|\|)\w+)[-–\s]H((?:alf|alves)(?:'''|\]\]))/gi, '$1-h$2');
regex(/((?:'''|\|)(?:[Oo]ne|[Tt]hree|[Ff]our))[-–\s]Q(uarters?(?:'''|\]\]))/gi, '$1-q$2');
regex(/((?:'''|\|)Population)[\s]D(ensity(?:'''|\s?\|))/gi, '$1 d$2');
regex(/((?:'''|\|)Population)[\s]P(rojection(?: \w+|)(?:'''|\s?\|))/gi, '$1 p$2');
 
regex(/([^\n]*\[\[)(One Country, Two Systems)(?=[|\]])/g, '$1{{' + 'subst:' + 'lc:$2}}');
regex(/(\[\[(?:[^\d{3,4} n]*|)(?:[A-Z^\.][a-z]+ \s)(?:\[A-Z]\[a-z]+ )*)((?:RaceExclusive |)Riot|Massacre|Murder|UprisingEconomic Zone)(?=s?(?: of \d{3,4}[|)\]| \(\d{3,4}\)])/g, '$1{{' + 'subst:' + 'lc:$2}}');
regex(/(\[\[(?:\d{3,4} |)(?:[A-Z][a-z]+ )(?:[A-Z][a-z]+ )*)(Conspiracy|Controversy|(?:Race |)Riot|Massacre|Murder|Protest|Uprising)(?=s?(?: of \d{3,4}|)\]| \(\d{3,4}\))/g, '$1{{' + 'subst:' + 'lc:$2}}');
 
//improper capitalisation within infobox strings
Line 132 ⟶ 138:
 
//rem inappropriate
regex(/((?:occupation|profession)[ ]*=[^\n]*)(?:, (?:activ|philanthrop)ist|Member of Parliament)(?=[^\n]*\n[ ]*\|)/gi, '$1$2');
// regex(/((?:occupation|profession)[ ]*=[ ]*)(?:\[\[Dewan Rakyat\|Member of Parliament\]\])(?=[^\n]*\n[ ]*\|)/gi, '$1Politican$2');
regex(/((?:occupation|profession)[ ]*=[ ]*)(?:(?:\[\[[^|\]]+\||)Member of Parliament\]\])(?=[^\n]*\n[ ]*\|)/gi, '$1Politican$2');
regex(/((?:occupation|profession)[ ]*=[ ]*[A-Z]+)([a-z]+[^=|}]+)(?=\n[ ]*\|)/gi, '$1{{' + 'subst:' + 'lc:$2}}'); //to genericise downcasing of occupations
 
//other improper capitalisation -sports
Line 162 ⟶ 169:
regex(/(== ?\w )(League Table)/gi, '$1 {{' + 'subst:' + 'lc:$2}}');
regex(/(Contract) +(Detail|Length)/gig, '$1 {{' + 'subst:' + 'lc:$2}}');
regex(/((?:\||==)\s*Current) +(Club|Line-?up|Roster|Team)/gig, '$1 {{' + 'subst:' + 'lc:$2}}');
regex(/(Points|Pts) +(Ag(?:ain|)st|Diff(?:erence|)|For)/g, '$1 {{' + 'subst:' + 'lc:$2}}');
regex(/(== ?Top) +(scorers(?: in Order of League Goals|))/gi, '$1 {{' + 'subst:' + 'lc:$2}}');
regex(/(== ?Touring )P(arty)/gig, '$1p$2');
regex(/((?:==|[|!])\s*(?:\d+ Season |Current |Former ))P(layers)/gig, '$1p$2');
regex(/(== ?\d+ Gains & )L(osses)/gig, '$1l$2');
regex(/(== ?\d+ Signings & )T(ransfers)/gig, '$1t$2');
regex(/(== ?\w+) +(Results & Fixtures)/g, '$1 {{' + 'subst:' + 'lc:$2}}');
regex(/(== ?\w+) +(and Capacity)/g, '$1 {{' + 'subst:' + 'lc:$2}}');
regex(/(== ?Accidents[^=]+)I(ncidents)/gig, '$1i$2');
regex(/(Airport) +(Name|Code)/g, '$1 {{' + 'subst:' + 'lc:$2}}');
regex(/(Bonus )P(oints|ts)/gig, '$1p$2');
regex(/(Busiest) +((?:International |Domestic |) *(?:Flight|Routes(?: Out [Oo]f|)))/gi, '$1 {{' + 'subst:' + 'lc:$2}}');
regex(/(City ) ?S(erved)/g, '$1s$2');
Line 265 ⟶ 272:
regex(/((?:birth|death)(?:_?place|)\s*=\s*)\{\{flag(?:country|u|)\|([^{}|]+)(?:\|[^{}]+|)\}\}/gi, '$1$2');
regex(/((?:(?:birth|death)(?:_?place|)|citizenship|residence|nationality)\s*=\s*)(?:\{\{flag ?icon\|[^{}]+(?:\|[^{}]+|)\}\} ?|\[\[(?:File|Image):Flag of [^\]]+\]\] ?)/gi, '$1$2');
// regex(/((?:countrycity|___location|nationality|residence|venue)\s*=\s*)\{\{flaguflag(?:country|)\|([^{}|]+)(?:\|[^{}]+|)\}\}/gi, '$1$2');
// regex(/((?:countrycity|___location|nationality|residence|venue)\s*=\s*[^{}|]*)(?:\{\{flag( ?:country|)icon\|([^{}|]+)(?:\|[^{}]+|)\}\}|\[\[(?:File|Image):Flag of [^\]]+\]\]) ?/gi, '$1$2');
regex(/((?:city|___location|residence|venue)\s*=\s*(\[\[[^|\]]+\|[^|\]]+\]\]|)[^{}|]*)(?:\{\{flag ?icon\|[^{}]+(?:\|[^{}]+|)\}\}|\[\[(?:File|Image):Flag of [^\]]+\]\]) ?/gi, '$1');
regex(/((?:country|___location|nationality|residence)\s*=\s*)\{\{flagu?\|([^{}|]+)(?:\|[^{}]+|)\}\}/gi, '$1$2');
regex(/((?:champs|name|leader|scorer)\s*=\s*)\{\{leagueicon?\|([^{}|]+)(?:\|[^{}]+|)\}\}/gi, '$1');
 
//strip bare facilities icons
Line 289 ⟶ 299:
regex(/(^\.U\.)[ ]+((?:S|K)\.)/gi, '$1$2'); //U. S. and U. K. to U.S. and U.K.
regex(/(<\/?ref(?: name=[^<>\/]*?|)>)[ ,\.]*(<ref)/gi, '$1$2'); // remove punctuation between ref tags
regex(/[ ]{1,3}(<\/?ref(?:>| >| n))/gi, '$1'); // remove spaces and line feeds preceding ref tags and templates
// regex(/(<\/ref ?>|<ref name=[^>\/]+\/>)([^\s<])/gi, '$1 $2'); // add spaces after ref tags
// regex(/[ ]+(\n|\r)/gi, '$1'); //removes multiple spaces preceding line break
Line 371 ⟶ 381:
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:K(g|m))s?\b/gi, '$1&nbsp;k$2');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*cms?/gi, '$1&nbsp;cm');
// regex(/([^\|\[=]\d{1,3})\s(m|b|tr)illion(\b[^}])/g, '$1&nbsp;$2illion$3');
 
regex(/(\d)(?:&nbsp;|\s)?C(entimet(?:er|re))/g, '$1&nbsp;c$2');
Line 520 ⟶ 530:
regex(/(.)(100\scrore club)(.)/gi, protect_function);
regex(/(.)(Conference of Presidents)(.)/g, protect_function);
regex(/(\[\[)((?:The |)Texas Chain ?Saw Massacre[^\]|]*)([\]|])/gi, protect_function);
regex(/C(hief )E(xecutive )O(fficer\W)/g, 'c$1e$2o$3');
Line 529 ⟶ 540:
regex(/M(anaging )D(irector\W)/g, 'm$1d$2');
regex(/G(eneral )M(anager\b)(?!of|[ ]*=)/g, 'g$1m$2');
regex(/C(hair(?:man|) of the )B(oard\W)/g, 'c$1b$2');
regex(/B(oard (?:of |))D(irectors?\W)/g, 'b$1d$2');
regex(/B(oard )M(embers?\W)/g, 'b$1m$2');
Line 535 ⟶ 547:
regex(/I(ndependent )N(on[\s\-])[Ee](xecutive )D(irectors?\W)/g, 'I$1n$2e$3d$4');
regex(/N(on)[\s\-][Ee](xecutive )D(irectors?\W)/g, 'n$1-e$2d$3');
regex(/CI(hair(?:man|) of thendependent )BS(oardchools?\W)/g, 'ci$1b1s$2');
regex(/N(on[\s\-])P(rofit\W)/g, 'n$1p$2');
regex(/N(on[\s\-])[Ee](xecutive )[Dd](irector)/g, 'n$1e$2d$3');
regex(/I(ndependent )D(irectors?\W)/g, 'i$1d$2');
regex(/(\w\s)V(ice)[\s\-]C(hair(?:man|)\W)(?!of)/g, '$1v$2-c$3');
regex(/(\w\s)C(hairman\W)(?!of)/g, '$1c$2');
Line 561 ⟶ 576:
 
// replace comma as decimal separator
regex(/(\|[\s\']+)(\d+),(\d\d?)(?=[ ']*[|\n<])/g, '$1$2.$3'); //add obligatory space or single quote mark,- false positives within convert templates
regex(/(\(\d+),(\d\d?%\))/g, '$1.$2'); //percentages in parentheses
regex(/(\{\{(?:de|in)crease\}\}\s*)(\d+),(\d\d?)(?=[ ]*[|\n<])/g, '$1$2.$3');
Line 630 ⟶ 645:
};
 
regex(/(== ?(?:Bibliography|Further reading|References|Sources|Works) ?==+)(\n[\S\s]*?)(\n)(?===)/gi, protect_function);
regex(/(== ?(?:Attribution|External links) ?==+)(\n[\S\s]*?)(\[\[Category:[^\]]+\]\])/gi, protect_function);
regex(/({{refn\|)([^}]*?)(}})/gi, protect_function);
regex(/(<ref name="[^\"]*?" ?>)([\s\S]*?)(<\/ref>)/gi, protect_function);
Line 668 ⟶ 683:
regex(/({{) ?(url) ?(?=\|)/gi, '$1$2');
regex(/({{url\|)[ ]*https?:\/\/(?:www\.|)([^\}]+}})[ ]*(?=[\n\r])/gi, '$1$2');
regex(/(\| ?homepage[ ]*=)[ ]*https?:\/\/(?:www\.|)([^\s\[\]]+)(?=[\s])/gi, '$1{{url|$2}}'); //rem 'website='
regex(/(\| ?(?:homepage|website)[ ]*=)[ ]*\[https?:\/\/(?:www\.|)([^\s\[\]]+) official (?:web|)site\](?=[\s])/gi, '$1{{url|$2}}');
regex(/({{url\|)([^\}]+)\|\2}}(?=[\s])/gi, '$1$2}}');
 
Line 683 ⟶ 698:
regex(/\[\[([^\]\|]*)\|\1([^-\] ]*|)(\]\])/gi, '[[$1$3$2');
regex(/\[\[([^\[\]\(\)\|:]*)( \((?:\d{4} |)film\))(\]\])/gi, '\'\'[[$1$2|$1$3\'\'');
regex(/\[\[([^\[\]\(\)\|:]*)( \([^\[\]\(\)\|]*(?:album|film|magazine|newspaper|song|\bEP)\))(\]\])(?![\s\n])/gig, '[[$1$2|$1$3'); //adding piping to album|film|magazine dabbed by parentheticals
regex(/([^"]\[\[)([^\[\]\(\)\|:]*)( \([^\[\]\(\)\|]*\))(\]\])(?![\s\n])/gi, '$1$2$3|$2$4'); //ensure songs titles not piped by default
 
// deprecated parameters in citation templates
Line 689 ⟶ 705:
 
}
 
function Ohc_downcase_headings(){
//cleanup of headings per MOSHEAD before complete downcasing (most code is copied from other parts of the script)