మీడియావికీ:Gadget-RegexMenuFramework-Cleanup.js

గమనిక: భద్రపరచిన తర్వాత, మార్పులను చూడాలంటే మీ విహారిణి కోశాన్ని తీసేయాల్సిరావచ్చు.

  • ఫైర్‌ఫాక్స్‌ / సఫారి: Shift మీటని నొక్కిపట్టి Reloadని నొక్కండి లేదా Ctrl-F5 గానీ Ctrl-R (మాకింటోషులో ⌘-Shift-R) గానీ నొక్కండి
  • గూగుల్ క్రోమ్: Ctrl-Shift-R (మాక్ లో ⌘-Shift-R) నొక్కండి
  • ఇంటర్నెట్ ఎక్ప్లోరర్/ఎడ్జి: Ctrl ను నొక్కిపట్టి Refresh నొక్కండి లేదా Ctrl-F5 నొక్కండి.
  • ఒపేరా:* Ctrl-F5 నొక్కండి.
/* global $, pathoschild */

/**
 * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
 * @see https://meta.wikimedia.org/wiki/TemplateScript
 * @update-token [[File:pathoschild/templatescript.js]]
 */
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
	pathoschild.TemplateScript.add([
		{
			name: 'clean up',
			script: function(editor) {
				editor
					// remove trailing whitespace at the end of each line
					.replace(/ \n/g, '\n')
					
					// remove trailing whitespace at the end of input
					.replace(/\s+$/g, '')
					
					// convert double-hyphen to mdash
					.replace(/--/g, '—')
					
					// remove spacing around mdash, but only if it has spaces on both sides
					// (we don't want to remove the trailing space from "...as follows:— "
					.replace(/ +— +/g, '—')
					
					// join words that are hyphenated across a line break
					.replace(/-\n/g, '');
					
				// stuff to do only if the page doesn't contain a <poem> tag:
				if (editor.get().indexOf("<poem>") != -1) {
					editor
						// remove single line breaks; preserve multiple.
						.replace(/([^>\n])\n([^<\n])/g, '$1 $2')
						
						// collapse sequences of spaces into a single space
						.replace(/  +/g, ' ');
				}
				
				editor
					// remove unwanted spaces around punctuation marks
					.replace(/ ([;:\?!,])/g, '$1')
					
					// OCR fixes: convert i9 to 19, etc.
					.replace(/[il]([0-9])/g, '1$1')
					
					// OCR fixes: "the", "them", "their", etcetera
					.replace(/tlie/g, 'the');
			}
		}
	]);
});