So @flying-sheep started working on resolving references by writing a two-pass transform approach: one which would walk the tree to keep track of every target of a reference, and then one which would walk the tree making the corresponding changes. I'm not sure anymore that all references can be resolved that way.
So, the different types of targets and references in ReST are:
The thing that makes this hard, perhaps impossible, to resolve in those two passes is substitutions, which in docutils get handled earlier than every other reference. Right now our parser only accepts an image directive inside a substitution definition, but in the general case substitution references can be replaced by any inline content (with the replace directive, for example), which can in turn have auto-numbered footnote references, anonymous hyperlink references or hyperlinks with an embedded URL.
I guess for now we could handle everything in those two passes, but in the future we'll have to move the code for substitutions to its own separate two passes that run before the others.
So @flying-sheep started working on resolving references by writing a two-pass transform approach: one which would walk the tree to keep track of every target of a reference, and then one which would walk the tree making the corresponding changes. I'm not sure anymore that all references can be resolved that way.
So, the different types of targets and references in ReST are:
implicit targets, which include section titles, footnotes which are either manually numbered or have autonumber labels, and citations. [See my next comment for what docutils actually treats as explicit and implicit targets.]The thing that makes this hard, perhaps impossible, to resolve in those two passes is substitutions, which in
docutilsget handled earlier than every other reference. Right now our parser only accepts animagedirective inside a substitution definition, but in the general case substitution references can be replaced by any inline content (with thereplacedirective, for example), which can in turn have auto-numbered footnote references, anonymous hyperlink references or hyperlinks with an embedded URL.I guess for now we could handle everything in those two passes, but in the future we'll have to move the code for substitutions to its own separate two passes that run before the others.