Suppose I wanted to change all occurrences of
{{cite book | ... | isbn=123 | ...}} into ... | id=ISBN 123 | ...
or all {{cite book | last=Marx | first=Karl | ...}} into | author=Karl Marx | ...
How would I do that? Apparently template.py can only change the template name (e.g. "cite book" into some other language) and the regexp capability of replace.py quickly makes this a mess, especially when you consider that first=Karl|year=1867|last=Marx is just as valid, and that template calls can contain newlines.
I guess what I want is a robot framework that finds all uses of a specified template (e.g. "cite book") and makes a call to a user-defined function, that receives the template parameters as a dictionary (hash, mapping). Then I could write specific Python code like this:
t[id] = 'ISBN ' + t[isbn] del t[isbn]
t[author] = t[first] + ' ' + t[last] del t[first] del t[last]
This too sounds easy until you consider that parameter values can contain template calls, e.g. {{cite book|...|id={{ISSN|1234-5678}}}}, so simply matching {{.*?}} isn't enough.
And then when the user-defined function returns, the dictionary must be packed back into text, preserving as much as possible of the previous whitespace and newline structure, to minimize the edit diff.
Has anybody tried this?