User talk:Gerbrant/edit/autoReplace.js

From Wikipedia, the free encyclopedia

Gerbrant.edit.autoReplace
This module allows you to make a standard set of regular expression based replacements each time you start editing a page. It uses the interface of Gerbrant.edit.regexReplace.

Contents

[edit] Usage

When installed, everytime you edit a non-talk page, the script will search for a standard set of regular expressions, allowing you to selectively replace them using a standard set of substitutions.

How the interface works is described in detail in the Gerbrant.edit.regexReplace documentation.

[edit] Installation

This script will only work in conjunction with Gerbrant.fw (documentation). If you're already using it, just add "Gerbrant.edit.autoReplace" to the start of the list of modules to load, otherwise paste the following in your monobook.js:

Gerbrant = {fw: {load: [

"Gerbrant.edit.autoReplace"

]}}

document.write('<script type="text/javascript" src="http://en.wikipedia.org/w/index.php?title=User:Gerbrant/fw.js&action=raw&ctype=text/javascript&dontcountme=s"></script>');

[edit] Exports

show()
Activate this module. Gets called everytime a non-talk page is edited.
caption
String, equal to "AutoReplace".
diag()
A diagnostic function to check whether all required libraries have finished loading correctly. Only useful for debugging purposes.

[edit] Settings

noDefault
If defined and true, disables the default set of replacements.
lib
An optional array of identifiers of modules to be loaded, containing extra sets of replacements. They should export an array of definitions, the format of which is explained below.
defs
An optional array of extra replacements. Each replacement is an object with two members:
re
The regular expression to search for as a string. This means that every \ in the regular expression should be escaped: \d becomes \\d.
hf
A function that is called to determine the replacement text. The first parameter is the full match, the rest are the submatches, if any.

[edit] Example