I want to write a tool which checks that you are consistent about ordering of <ref> tags. For example, if I did:
The sky is blue.<ref name=“x”/><ref name=“y”/> The grass is green.<ref name=“y”/><ref name=“x”/>
This would get rendered as:
The sky is blue.[1][2] The grass is green.[2][1]
When what you want is:
The sky is blue.[1][2] The grass is green.[1][2]
Checking for out-of-order citations seems pretty straight-forward. In python, I’m using mwclient to get the wikitext, and wikitextparser to extract the tags from that. It should be trivial to check that they always show up in the same order.
The problem is, when I do:
parsed = wtp.parse(wikitext) tags = parsed.tags()
I get a list of tags with no information about which ones are adjacent to each other. So, while the above example is an error, doing:
The sky is blue.<ref name=“x”/><ref name=“y”/> The grass is green.<ref name=“y”/>. The dirt is brown.<ref name=“x”/>
Will render as:
The sky is blue.[1][2] The grass is green.[2] The dirt is brown.[1]
which is perfectly fine. But, wikitextparser’s tags() doesn’t differentiate between those.