Nested refs fail inside references block


By design, Cite does not allow a <ref> to appear within another <ref>. (This is probably a result of parser design and concerns over maintaining the integrity of Cite's internal data stack.)

However, clever Wikipedians realized that one can use #tag to avoid Cite's design limitations and create functional nested references such as:

AAA {{#tag:ref| BBB <ref> CCC </ref> }}

(See also: Bug 16330)

Recently, Cite was expanded to allow reference content to be defined within a references block, i.e.

Foo <ref name="bar"/>

<ref name="bar">blah blah</ref>

While most references work fine in this context, the #tag based nested ref constructions universally fail when moved inside <references>. Depending on the number and order of #tag calls used and the depth of the stack the result will either be an uninformative error message or a misnumbered reference list.

The solution to this is probably to create an implementation that generically supports nested refs. (Part of the problem is that Cite was not intended to allow for nested refs at all and though the #tag based hack worked previously because of quirks in parser behavior, the same call structure doesn't work when moved inside the references block.)

The "right" way to do this is probably to restructure Cite's internal data stack and change the way the evaluation of references are hooked into the parser. I will probably implement this myself eventually, though probably not for some months.

Version: unspecified
Severity: major
See Also:

bzimport added a project: Cite.Via ConduitNov 21 2014, 10:54 PM
bzimport added a subscriber: wikibugs-l.
bzimport set Reference to bz20707.
Dragons_flight created this task.Via LegacySep 18 2009, 1:41 AM
bzimport added a comment.Via ConduitSep 20 2009, 6:18 PM

Ruslik00 wrote:

An obvious solution to this problem is to use {{#tag:references|...}} construct.

Dragons_flight added a comment.Via ConduitSep 20 2009, 7:16 PM

(In reply to comment #1)

An obvious solution to this problem is to use {{#tag:references|...}}

Apparently one can define a nested ref inside a #tag:references as long as both the portions of the nest are also defined by #tag.

Based on an example by Ruslik_Zero:

AAAA<ref name="note1" group="note" />


{{#tag:ref|foo{{#tag:ref|inside ref}}bar|group="note"|name="note1"}}



<references />

Frankly, I'm surprised that even that works, but it will fail if any of those three #tag calls is replaced by a normal invocation. Hence I would say this is a rather fragile work around.

Gadget850 added a comment.Via ConduitMay 11 2010, 2:27 PM

I suspect this is the same issue that causes problems with #tag:ref in list defined references. A single use works, but more than one results in Cite error: <ref> tag defined in <references> has no name attribute.


<ref group=Note name=a />
<ref group=Note name=b />
<ref group=Note name=c />



Nesting #tag:ref does not work either:


Platonides added a comment.Via ConduitMay 22 2010, 3:07 PM

Also see bug 22635

Platonides added a comment.Via ConduitMay 22 2010, 3:08 PM

*** Bug 22300 has been marked as a duplicate of this bug. ***

bzimport added a comment.Via ConduitAug 13 2010, 12:48 PM

athenurlauber wrote:

A reflist containing both a plain ref tag and a "#tag:" ref tag with a nested ref tag in it works if the ref-in-a-ref is listed before the plain ref, and doesn't work if the ref-in-a-ref is listed after the plain ref (demo here

This works:

text<ref name=n1 group=nested_first/>
text<ref name=n2 group=nested_first/>.

;Reflist, nested ref listed first:{{reflist|group=nested_first|refs=

{{#tag:ref|With nested reference<ref>content
of nested reference</ref>|name=n1|group=nested_first}}

<ref name=n2 group=nested_first>With no nested reference</ref>

;Nested refs:

This not:

text<ref name=n3 group=nested_second/>
text<ref name=n4 group=nested_second/>.

;Reflist, nested ref listed second:{{reflist|group=nested_second|refs=

<ref name=n3 group=nested_second>With no nested reference</ref>

{{#tag:ref|With nested reference<ref>content
of nested reference</ref>|name=n4|group=nested_second}}

;Nested refs:

Gadget850 added a comment.Via ConduitOct 6 2011, 1:24 PM

Here is the working sample from above without templates.

Placing <ref name=n2> first throws a "Cite error references no text" and a "Cite error references no key".

Using #tag:ref more than once in the list throws the errors.

text<ref name=n1 group=nested_first/>
text<ref name=n2 group=nested_first/>.



{{#tag:ref|With nested reference<ref>content
of nested reference</ref>|name=n1}}

<ref name=n2>With no nested reference</ref>



<references />

I consider this the most egregious issue with cite.php. The inability to easily add a reference to an explanatory note using cite.php has caused the creation and retention of multiple templates for this purpose. In use, most of these templates create duplicate ids, thus rendering invalid HTML and bad in-page linking.

The simplest fix from the user standpoint would be to allow <ref> tags to nest, while allowing the #tag:ref hack to still work. Note that many uses of #tag:ref have multiple embedded <refs>s. If we have to add new syntax, then we can deal with it.

There is no expectation of multiple nesting, i.e. stuffing a #tag:ref inside a #tag:ref.

mxn added a subscriber: mxn.Via WebNov 24 2014, 8:55 PM

Add Comment

Column Prototype
This is a very early prototype of a persistent column. It is not expected to work yet, and leaving it open will activate other new features which will break things. Press "\" (backslash) on your keyboard to close it now.