Page MenuHomePhabricator

ref might add a newline
Closed, ResolvedPublic

Description

Author: dogma

Description:
When the very first <ref> tag in an article is followed by a newline, e.g.:

<ref>
This is reference 1
</ref>

It adds a newline in the reference itself:

But this does not occur with later references, e.g.:

<ref>
This is reference 2
</ref>

What these refs actually render as is this (but see the example on en.wikipedia):

  1. ^

This is reference 1

  1. ^ This is reference 2

Version: unspecified
Severity: minor
URL: http://en.wikipedia.org/wiki/User:Evercat/test

Details

Reference
bz13073

Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 10:03 PM
bzimport added a project: Cite.
bzimport set Reference to bz13073.
bzimport added a subscriber: Unknown Object (MLST).

dogma wrote:

Correction: this only seems to occur when <div class="references-small"> is used.

ncw33 wrote:

I have tested this both with reflist and without and cannot reproduce. Please provide a link (or perma-link, better) to an actual example. If you can reproduce this, reopen it; otherwise, this bug cannot be reproduced using the information you have given, so will be closed.

ncw33 wrote:

My bad. I didn't notice the link given as well as the code in the post. The example given at the test page on WP does indeed demonstrate the bug, but it does not on my own MW.

So, we have a strange parser oddity to track down. The newline does not appear on third or fourth references, just the first, so there is an off-by-one error in the parser going on here. I have not yet had time to track down why it works on my setup and not yours, but I think this is the same as bug 11224.

This has little to do with Cite; it's mainly a Tidy issue.

Consider the following test case:

<ref>
foo
</ref>
<ref>
bar
</ref>
<div><references/></div>

As far as Cite is concerned, it outputs wikitext something like this for the <references/> tag:

<ol><li id="cite_note-0">[[#cite_ref-0|↑]]
foo
</li>
<li id="cite_note-1">[[#cite_ref-1|↑]]
bar
</li></ol>

The page output handed to the parser is therefore something like this:

<div><ol><li id="cite_note-0">[[#cite_ref-0|↑]]
foo
</li>
<li id="cite_note-1">[[#cite_ref-1|↑]]
bar
</li></ol></div>

When Tidy sees the <div> on the same line as the <li>, it decides it has to wrap the rest of the lines in that <li> with <p> tags, which causes the odd output noted in this bug.

We ''could'' work around this in Cite by outputting newlines around the contents of the references list. Then the parser would see something like this:

<div><ol>
<li id="cite_note-0">[[#cite_ref-0|↑]]
foo
</li>
<li id="cite_note-1">[[#cite_ref-1|↑]]
bar
</li>
</ol></div>

Since the <div> on not on the same line as the <li> anymore, Tidy won't insert the problematic <p> tags.

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

Gerrit change #30795 implements what I suggested in comment 4.