Goal: understand why VE is not able to recognize and process references produced by templates
Output: an explanation of the problem and feasibility assessment of solving it.
Problem statements
I am an editor using visual editor
I'm trying to identify and work with existing references in an article.
But the numbers in the body of the article don't match the numbers in the <references> section at the bottom of the article.
Because VE apparently gets confused when some <ref> are not in the article but in a template.
I am an editor using visual editor.
I'm trying to copy and paste an existing citation to reuse it for the first time in the article.
But the reference instance is given an automatic number by VE that already exists on the article page, and VE doesn't warn me before saving.
Because a reference named ":0" already exists (maybe inside of a template transclusion?) and a new name like ":0" is assigned which already exists on the page. Also VE doesn't preview the error message, even if there is one after the page is saved.
Notes
- References added within a template (like an infobox) show up in the list now (see resolved ticket T53289), but they are not editable (T52896).
- This is likely a bigger problem, there are other cards which seem to be related to the invisibility of refs inside a template transclusion.//
See also:
- T52474: In VisualEditor, references in templates cannot be reused and are numbered separately from references in the text.
- T215867: Visual editor reference auto name may collide with existing ref names when the existing reference comes from a template tranclusion
- T150612: Information about ref name is not provided if the ref is generated by a template and it's the root
- https://app.asana.com/0/1203688298459190/1204011426355425
- https://app.asana.com/0/1203688298459190/1204063551050056
Outcomes
There are two very different issues preventing this from working already.
- In the case that the template emits a ref tag as its top-level output node, the data-mw for the template conflicts with the ref's structured data, and the template data wins. This is discussed in T214241 and some ideas were suggested, but it's currently an open problem. The changes will need to take place in Parsoid, to generally support the case where multiple wikitext constructs overlap to create a single DOM element. Once that's solved, we can probably teach VE to understand this additional data.
- If the template output has a deeper hierarchy and the ref tag appears with at least one level of parent node above it, then the ref attributes are discoverable in Parsoid output. VE is currently able to render these Cite elements correctly but they're ignored by the editor. This is probably intentional and it seems feasible to change VE to recognize the refs as read-only nodes which are still catalogued in the full list of refs, enabling reuse, avoiding name collisions, and other use cases. I assume that any general solution to the first problem (ref and template data-mw colliding) will also make the ref accessible to VE in a similar way as more deeply-nested refs currently are.