mwparserfromhell
mwparserfromhell copied to clipboard
Node select & callable replace interface like re.sub
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.