In this article we are going to address the topic of
User:Quarl/autoreplace.js, which has sparked great interest and debate in different areas.
User:Quarl/autoreplace.js is a relevant topic that impacts people's daily lives, both on a personal and global level. Over the years,
User:Quarl/autoreplace.js has evolved and generated diverse perspectives and opinions, sparking endless discussions and analyzes about its importance, implications, and possible solutions. Therefore, it is essential to delve deeper and understand the complexity of
User:Quarl/autoreplace.js in order to form an informed opinion and contribute to the dialogue on this topic. In this article, we will explore different aspects of
User:Quarl/autoreplace.js and analyze its impact on today's society.
// ] - provides capability to replace strings (regular expressions) in edit boxes on submission.
// Strings between <nowiki> ... </nowiki> are not replaced.
// depends: wikipage.js, wikiedit.js, util.js
// recommends: smartsubmit.js
// external entry points:
// autoreplace.addReplacement("string", "replacement" || replacement_function);
// quarl 2006-01-04 initial version
// test:
// javascript:alert(autoreplace_replace_string_nonowiki("2 x 3 <nowiki> 4 x 5 </nowiki> 6", "x", "XXX"))
// javascript:alert(autoreplace_replace_strings("a ~~"+"~~ foo <nowiki>~~"+"~~</nowiki>"))
// <pre><nowiki>
autoreplace = new Object();
autoreplace.enabled = true;
autoreplace.replacements = Array();
// add a replacement
autoreplace.addReplacement = function(str, replacement) {
autoreplace.replacements.push();
}
// deprecated
autoreplace_add = autoreplace.addReplacement;
autoreplace.fToStr = function(t) {
if (typeof t == 'function') t = t();
return ""+t;
}
autoreplace.replaceString = function(text, str, replacement) {
return text.replace(new RegExp(str,'g'), replacement);
}
autoreplace.replaceStringNoNowiki = function(text, str, replacement) {
var rtext = '';
while ( text.match(/<nowiki>(?:.|\n)*?<\/nowiki>|<!--(?:.|\n)*?-->/) ) {
// save these before they get clobbered!
var left = RegExp.leftContext;
var match = RegExp.lastMatch;
var right = RegExp.rightContext;
rtext += autoreplace.replaceString(left, str, replacement) + match;
text = right;
}
rtext += autoreplace.replaceString(text, str, replacement)
return rtext;
}
autoreplace.replaceStrings = function(text) {
if (!text) return text;
for (i in autoreplace.replacements) {
r = autoreplace.replacements;
text = autoreplace.replaceStringNoNowiki(text, r, autoreplace.fToStr(r));
}
return text;
}
autoreplace.preSubmitHook = function(editor, data, button) {
if (!autoreplace.enabled) return;
if (!data.wpTextbox1) return;
data.wpTextbox1 = autoreplace.replaceStrings(data.wpTextbox1);
}
autoreplace.load = function() {
WikiEditor.addPreSubmitHook(autoreplace.preSubmitHook);
}
$(autoreplace.load);
// </nowiki></pre>