I am a contributor to Wikipedia and I would like to make a script with AutoHotKey that could format the wikicode of infoboxes and other similar templates.
Infoboxes are templates that displays a box on the side of articles and shows the values of the parameters entered (they are numerous and they differ in number, lenght and type of characters used depending on the infobox).
Parameters are always preceded by a pipe (|) and end with an equal sign (=). On rare occasions, multiple parameters can be put on the same line, but I can sort this manually before running the script.
A typical infobox will be like this:
Code: Select all
{{Infobox XYZ
| first parameter = foo
| second_parameter =
| 3rd parameter = bar
| 4th = bazzzzz
| 5th =
| etc. =
}}
Code: Select all
{{Infobox XYZ
|first parameter=foo
|second_parameter=
|3rd parameter=bar
|4th=bazzzzz
|5th=
|etc.=
}}
I would like to know if it is possible to make a regex (or a serie of regexes) that would transform the second example into the first.
The lines should start with a space, then a pipe, then another space, then the parameter name, then any number of spaces (to match the other lines lenght), then an equal sign, then another space, and if present, the parameter value.
I try some things using multiple capturing groups, but I'm going nowhere... (this is the best I could make: https://regex101.com/r/GunrUg/1).
Would someone have an idea on how to make it work?
I have asked also on StackOverflow https://stackoverflow.com/questions/74448042/regex-to-format-wikipedias-infoboxes-code?noredirect=1#comment131424643_74448042 and Taazar told me about a JS script I could add to my common.js page on Wikipedia, but it doesn't seem to work for me (script is here: https://en.wikipedia.org/wiki/User:Taavi/Aligner.js )
Thank you for your time.