MediaWiki:Gadget-Typo-pl-common.js

Z Wikiźródeł, wolnej biblioteki

Uwaga: aby zobaczyć zmiany po opublikowaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.

  • Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5, lub Ctrl+R (⌘-R na komputerze Mac)
  • Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
  • Internet Explorer / Edge: Przytrzymaj Ctrl, jednocześnie klikając Odśwież, lub naciśnij klawisze Ctrl+F5
  • Opera: Naciśnij klawisze Ctrl+F5.
/*
 * Na podstawie skryptu:
 * Typo
 * lokalizacja źródła: https://fr.wikisource.org/wiki/MediaWiki:Gadget-Typo.js
 * Auteur : Marc, Tpt
 * Dernière révision : 25 mai 2011
 * (znacznie) zmodyfikowany przez Zdzislaw
 * 02.2014
 * 08.2015-09.2016 przejście na ext.gadget.lib-toolbar + modyfikacje (Zdzislaw)
 */
 
$.typo = {
	todo: [],
	add: function(fonction) {
		$.typo.todo.push(fonction);
	},
	exec: function() {
		var txt = $('#wpTextbox1').val();
		for (var i = 0; i < $.typo.todo.length; ++i) {
			txt = $.typo.todo[i](txt,'');
		}
		$('#wpTextbox1').val(txt);
	},
	execp: function() {
		var txt = $('#wpTextbox1').val();
		for (var i = 0; i < $.typo.todo.length; ++i) {
			txt = $.typo.todo[i](txt,'poem');
		}
		$('#wpTextbox1').val(txt);
	},
};

if($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1 ) {
	$(function() {
		//typo
		$.typo.add(function(str,poem) {
			if ( poem === "poem" ) {
				str = str.replace(/­/g, "");
			} else {
				// tiret conditionnel
				str = str.replace(/­ *\n?/g, "");
				str = str.replace(/¬ *\n?/g, "");
				// espace
				str = str.replace(/(\S)- *\n/g, "$1");
				str = str.replace(/([^\.>} ]) *\n/g, "$1 ");
			}
			//smieci
			str = str.replace(/[·\t]/g," ");

			// fix divers
			str = str.replace(/ +/g," ");

			//----- typographie
			str = str.replace(/\n +/g, "\n");
			str = str.replace(/ -/g, " —");
			str = str.replace(/- /g, "— ");
			str = str.replace(/ - /g, " — ");
			str = str.replace(/ -,/g, " —,");
			str = str.replace(/ - ,/g, " —,");
	
			str = str.replace(/([^ \n])—/g, "$1 —");
			str = str.replace(/—([^ \n])/g, "— $1");
			str = str.replace(/([0-9]) — ([0-9])/g, "$1—$2");

			str = str.replace(/ *, *([^\"“„ ])/g, ", $1");

			str = str.replace(/([^'])'([^'])/g, "$1’$2");

			str = str.replace(/ ([\.\!\?\,\;\:\u2026])/g, "$1");

			str = str.replace(/"([a-ząćęłóńśżź])/gi, "„$1");
			str = str.replace(/"/g, "“");
			str = str.replace(/“ ,/g, "“,");
			str = str.replace(/“ \./g, "“.");

			// ligatury
			str = str.replace(/dz([a-ząćęłóńśżź])/g, "dz$1");
			str = str.replace(/([a-ząćęłóńśżźA-ZĆŁÓŚŹŻ])dz/g, "$1dz");
			str = str.replace(/Dz([a-ząćęłóńśżź])/g, "Dz$1");
			str = str.replace(/DZ([A-ZĄĆĘŁŃÓŚŹŻ])/g, "DZ$1");
			str = str.replace(/([A-ZĄĆĘŁŃÓŚŹŻ])DZ/g, "$1DZ");
			str = str.replace(/([a-ząćęłóńśżźA-ZĆŁÓŚŹŻ])fi/g, "$1fi");
			str = str.replace(/fi([a-ząćęłóńśżź])/g, "fi$1");
			str = str.replace(/([a-ząćęłóńśżźA-ZĆŁÓŚŹŻ])ij/g, "$1ij");
			str = str.replace(/ij([a-ząćęłóńśżź])/g, "ij$1");
			str = str.replace(/([a-ząćęłóńśżźA-ZĆŁÓŚŹŻ])/g, "$1fr");
			str = str.replace(/([a-ząćęłóńśżź])/g, "fr$1");
	
			str = str.replace(/n\. p\. m\./g, "n.&nbsp;p.&nbsp;m.");
			str = str.replace(/n\. p\./g, "n.&nbsp;p.");

			// syntaxe wiki
			str = str.replace(/ ?<br\s?\/?>/gi, "<br>");
			str = str.replace(/{{tab}} /gi, "{{tab}}");
			str = str.replace(/{{tab}}— 1 /gi, "{{tab}}— I ");
			str = str.replace(/\n— {{tab}}/gi, "\n{{tab}}— ");

			//typowe błedy orr
			str = str.replace(/[■•_]/g, "");
			str = str.replace(/’I'/g, "T");
			str = str.replace(/ 011 /g, " on ");
			str = str.replace(/ [i]v /g, " w ");
			str = str.replace(/(\d)O/g, "$10");
			str = str.replace(/ 0([a-ząćęłóńśżź])/g, " O$1");
			str = str.replace(/aui/gi, "ani");
			str = str.replace(/[°“]\/0/gi, "%");
			str = str.replace(/([\n ][Gg])lówn/gi, "$1łówn");
			str = str.replace(/ si[ąo] /gi, " się ");
			str = str.replace(/ juz /gi, " już ");
			str = str.replace(/([\wĄ-ż])ó([^\wĄ-ż|}{<>\-])/g, "$1ć$2");
			str = str.replace(/ćj/g, "éj");
			str = str.replace(/tć/g, "té");
			str = str.replace(/cb(?!y\W)/g, "ch");
			str = str.replace(/ćh/g, "ch");
			str = str.replace(/([a-zA-Z])6([a-z])/gi, "$1ó$2");
			str = str.replace(/([a-zA-Z])1([a-z])/gi, "$1l$2");
			str = str.replace(/( [Tt])ern/g, "$1em");
			str = str.replace(/\/\./g, "z");
			str = str.replace(/[\\v]v/g, "w");
			str = str.replace(/\\\\’/g, "w");
			str = str.replace(/[\\V]V/g, "W");
			str = str.replace(/v\//g, "w");
			str = str.replace(/c[lł]i/g, "ch");
			str = str.replace(/ź([eaoąęiuóy])/g, "ż$1");
			str = str.replace(/(mo|ró)źn/g, "$1żn");
			str = str.replace(/ iź/g, " iż");
			str = str.replace(/iź /g, "iż ");
			str = str.replace(/ żc /g, " że ");
			str = str.replace(/ ai /g, " aż ");
			str = str.replace(/ teź/g, " też");
			str = str.replace(/ ([bB])[yv][lł] /g, " $1ył ");
			str = str.replace(/czvm/g, "czym");
			str = str.replace(/slde/gi, "skie");
			str = str.replace(/ oc[lł]/gi, " od");
			str = str.replace(/ dła /gi, " dla ");
			str = str.replace(/i t\. ([pd])\./g, "i&nbsp;t.&nbsp;$1.");
			str = str.replace(/t\. zw\./g, "t.&nbsp;zw.");
			str = str.replace(/p\. t\./g, "p.&nbsp;t.");
			str = str.replace(/t\. j\./g, "t.&nbsp;j.");
			str = str.replace(/(ś)\. (p)\./gi, "$1.&nbsp;$2.");
			str = str.replace(/\— rzeki/g, "— rzekł");
			str = str.replace(/ž/g, "ż");
			str = str.replace(/\n,,([A-Z])/g, "\n„$1");
			str = str.replace(/ +\n/g, "\n");

			//przywraca 'zwykłe' "(cudzusłowy) w tagach html i mw
			str = str.replace(/<[^<>\n]*[“„][^<>\n]*>/g, function restoreqm(x){return x.replace(/[“„]/g,"\"");});
			return $.trim(str);
		});

	});
}