Замечание: Возможно, после публикации вам придётся очистить кэш своего браузера, чтобы увидеть изменения.

  • Firefox / Safari: Удерживая клавишу Shift, нажмите на панели инструментов Обновить либо нажмите Ctrl+F5 или Ctrl+R (⌘+R на Mac)
  • Google Chrome: Нажмите Ctrl+Shift+R (⌘+Shift+R на Mac)
  • Internet Explorer / Edge: Удерживая Ctrl, нажмите Обновить либо нажмите Ctrl+F5
  • Opera: Нажмите Ctrl+F5.
/*
  Этот скрипт добавлят кнопку для исправления заголовков секций 3 уровня

function FormatHeader(str, header, offset, s)
{
  switch (header) {
  case "Морфологические и синтаксические свойства": 
  case "Произношение": 
  case "Произношение":
  case "Семантические свойства":
  case "Родственные слова":
  case "Фразеологизмы и устойчивые сочетания":
  case "Этимология":
  case "Перевод":
    return "=== " + header + " ===";
  case "Значение":
  case "Синонимы":
  case "Антонимы":
  case "Гиперонимы":
  case "Гипонимы":
    return "==== " + header + " ====";
  default:
    return str;
  }   
}

var FormatEdit = function()
{
  wpTextbox1 = document.editform.wpTextbox1;
  wpTextbox1.value = wpTextbox1.value.replace(/^=+\s*([^=]+?)\s*=+$/gm, FormatHeader);
}

// удаление шаблона {{Rm acc}} в шаблонах словоизменения
var RemoveAcc = function ()
{
  wpTextbox1 = document.editform.wpTextbox1;
  wpTextbox1.value = wpTextbox1.value.replace(/\{\{#if:.+?\|[—-]\|(.+)\}\}/gm, '$1'); // убираем if
  wpTextbox1.value = wpTextbox1.value.replace(/\{\{Rm acc\|([^, |]+)\}\}/gm, '$1'); // убираем Rm acc
  wpTextbox1.value = wpTextbox1.value.replace(/\{\{!\}\}/gm, '|'); // заменяем пайп
  wpTextbox1.value = wpTextbox1.value.replace(/\[\[([^\|]+\|)?([^\]]+)\]\]/gm, '$2'); // убираем ссылку
  if (wpTextbox1.value.match(/\|коммент=/m) === null ) {
     wpTextbox1.value = wpTextbox1.value.replace(/(^\}\}$)/m, '|коммент={{{коммент|}}}\r\n$1'); // добавляем коментарий
  }
}
*/

function wikify()
{
	var txt = '';
	
	var $textbox = $('#wpTextbox1' );
	if ( $textbox.length == 0)
	  return;
	  
	var $codemirror; 
	if ( $('.CodeMirror').length > 0) {
		$codemirror = $('.CodeMirror')[0].CodeMirror;
	}
	
	if ( mw.user.options.get( 'usecodemirror') && (typeof $codemirror !== 'undefined') ) {
		txt = $codemirror.getValue();
	} else {
		txt = $textbox.val();
	}

	// var wgTitle = mw.config.get('wgTitle');
	// var words = wgTitle.split(/[ .,;:!?—]+/);

	var astring = txt.split('\n');
	var lang = '';
	var newtext = '';
	var section = '';
	
	for (var line of astring) {
		if (line.match(/=\s\{\{-(\w+)-\}\}\s=/m)) {
			if (section != '') {
				parseSection();
				newtext = newtext + section + '\n';
				section = '';
			}
			lang = line.replace(/=\s\{\{-(\w+)-\}\}\s=/m, '$1');
			newtext = newtext + line + '\n';
	    } else if (lang != '') {
	    	section = section + line + '\n';
	    } else {
	      newtext = newtext + line + '\n';
	    }
    }
	if (section != '') {
		parseSection();
		newtext = newtext + section + '\n';
		section = '';
	}
	txt = newtext;
	
	// Замена минусов на прочерки
	txt = txt.replace(/^#\s*-\s*$/gm, '# —');
		
	// Замена ёлочек на лапки в названии
	txt = txt.replace(/(\{\{пример\|([^|{}]*\{{2}(?:[^{}]+|\{{2}(?:[^{}]+|\{{2}[^{}]*\}{2})*\}{2})*\}{2}[^|{}]*)\|[^|{}]*\|)([^|{}]*)(\|[^}]*\}\})/gm, 
		function ( match, before, text, title, after ) {
			return before + title.replace(/«([^«»]+)»/, '„$1“') + after;
		});
	

	r(/\{\{(сущ|гл|прил|прич) (ru|uk)(\s*[^|]*)(\|слоги=\{\{по-слогам\|[^}]*?\}\})(\|основа\=[^|]*?)(\|основа1=[^|]*?)(\|основа2=[^|]*?)?\}\}/gm, '{{$1 $2$3\r\n$5\r\n$6\r\n$4\r\n}}');

//	r(/\|слово([1-9])={{по-слогам\|}}\r?\n\|лемма[1-9]=\r?\n(\|знак[1-9]=\r?\n)*/gm, function (str, num) {
//		var w = words[parseInt(num)-1]
//		var nextch = wgTitle.match(new RegExp(w + '([ .,;:!?—]+)') )
//		var z = (nextch && nextch[1] != ' ' ) ? '|знак' + num + '=' + nextch[1] + '\r\n' : ''
//		return (w) ? '|слово' + num + '={{по-слогам|' + w + '}}\r\n|лемма' + num + '=' + w + '\r\n' + z : ''
//	})
	
//	findall(/{{родств-блок[^{}|]*[^{}]+}}/gm, function (value) {
//		r(value, value.replace(/\[\[([^\[\]\|]*?)\]\]/g, '$1'));
//	});

	var m = 'января,февраля,марта,апреля,мая,июня,июля,августа,сентября,октября,ноября,декабря'.split(',');
	txt = txt.replace(/(\d{4})\.(\d{2})\.(\d{2})/gm, function (str, year, month, day) {
		return parseInt(day) + ' ' + m[parseInt(month)-1] + ' ' + parseInt(year);
	});
	txt = txt.replace(/(\d{2})\.(\d{2})\.(\d{4})/gm, function (str, day, month, year) {
		return parseInt(day) + ' ' + m[parseInt(month)-1] + ' ' + parseInt(year);
	});


	if ( mw.user.options.get( 'usecodemirror') && (typeof $codemirror !== 'undefined') ) {
		$codemirror.setValue(txt);
	} else {
		$textbox.val(txt);
	}

	function rs(regExp, replaceTo) {
		section = section.replace(regExp, replaceTo);
	}
	
	function parseSection() {
		rs(/(\{\{этимология:\|)(\}\})/gm, '$1' + lang +'$2');
		rs(/\{\{stub\|XX\}\}<!--(\{\{improve\|)XX(\|\?\?\}\})-->/gm, '$1' + lang +'$2');
		rs(/\|((lang|язык)=|)XX(\s*[|}])/gmi, '|$1' + lang +'$3');
		rs(/\|(lang|язык)=(\s*[|}])/gm, '|$1=' + lang +'$2');
		rs(/\{\{(сущ|гл|мест|прил|прич|числ|art|adv|conj|interj|part|prep) XX/gm, '{{$1 '+ lang);
	}
	
	function r(regExp, replaceTo) {
		txt = txt.replace(regExp, replaceTo);
	}
	
	function findall(regExp, func) {
		var matches = txt.match(regExp);
		if (matches) {
			for (var i = 0; i < matches.length; i++) {
				func(matches[i]);
			}
		}
	}
	
}

var customizeToolbar = function() {
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'main',
        'group': 'format',
        'tools': {
            'formatpage': {
                label: 'Format Page', // or use labelMsg for a localized label, see above
                filters: [ 'body.ns-0' ],
                type: 'button',
                icon: '//upload.wikimedia.org/wikipedia/commons/a/a0/Toolbaricon_bold_F-1.png',
                action: {
                    'type': 'callback',
                    'execute': wikify // FormatEdit
                }
            }
        }
    } );
};
 
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
    mw.loader.using( ['user.options', 'jquery.textSelection'], function () {
        if ( mw.user.options.get('usebetatoolbar') === 1 ) {
			$.when(
				mw.loader.using( 'ext.wikiEditor' ),
					$.ready
			).then( customizeToolbar );
		}
    } );
}