مدیاویکی:Gadget-Extra-Editbuttons-persiantools.js: تفاوت میان نسخهها
ظاهر
imported>Ebrahim بدون خلاصۀ ویرایش |
imported>Ebrahim بدون خلاصۀ ویرایش |
||
| خط ۲۳: | خط ۲۳: | ||
arabicDigitsEnglishContext: /[a-z][\s_:\|,]*\d(?:\|\d|–|\s|\d|\:|\.|,)*(?=[a-z_\.,]|<|\)|<\/|\}|\n|\||$)/gi, | arabicDigitsEnglishContext: /[a-z][\s_:\|,]*\d(?:\|\d|–|\s|\d|\:|\.|,)*(?=[a-z_\.,]|<|\)|<\/|\}|\n|\||$)/gi, | ||
arabicTagEnclosed: /\{\{(?:عربی|شروع عربی|آغاز عربی)\}\}([\s\S]*?)\{\{(?:پایان عربی)\}\}/g, | arabicTagEnclosed: /\{\{(?:عربی|شروع عربی|آغاز عربی)\}\}([\s\S]*?)\{\{(?:پایان عربی)\}\}/g, | ||
argumentsBlacklist: /(?:accessdate|namespace|doi|style|شابک|عرض)\s*\=\s*[^\|\}]*/gi, | argumentsBlacklist: /(?:accessdate|namespace|doi|style|شابک|عرض|bibcode|isbn|pmid|arxiv)\s*\=\s*[^\|\}]*/gi, | ||
color: /#[abcdef0-9]{3,8}/gi, | color: /#[abcdef0-9]{3,8}/gi, | ||
decodeUriBlacklist: /(?:%20|%7B|%7C|%7D)/gi, // space, {, |, }, they will interfere with wiki markup | decodeUriBlacklist: /(?:%20|%7B|%7C|%7D)/gi, // space, {, |, }, they will interfere with wiki markup | ||
نسخهٔ ۷ ژوئیهٔ ۲۰۱۳، ساعت ۰۹:۲۲
// <nowiki>
/**
* Persian tools that is rewritten from [[MediaWiki:Gadget-Extra-Editbuttons-Functions-legacy.js]]
* Tests available on [[MediaWiki:Gadget-Extra-Editbuttons-Unit-Tests.js]]
*
* @author User:Ebraminio <ebrahim {{at}} gnu.org>
*/
/*jslint indent: 2, browser: true, regexp: true*/
/*global persianToolsDictionary*/
window.persianTools = (function () {
'use strict';
// Local variables
var patterns, persianGlyphs, persianDigits, arabicIndicDigits, arabicDigits,
persianCharacters, persianPastVerbs, persianPresentVerbs;
arabicDigits = '0123456789'; // Yes, they called Arabic
arabicIndicDigits = '٠١٢٣٤٥٦٧٨٩';
persianCharacters = 'ءاآأإئؤبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهیةيك' + 'ًٌٍَُِّْ';
persianDigits = '۰۱۲۳۴۵۶۷۸۹';
patterns = {
arabicDigitsEnglishContext: /[a-z][\s_:\|,]*\d(?:\|\d|–|\s|\d|\:|\.|,)*(?=[a-z_\.,]|<|\)|<\/|\}|\n|\||$)/gi,
arabicTagEnclosed: /\{\{(?:عربی|شروع عربی|آغاز عربی)\}\}([\s\S]*?)\{\{(?:پایان عربی)\}\}/g,
argumentsBlacklist: /(?:accessdate|namespace|doi|style|شابک|عرض|bibcode|isbn|pmid|arxiv)\s*\=\s*[^\|\}]*/gi,
color: /#[abcdef0-9]{3,8}/gi,
decodeUriBlacklist: /(?:%20|%7B|%7C|%7D)/gi, // space, {, |, }, they will interfere with wiki markup
englishDate: /\d{1,2},? [a-z]{3,} \d{2,4}/gi, // 3, May 2013
fileNames: /(?:پرونده|File|تصویر|Image)\:.*?(?=\||\]|\n|$)/gi, // don't capture | after
fileParameter: /\|\s*(image|تصویر)\s*\=\s*.*/g,
ipSign: /\[\[ویژه:مشارکت\u200cها.*?\]\]/g,
isbn: /ISBN [\d\-]*/ig,
htmlAttributes: /(?:style|colspan|rowspan|cellpadding|cellspacing|height|width|size|border|thumbtime|name)\s*\=\s*(?:['\"].*?['\"]|[\da-z]+)/gi,
imagePixelSize: /[\|=] *[x\d]+?(px|پیکسل)[\]\|\s]/g, // means it will capture |10px| and |10x10px|
linksOnEnglishContext: /[a-z][\:\,\. ]*\[\[[\da-z\-\, ]*/gi,
mathTag: /<math.*?>[\s\S]*?<\/math>/g,
otherLanguagesInline: /\{\{(?:به .+?|به انگلیسی|انگلیسی|عربی|به عربی)[\s\S]*?\}\}/g,
parameter: /\{\{\{\d+/gi,
paranthesisAfterDigits: /\w\s?\([\w\s\.\-]*?\)/g,
ref: /(?:<ref[^\/]*?>[\s\S]*?<\/ref>|<ref[^\/]*?\/>)/g, // inside <ref></ref> and <ref/>
signatures: /\[\[(?:کاربر|User|بحث[ _]کاربر|User[_ ]talk)\:.*?\]\]/gi,
sourceTag: /<source.*?>[\s\S]*?<\/source>/g,
templateEnglishName: /(الگو|Template):[a-z][a-z\d\-\+_]+/gi,
templateParameterName: /\|\s*[a-z\d_]*\s*\=/gi,
url: /\/\/.*?(?=[\s\r\n\|\}\]]|$)/ig // بدون https?: هم ممکن است
};
persianPastVerbs = '(آراست|آرامید|آزرد|آزمود|آسود|آشامید|آشفت|آغازید|آغشت|آفرید|آگند|آلود|آمد|آمرزید|آموخت|آمیخت|آورد|آویخت|آهیخت|ارزید|افتاد|افراشت|افروخت|افزود|افسرد|افشاند|افگند|انباشت|انجامید|انداخت|اندوخت|اندود|اندیشید|انگاشت|انگیخت|اوباشت|ایستاد|باخت|بارید|بافت|بالید|بایست|بخشود|بخشید|برازید|برد|برید|بست|بسود|بسیجید|بلعید|بود|بوسید|بویید|بیخت|پاشید|پالود|پخت|پذیرفت|پراکند|پرداخت|پرستید|پرسید|پرورد|پرید|پژمرد|پژوهید|پسندید|پلاسید|پلکید|پناهید|پنداشت|پوسید|پوشید|پویید|پیچید|پیراست|پیمود|پیوست|تاخت|تافت|تپید|تراشید|تراوید|ترسید|ترشید|ترکید|تکاند|تکانید|تنید|توانست|جست|جُست|جَست|جنبید|جنگید|جوشید|جوید|جهید|چاپید|چایید|چپید|چربید|چرخید|چرید|چسبید|چشید|چکید|چلاند|چلانید|چمید|چید|خارید|خاست|خایید|خراشید|خرامید|خروشید|خرید|خزید|خست|خشکید|خلید|خمید|خوابید|خواست|خواند|خورد|خوفید|خیسید|داد|داشت|دانست|درخشید|دروید|درید|دزدید|دمید|دوخت|دوشید|دوید|دیدم|ربود|رخشید|رسید|رست|رَست|رُست|رشت|رفت|رُفت|روفت|رقصید|رمید|رنجید|رندید|رویید|ریخت|رید|زارید|زایید|زد|زدود|زیست|ساخت|سپرد|سپوخت|ستد|سترد|ستود|ستیزید|سرود|سرشت|سرید|سزید|سفت|سگالید|سنجید|سوخت|سود|شاشید|شایست|شتافت|شد|شست|شکافت|شکست|شکفت|شکیفت|شگفت|شمرد|شناخت|شنید|شورید|طلبید|طوفید|غارتید|غرید|غلطید|غنود|فرستاد|فرسود|فرمود|فروخت|فریفت|فشرد|فهمید|قاپید|قبولاند|کاست|کاشت|کاوید|کرد|کشت|کشید|مکشید|کفت|کفید|کند|کوچید|کوشید|کوفت|گایید|گداخت|گذاشت|گذشت|گرازید|گرایید|گردید|گرفت|گروید|گریخت|گریست|گزارد|گزید|گُزید|گَزید|گسارد|گسترد|گسست|گشت|گشود|گفت|گماشت|گنجید|گندید|گوارید|گوزید|لرزید|لغزید|لمدنی|لندید|لنگید|لهید|لیسید|ماسید|مالید|ماند|مرد|مکید|مولید|مویید|نازید|نالید|نامید|نشست|نکوهید|نگاشت|نگریست|نمود|نواخت|نوردید|نوشت|نوشید|نهاد|نهفت|نیوشید|ورزید|وزید|هراسید|هشت|یارست|یازید|یافت|مالاند)';
persianPresentVerbs = '(آرای|آرام|آزار|آزمای|آسای|آشام|آشوب|آغاز|آغار|آفرین|آگن|آلای|آی|آمرز|آموز|آمیز|آور|آویز|آهنج|ارز|افت|افراز|افروز|افزای|افسر|افشان|افگن|انبار|انجام|انداز|اندوز|اندای|اندیش|انگار|انگیز|اوبار|ایست|باز|بار|باش|باف|بال|بای|بخشای|بخش|براز|بر|بُر|بَر|بند|بساو|بسیج|بلع|بو|بوس|بوی|بیز|پاش|پالای|پز|پذیر|پراکن|پرداز|پرست|پرس|پرور|پر|پژمر|پژوه|پسند|پلاس|پلک|پناه|پندار|پوس|پوش|پوی|پیچ|پیرای|پیمای|پیوند|تاز|تاب|تپ|توپ|تراش|تراو|ترس|ترش|ترک|تکان|تن|توان|جه|جوی|جنب|جنگ|جوش|جو|چاپ|چای|چپ|چرب|چرخ|چر|چسب|چش|چک|چلان|چم|چین|خار|خیز|خای|خراش|خرام|خروش|خر|خز|خست|خشک|خل|خم|خواب|خواه|خوان|خور|خوف|خیس|ده|دار|درخش|درو|در|دزد|دم|دوز|دوش|دو|بین|ربای|رخش|رس|ره|روی|رشت|رو|روب|رقص|رم|رنج|رند|روی|ریز|رین|زار|زای|زن|زدای|زی|ساز|سپر|سپوز|ستان|ستر|ستان|ستیز|سرای|سرشت|سر|سز|سنب|سگال|سنج|سوز|سای|شاش|شای|شتاب|شو|شوی|شکاف|شکن|شکوف|شکیب|شمر|شناس|شنو|شور|طلب|طوف|غارت|غر|غلط|غنو|فرست|فرسای|فرمای|فروش|فریب|فشر|فهم|قاپ|قبولان|کاه|کار|کاو|کن|کار|کُش|کش|کِش|کَش|کف|کن|کوچ|کوش|کوب|گای|گداز|گذار|گذر|گراز|گرای|گرد|گیر|گرو|گریز|گری|گزار|گز|گزین|گسار|گستر|گسل|گشای|گو|گمار|گنج|گند|گوار|گوز|لرز|لغز|لم|لند|لنگ|له|لیس|ماس|مال|مان|میر|مک|مول|موی|ناز|نال|نام|نشین|نکوه|نگار|نگر|نمای|نواز|نورد|نویس|نوش|نه|نهنب|نیوش|ورز|وز|هراس|هل|یار|یاز|یاب|مالان)';
function descendingFromComparetor(x, y) {
return x.from - y.from;
}
function replaceExcept(text, callback, excepts) {
var match, result = [], i, ranges, minRange, to, min, max;
while (text !== '') {
ranges = [];
for (i in excepts) {
if (excepts.hasOwnProperty(i)) {
excepts[i].lastIndex = 0; // a global regex should be reset before calls
match = excepts[i].exec(text);
if (match !== null) {
ranges.push({
from: match.index,
to: match.index + match[0].length
});
}
}
}
if (ranges.length === 0) { // so nothing is matched
result.push(callback(text));
break;
}
minRange = ranges.sort(descendingFromComparetor)[0];
min = minRange.from;
to = [];
for (i in ranges) {
if (ranges.hasOwnProperty(i)) {
if (ranges[i].from <= minRange.to) {
to.push(ranges[i].to);
}
}
}
max = Math.max.apply(null, to);
result.push(callback(text.substr(0, min)));
result.push(text.substr(min, max - min));
// console.log('Excepted: "' + text.substr(min, max - min) + '"');
text = text.substr(max);
}
return result.join('');
}
if (!String.prototype.trim) { // if is not available currently
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g, '');
};
}
function convertArabicCharactersToPersian(text) {
return replaceExcept(
text,
function (text) {
return text
.replace(/ي/g, 'ی') // Arabic
.replace(/ك/g, 'ک')
.replace(/ې/g, 'ی') // Uyghur
.replace(/[ىﻲ]/g, 'ی') // Urdu
.replace(/ہ/g, 'ه') // Convert ہ to ه ہہہہ to ههه
.replace(/ۍ/g, 'ی') // Pushtu
.replace(/[ەھ]/g, 'ه'); // Kurdish
},
[patterns.otherLanguagesInline, patterns.arabicTagEnclosed, patterns.fileNames, patterns.signatures, patterns.url]
);
}
function urlFix(text) {
return text
.replace(patterns.url, function (x) {
return replaceExcept(
x,
function (x) { return decodeURI(x); },
[patterns.decodeUriBlacklist]
);
})
// Shorten Wikipedia diff URLs
.replace(/\[(https?\:|)\/\/([\w\-]+\.wikipedia\.org\/w\/index\.php\?)title=[^&\s\]]*&(?=(?:diff=[^&\s]+&|)(?:oldid=\d+))/g, '[//$2')
// Strip the http(s) prefix
.replace(/\[(https?\:)(?=\/\/(?:[\w\-]+)\.wikipedia\.org\/[^\s\]]*)/g, '[');
}
persianGlyphs = {
'\u200cه': 'ﻫ',
'ی\u200c': 'ﻰﻲ',
'ﺃ': 'ﺄﺃ',
'ﺁ': 'ﺁﺂ',
'ﺇ': 'ﺇﺈ',
'ا': 'ﺎا',
'ب': 'ﺑﺐﺏﺒ',
'پ': 'ﭙﭘﭗﭖ',
'ت': 'ﺘﺖﺗﺖﺕ',
'ث': 'ﺜﺛﺚﺙ',
'ج': 'ﺠﺟﺞﺝ',
'چ': 'ﭼﭻﭺﭽ',
'ح': 'ﺤﺣﺢﺡ',
'خ': 'ﺥﺨﺧﺦ',
'د': 'ﺪﺩ',
'ذ': 'ﺬﺫ',
'ر': 'ﺮﺭ',
'ز': 'ﺰﺯ',
'ژ': 'ﮋﮊ',
'س': 'ﺴﺳﺲﺱ',
'ش': 'ﺸﺷﺶﺵ',
'ص': 'ﺼﺻﺺﺹ',
'ض': 'ﻀﺿﺾﺽ',
'ط': 'ﻄﻃﻂﻁ',
'ظ': 'ﻈﻇﻆﻅ',
'ع': 'ﻌﻋﻊﻉ',
'غ': 'ﻍﻐﻏﻎ',
'ف': 'ﻔﻓﻒﻑ',
'ق': 'ﻘﻗﻖﻕ',
'ک': 'ﮑﮐﮏﮎﻜﻛﻚﻙ',
'گ': 'ﮕﮔﮓﮒ',
'ل': 'ﻠﻟﻞﻝ',
'م': 'ﻡﻤﻣﻢﻣ',
'ن': 'ﻨﻧﻦﻥ',
'ه': 'ﻩﻪﻫﻬ',
'هٔ': 'ﮥﮤ',
'و': 'ﻮﻭ',
'ﺅ': 'ﺆﺅ',
'ی': 'ﯽﻴﻳﯾﻲﻱﻰىىﻯﯿ',
'ئ': 'ﺌﺋﺊﺉ',
'لا': 'ﻼ',
'ﻹ': 'ﻺ',
'ﻷ': 'ﻸ',
'ﻵ': 'ﻶ'
};
function cleanUselessZwnj(text) {
return text
// Remove more than a ZWNJs
.replace(/\u200c{2,}/g, '\u200c')
// Clean ZWNJs after characters that don't conncet to the next letter
.replace(/([۰-۹0-9إأةؤورزژاآدذ،؛,\:«»\\\/@#$٪×\*\(\)ـ\-=\|])\u200c/g, '$1')
// Clean ZWNJs before English characters
.replace(/\u200c([\w])/g, '$1')
.replace(/([\w])\u200c/g, '$1')
// Clean ZWNJs after and before punctuation
.replace(/\u200c([\n\s\[\]\.،«»\:\(\)\؛\؟\?\;\$\!\@\-\=\+\\])/g, '$1')
.replace(/([\n\s\[\.،«»\:\(\)\؛\؟\?\;\$\!\@\-\=\+\\])\u200c/g, '$1');
}
function nonStandard(text) {
var i;
for (i in persianGlyphs) {
if (persianGlyphs.hasOwnProperty(i)) {
text = text.replace(new RegExp('[' + persianGlyphs[i] + ']', 'g'), i);
}
}
return cleanUselessZwnj(text)
.replace(/ه[\u200c\u200e\s]+ی([\s\n])/g, 'هٔ$1') // Replace ه followed by (space|ZWNJ|lrm) follow by ی with هٔ
.replace(/ه[\u200c\u200e\s]*[ءٔ]([\s\n])/g, 'هٔ$1') // Replace ه followed by (space|ZWNJ|lrm|nothing) follow by ء or ٔ with هٔ
.replace(/(ۀ|هٓ)/g, 'هٔ') // Replace هٓ or single-character ۀ with the standard هٔ
.replace(/ه\u200c[ئی]ی/g, 'ه\u200cای') // Replace ه followed by ئ or ی, and then by ی, with ه\u200cای, example: خانهئی becomes خانه\u200cای
.replace(/([\u200c\u200e])([\s\n])/g, '$2') // Function for removing incorrect ZWNJs
.replace(/([\s\n])([\u200c\u200e])/g, '$1');
}
/**
* Replaces Persian characters with Arabic's ones so an Arabic sorter can sort Persian lines
*/
function dePersian(text) {
return text
.replace(/ی/g, 'ي')
.replace(/ک/g, 'ك')
.replace(/گ/g, 'كی')
.replace(/ژ/g, 'زی')
.replace(/چ/g, 'جی')
.replace(/پ/g, 'بی');
}
function persianSortText(text) {
return text.split('\n').sort(function (x, y) {
var keyX = dePersian(x),
keyY = dePersian(y);
if (keyX < keyY) { return -1; }
if (keyX > keyY) { return 1; }
return 0;
}).join('\n');
}
function applyZwnj(text) {
return cleanUselessZwnj(text)
.replace(
new RegExp('(^|[^' + persianCharacters + '])(می|نمی)\\s?' + persianPastVerbs +
'(م|ی|یم|ید|ند|)($|[^' + persianCharacters + '])', 'g'),
'$1$2\u200c$3$4$5'
)
.replace(
new RegExp('(^|[^' + persianCharacters + '])(می|نمی)\\s?' + persianPresentVerbs +
'(م|ی|د|یم|ید|ند)($|[^' + persianCharacters + '])', 'g'),
'$1$2\u200c$3$4$5'
)
// ای «توان» ناقلا!
.replace(/(می|نمی) ?توان/g, '$1\u200cتوان')
// چسباندن تمام «ها»ها با فاصلهٔ مجازی
.replace(/\sها([\]\.،\:»\)\s])/g, '\u200cها$1')
.replace(/\sها(ی|یی|یم|یت|یش|مان|تان|شان)([\]\.،\:»\)\s])/g, '\u200cها$1$2')
// برای حذف علامت ستاره اضافی قبل از عنوان ها
.replace(/\n\*\s*(\=+.+?\=+\n)/g, '\n$1')
// عضو علامت های نقل قول تکی از عنوان ها
.replace(/(\n=+)(.*?)(?:'+)(.*?)(?:'+)(.*?)(=+\n)/g, '$1$2$3$4$5')
// برای حذف فاصله های اضافی در پیوندها
.replace(/\[\[\s*(.*?)\s*\]\]/g, '[[$1]]')
// تبدیل به نویسه / یکی کردن فاصله های مجازی پشت سرهم
.replace(/(\{\{فم\}\}|\&zwnj\;|\u200c+)/g, '\u200c')
// اول و آخر هم خط اگر فاصلهٔ مجازی باشد، حذف شود
.replace(/(^\u200c|\u200c$)/mg, '')
// شناسه ها
// توجه: «است» تعدماً از شناسه ها حذف شده چون به عنوان فعل مستقل هم کاربرد دارد و در آن موارد باید جدا نوشته شود
// مثال: «این یک خانه است» که است در آن باید از خانه جدا نوشته شود
.replace(new RegExp('ه\\s+(ام|ای|ایم|اید|اند)($|[^' + persianCharacters + '])', 'g'), 'ه\u200c$1$2')
// موارد جزئی دیگر و بی ربط به فاصلهٔ مجازی، باید منتقل شود
.replace(/ا\sً/g, 'اً');
}
function convertDigitsToPersian(text) {
var i = 0;
for (i = 0; i <= 9; i = i + 1) {
text = text.replace(new RegExp('[' + arabicIndicDigits[i] + arabicDigits[i] + ']', 'g'), persianDigits[i]);
}
return text
.replace(new RegExp('([' + persianDigits + '])\\s?%', 'g'), '$1٪')
.replace(new RegExp('([' + persianDigits + '])\\.(?=[' + persianDigits + '])', 'g'), '$1٫'); // persian decimal separator
}
function wikiTextDigitsToPersian(text) {
text = replaceExcept(
text,
convertDigitsToPersian,
[patterns.htmlAttributes, patterns.mathTag, patterns.imagePixelSize, patterns.fileNames, patterns.ref,
patterns.sourceTag, patterns.url, patterns.signatures, patterns.arabicDigitsEnglishContext,
patterns.argumentsBlacklist, patterns.fileParameter, patterns.templateParameterName, patterns.ipSign,
patterns.paranthesisAfterDigits, patterns.otherLanguagesInline, patterns.isbn, patterns.englishDate,
patterns.parameter, patterns.color, patterns.templateEnglishName, patterns.linksOnEnglishContext]
);
return text
// Decimal point, and thousands' separator
.replace(/([۱۲۳۴۵۶۷۸۹۰])\.([۱۲۳۴۵۶۷۸۹۰])/g, '$1٫$2')
.replace(/([۱۲۳۴۵۶۷۸۹۰]),([۱۲۳۴۵۶۷۸۹۰])/g, '$1٬$2');
}
function addSpaceAfterPunctuation(text) {
return replaceExcept(
text,
function (x) {
return x.replace(
new RegExp('([' + persianCharacters + ']+)([؟،؛!\\.])([' + persianCharacters + ']+)', 'g'),
'$1$2 $3'
);
},
[patterns.fileNames] // Other patterns should be added here also
);
}
function punctuation(text) {
text = text
.replace(/ *(<\/? ?br ?\/?>|\{\{بر\}\}) */g, '{{سخ}}')
.replace(/([،\.])([^\s\.\(\)«»\"\[\]<>\d\w\{\}\|۰-۹])/g, '$1 $2')
.replace(/([\(«])\s/g, '$1')
.replace(/\s([\)»])/g, '$1')
.replace(/٬\s/g, '، ')
.replace(/(<\/ref>)\s+(<ref)/g, '$1$2')
.replace(/(\={2,})\s*([^\=]*?)\s*(\={2,})/g, '$1 $2 $3') // Format headings level 2 and above
.replace(/[\r\n]{3,}/g, '\n\n') // Cosmetic changes bot replaces
.replace(/[\r\n]\s{1,}[\r\n]/g, '\n\n')
.replace(/([^=])[\r\n]+(\=.*?\=[\r\n]+)/g, '$1\n\n$2')
.replace(/[\s\r\n]+<ref/g, '<ref')
.replace(/([\r\n]?)[\s\r\n]+?<\/ref>/g, '$1</ref>')
.replace(/^([*#]+)([^*#\:\s])/mg, '$1 $2') // Add a space after the # or * for lists
.replace(/(\={2,}) [\:,;'<>»«&\^#@•→←↔↑↓—–…~٫،؛ٔ]/g, '$1') // Clean headers
.replace(/[\:,;'<>»«&\^#@•→←↔↑↓—–…~٫،؛ٔ] (\={2,})/g, '$1') // Clean headers
.replace(/^#\s*(REDIRECT|تغییر[ _]?مسیر)/ig, '#تغییرمسیر')
.replace(/^#تغییرمسیر(?=\S)/g, '#تغییرمسیر ') // Adds a space after #REDIRECT
.replace(/(\n\*.*?)\n+(?=\n\*)/g, '$1') // Removes extra line between two items list
.replace(/(\n#.*?)\n+(?=\n#)/g, '$1') // Removes extra line between two items list
.replace(/([^=]) *$/mg, '$1')
.replace(/[\n\s]*\{\{[•·ن](w?)\}\}\s*/g, '{{•$1}} ')
.replace(/ +\( +/g, ' (')
.replace(new RegExp('([' + persianCharacters + '])\\s*\\(\\s*(?=[' + persianCharacters + '])', 'g'), '$1 (')
.replace(new RegExp('([' + persianCharacters + '])\\s*\\)\\s*(?=[' + persianCharacters + '])', 'g'), '$1) ')
// Convert , to ، if there are Persian characters on both sides of it
.replace(new RegExp('([' + persianCharacters + '])\\s?,\\s?(?=[' + persianCharacters + '])', 'g'), '$1، ')
.replace(/ *([؟،\:؛!\.])/g, '$1') // Remove space preceding punctuations
.replace(/\[\[(رده|الگو|ویکی\u200cپدیا)\: +/g, '[[$1:');
return addSpaceAfterPunctuation(text).trim();
}
function dictationReplace(x, y, extensions, text) {
return text.replace(
new RegExp(
'(^|[^' + persianCharacters + '])(\\s|\u200c|_|)(' + x + ')(\\s|_)(' + y + ')(\\s|\u200c|_|)(' +
extensions + ')($|[^' + persianCharacters + '])',
'g'
),
'$1$2$3\u200c$5$6$7$8'
);
}
// it has dependency to MediaWiki:Gadget-Extra-Editbuttons-Dictionary.js
function dictation(text) {
var i, dictionary = persianToolsDictionary;
for (i in dictionary.complexes) {
if (dictionary.complexes.hasOwnProperty(i)) {
text = dictationReplace(
i,
dictionary.complexes[i],
'ی|ها|های|هایی|هایم|هایت|هایش|هایمان|هایتان|هایشان|',
text
);
}
}
// for last name
text = dictationReplace(
dictionary.personNames,
'ی|زاده|نیا|پور|گان|فر|نژاد|یان|ی\u200cها|یها',
'ی|',
text
);
// for 'آباد's
text = dictationReplace(
dictionary.personNames + '|' + dictionary.addToAbad,
'آباد',
'زاده|نیا|پور|گان|فر|نژاد|ی|یان|ها|های|هایی|ی\u200cها|یها|',
text
);
// for first names
for (i in dictionary.firstNameComplex) {
if (dictionary.firstNameComplex.hasOwnProperty(i)) {
text = text.replace(
new RegExp(
'(^|[^' + persianCharacters + ']|\\s|_)(' + i + ')(\\s|_)(' +
dictionary.firstNameComplex[i] + ')(\\s|_)($|[^' + persianCharacters + ']|[^' +
persianCharacters + '])',
'g'
),
'$1$2\u200c$4$5$6'
);
}
}
// for colors
text = dictationReplace(
dictionary.colorsNames,
'فام|گون',
'زاده|نیا|پور|گان|فر|نژاد|ی|ها|های|هایی|ی\u200cها|یها|هایم|هایت|هایش|هایمان|هایتان|هایشان|',
text
);
// for numbers
text = dictationReplace(
dictionary.persianNumbers,
'گانه|ماهه',
'زاده|نیا|پور|گان|فر|نژاد|ی|ها|های|هایی|هایم|هایت|هایش|هایمان|هایتان|هایشان|',
text
);
// wrong dictation
for (i in dictionary.forReplace) {
if (dictionary.forReplace.hasOwnProperty(i)) {
text = text.replace(
new RegExp(
'(^|[^' + persianCharacters + '])(\\s|\u200c|_|)(' + i + ')(\\s|\u200c|_|)($|[^' +
persianCharacters + '])',
'g'
),
'$1$2' + dictionary.forReplace[i] + '$4$5'
);
}
}
return cleanUselessZwnj(text);
}
function wikiDictation(text) {
return replaceExcept(
text,
dictation,
[patterns.fileNames, patterns.signatures, patterns.url]
);
}
return {
applyZwnj: applyZwnj,
cleanUselessZwnj: cleanUselessZwnj,
convertArabicCharactersToPersian: convertArabicCharactersToPersian,
convertDigitsToPersian: convertDigitsToPersian,
dictation: dictation,
nonStandard: nonStandard,
persianSortText: persianSortText,
punctuation: punctuation,
urlFix: urlFix,
wikiDictation: wikiDictation,
wikiTextDigitsToPersian: wikiTextDigitsToPersian
};
}());