mwparserfromhell icon indicating copy to clipboard operation
mwparserfromhell copied to clipboard

Node select & callable replace interface like re.sub

Open jayvdb opened this issue 8 years ago • 0 comments

It would be useful to have an interface similar to re.sub that allows matching and in-place modifications of wikitext.

pywikibot has many instances of regex's being used, and the regex's are nasty to become close to accurate, and still are not perfect. Ideally we could combined / replace them with mwparserfromhell, and it would be useful if the interface was similar.

Wikicode.replace is a good start, providing reasonable selection. However value currently must be a specific value of some kind. If value could be callable, and the matched node provided as an argument to the call, Wikicode.replace could be used to dynamically determine the replacement value based on the context matched.

jayvdb avatar Oct 28 '15 23:10 jayvdb