Marcoil has uploaded a new change for review.
https://gerrit.wikimedia.org/r/191593
Change subject: WIP: T88290: Only output <ref> contents in <references>
......................................................................
WIP: T88290: Only output <ref> contents in <references>
Instead of outputting a <ref>'s HTML in both data-mw and in
<references>, output it only in the later and point to it from
data-mw.body.id.
Change-Id: I0fa7ad692585af19136909bfec39db9868b137c5
---
M lib/ext.Cite.js
M lib/mediawiki.WikitextSerializer.js
2 files changed, 31 insertions(+), 16 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/93/191593/1
diff --git a/lib/ext.Cite.js b/lib/ext.Cite.js
index 2584a56..7c1c46c 100644
--- a/lib/ext.Cite.js
+++ b/lib/ext.Cite.js
@@ -208,7 +208,7 @@
RefGroup.prototype.renderLine = function(refsList, ref) {
var ownerDoc = refsList.ownerDocument,
arrow = ownerDoc.createTextNode('↑'),
- li, a;
+ li, a, textSpan;
// Generate the li and set ref content first, so the HTML gets parsed.
// We then append the rest of the ref nodes before the first node
@@ -217,18 +217,17 @@
'about': "#" + ref.target,
'id': ref.target
});
- li.innerHTML = ref.content;
+ textSpan = ownerDoc.createElement('span');
+ textSpan.setAttribute('id', "mw-reference-text-" + ref.target);
+ textSpan.innerHTML = ref.content;
// Mark as coming from a ref so it doesn't get stripped
- // TODO: Instead of marking the <li>, mark just the HTML that comes
from the
- // ref.
- DU.getDataParsoid(li).stx = 'ref';
-
- var contentNode = li.firstChild;
+ DU.getDataParsoid(textSpan).stx = 'ref';
+ li.appendChild(textSpan);
// 'mw:referencedBy' span wrapper
var span = ownerDoc.createElement('span');
span.setAttribute('rel', 'mw:referencedBy');
- li.insertBefore(span, contentNode);
+ li.insertBefore(span, textSpan);
// Generate leading linkbacks
if (ref.linkbacks.length === 1) {
@@ -253,7 +252,7 @@
}
// Space before content node
- li.insertBefore(ownerDoc.createTextNode(' '), contentNode);
+ li.insertBefore(ownerDoc.createTextNode(' '), textSpan);
// Add it to the ref list
refsList.appendChild(li);
@@ -384,7 +383,7 @@
'name': 'ref',
// Dont set body if this is a reused reference
// like <ref name='..' /> with empty content.
- 'body': content ? { 'html': content } : undefined,
+ 'body': content ? { 'id': "mw-reference-text-" +
ref.target } : undefined,
'attrs': {
// 1. Use 'dp.group' (which is the group
attribute that the ref node had)
// rather than use 'group' (which could be
the group from an enclosing
diff --git a/lib/mediawiki.WikitextSerializer.js
b/lib/mediawiki.WikitextSerializer.js
index eccc42f..78cc44e 100644
--- a/lib/mediawiki.WikitextSerializer.js
+++ b/lib/mediawiki.WikitextSerializer.js
@@ -550,13 +550,29 @@
srcParts.push(" />");
} else {
srcParts.push(">");
- if (typeof dataMW.body.html === 'string') {
+ if (typeof dataMW.body.html === 'string' ||
+ typeof dataMW.body.id === 'string') {
var wts = new WikitextSerializer({
- logType: this.logType,
- env: state.env,
- extName: extName
- });
-
srcParts.push(wts.serializeDOM(DU.parseHTML(dataMW.body.html).body));
+ logType: this.logType,
+ env: state.env,
+ extName: extName
+ }),
+ htmlText;
+ // First look for the extension's content in
data-mw.body.html
+ if (dataMW.body.html) {
+ htmlText = dataMW.body.html;
+ } else {
+ // If the body isn't contained in
data-mw.body.html, look if
+ // there's an element pointed to by body.id.
+ var bodyElt =
node.ownerDocument.getElementById(dataMW.body.id);
+ if (bodyElt) {
+ htmlText = bodyElt.innerHTML;
+ } else {
+ this.env.log("error",
+ "extension src id points to
non-existent element for: " + node.outerHTML);
+ }
+ }
+
srcParts.push(wts.serializeDOM(DU.parseHTML(htmlText).body));
} else if (dataMW.body.extsrc !== null && dataMW.body.extsrc
!== undefined) {
srcParts.push(dataMW.body.extsrc);
} else {
--
To view, visit https://gerrit.wikimedia.org/r/191593
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0fa7ad692585af19136909bfec39db9868b137c5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Marcoil <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits