Page MenuHomePhabricator

[refactor] Parsoid must always emit data-mw for reference list items
Closed, InvalidPublic

Description

The goal of this task is that Parsoid includes data-mw on the reflist <li> as the source of truth for footnote body content.

Background

Parsoid will render a main+details ref by putting the main ref footnote body into the reference list's data-mw attribute. Wikitext such as:

<ref name="main" details="{{1x|wrapped details text}}">{{1x|wrapped text}}</ref>

Is rendered as:

<p id="mwAg"><sup about="#mwt2" class="mw-ref reference" id="cite_ref-2" rel="dc:references" typeof="mw:Extension/ref"
		data-mw="{&quot;name&quot;:&quot;ref&quot;,&quot;attrs&quot;:{&quot;name&quot;:&quot;main&quot;,&quot;details&quot;:&quot;{{1x|wrapped details text}}&quot;},&quot;body&quot;:{&quot;id&quot;:&quot;mw-reference-text-cite_note-2&quot;},&quot;mainRef&quot;:&quot;main&quot;,&quot;isSubRefWithMainBody&quot;:1}"><a
			href="#cite_note-2" id="mwAw" title=""><span class="mw-reflink-text" id="mwBA"><span class="cite-bracket"
					id="mwBQ">[</span>1.1<span class="cite-bracket" id="mwBg">
					]</span></span></a></sup></p>

<div class="mw-references-wrap" typeof="mw:Extension/references" about="#mwt4" id="mwBw"
	data-mw="{&quot;name&quot;:&quot;references&quot;,&quot;attrs&quot;:{},&quot;autoGenerated&quot;:true,&quot;body&quot;:{&quot;html&quot;:&quot;\n&lt;sup typeof=\&quot;mw:Extension/ref\&quot; data-parsoid=\&quot;{}\&quot; data-mw='{\&quot;name\&quot;:\&quot;ref\&quot;,\&quot;attrs\&quot;:{\&quot;name\&quot;:\&quot;main\&quot;,\&quot;group\&quot;:\&quot;\&quot;},\&quot;body\&quot;:{\&quot;id\&quot;:\&quot;mw-reference-text-cite_note-main-1\&quot;},\&quot;isSyntheticMainRef\&quot;:1}'&gt;&lt;span about=\&quot;#mwt1\&quot; typeof=\&quot;mw:Transclusion\&quot; data-parsoid=\&quot;{}\&quot; data-mw='{\&quot;parts\&quot;:[{\&quot;template\&quot;:{\&quot;target\&quot;:{\&quot;wt\&quot;:\&quot;1x\&quot;,\&quot;href\&quot;:\&quot;./Template:1x\&quot;},\&quot;params\&quot;:{\&quot;1\&quot;:{\&quot;wt\&quot;:\&quot;wrapped text\&quot;}},\&quot;i\&quot;:0}}]}'&gt;wrapped text&lt;/span&gt;&lt;/sup&gt;&quot;}}">
	<ol class="mw-references references" id="mwCA">
		<li about="#cite_note-main-1" id="cite_note-main-1" data-mw-footnote-number="1"><span rel="mw:referencedBy"
				class="mw-cite-backlink" id="mwCQ"></span> <span id="mw-reference-text-cite_note-main-1"
				class="mw-reference-text reference-text"><span about="#mwt1" typeof="mw:Transclusion" id="mwCg"
					data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;1x&quot;,&quot;href&quot;:&quot;./Template:1x&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;wrapped text&quot;}},&quot;i&quot;:0}}]}">wrapped
					text</span></span>
			<ol class="mw-subreference-list" id="mwCw">
				<li about="#cite_note-2" id="cite_note-2" data-mw-footnote-number="1.1"><span class="mw-cite-backlink"
						id="mwDA"><a href="#cite_ref-2" rel="mw:referencedBy" id="mwDQ" aria-label="Jump up" title="Jump up"><span
								class="mw-linkback-text" id="mwDg">↑ </span></a></span> <span id="mw-reference-text-cite_note-2"
						class="mw-reference-text reference-text"><span about="#mwt3" typeof="mw:Transclusion" id="mwDw"
							data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;1x&quot;,&quot;href&quot;:&quot;./Template:1x&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;wrapped details text&quot;}},&quot;i&quot;:0}}]}">wrapped
							details text</span></span></li>
			</ol>
		</li>
	</ol>
</div>

When wikitext is nontrivial, data-mw is also added reflist list items. It's clearest when using a template:if the footnote body contains {{1x|main body}} then the reflist item contains the transclusion data.

Outcome

In Cite Parsoid, RefTagHandler has always called extTagToDOM which renders the ref tag as a <sup> containing wikitextToDOM of the ref body wikitext. The sup's firstChild (the footnote body) is copied into the reflist and includes data-mw.

This even works inside of a template-produced {{reflist}}.

It also works for subrefs, whose content Cite produces directly using wikitextToDOM stored by a separate code path in externalFragment—still correctly including data-mw.

Event Timeline

awight renamed this task from Investigation: Parsoid should emit main+details in a format that doesn't require "synthetic list-defined refs" to Parsoid must always emit data-mw in the reference list.Oct 9 2025, 2:33 PM
awight renamed this task from Parsoid must always emit data-mw in the reference list to Parsoid must always emit data-mw for reference list items.Oct 9 2025, 2:40 PM
awight renamed this task from Parsoid must always emit data-mw for reference list items to [refactor] Parsoid must always emit data-mw for reference list items.
awight moved this task from Doing to Done on the WMDE-TechWish-Sprint-2025-10-14-Choco-Soufflé board.

The outcome is that reflist <li> elements already include the needed data-mw to be transformed back to wikitext, as needed. Full explanation will be added to the task description.

awight updated the task description. (Show Details)