Add 'references' class to reflist node

* Matches the core Cite extension commit cec36fed

 * This change means we can get rid of some of wiki specific styling in,
   https://github.com/wikimedia/integration-visualdiff/blob/master/lib/parsoid.custom_styles.yaml

Change-Id: I763b8086d057ea0cac8ba8fd4c9f4f4279766fed
This commit is contained in:
Arlo Breault 2017-09-11 14:56:07 -04:00
parent 6e5b366ff6
commit ff09c1667d

View file

@ -5,6 +5,8 @@
'use strict'; 'use strict';
var domino = require('domino');
var ParsoidExtApi = module.parent.require('./extapi.js').versionCheck('^0.7.1'); var ParsoidExtApi = module.parent.require('./extapi.js').versionCheck('^0.7.1');
var Util = ParsoidExtApi.Util; var Util = ParsoidExtApi.Util;
var DU = ParsoidExtApi.DOMUtils; var DU = ParsoidExtApi.DOMUtils;
@ -41,7 +43,6 @@ function hasRef(node) {
} }
c = c.nextSibling; c = c.nextSibling;
} }
return false; return false;
} }
@ -303,6 +304,8 @@ function References(cite) {
this.cite = cite; this.cite = cite;
} }
var dummyDoc = domino.createDocument();
/** /**
* Sanitize the references tag and convert it into a meta-token * Sanitize the references tag and convert it into a meta-token
*/ */
@ -321,9 +324,13 @@ References.prototype.tokenHandler = function(manager, pipelineOpts, refsTok, cb)
// token so that the dom post processor can generate // token so that the dom post processor can generate
// and emit references at this point in the DOM. // and emit references at this point in the DOM.
var emitReferencesFragment = function(toks, refsBody) { var emitReferencesFragment = function(toks, refsBody) {
var olHTML = "<ol class='mw-references'" + var dummyOl = dummyDoc.createElement('ol');
" typeof='mw:Extension/references'" + DU.addAttributes(dummyOl, {
" about='" + referencesId + "'" + ">" + (refsBody || "") + "</ol>"; 'class': 'mw-references references',
typeof: 'mw:Extension/references',
about: referencesId,
});
dummyOl.innerHTML = refsBody || '';
var olProcessor = function(ol) { var olProcessor = function(ol) {
var dp = DU.getDataParsoid(ol); var dp = DU.getDataParsoid(ol);
dp.src = refsTok.getAttribute('source'); dp.src = refsTok.getAttribute('source');
@ -337,7 +344,7 @@ References.prototype.tokenHandler = function(manager, pipelineOpts, refsTok, cb)
tokens: DU.buildDOMFragmentTokens( tokens: DU.buildDOMFragmentTokens(
manager.env, manager.env,
refsTok, refsTok,
olHTML, dummyOl.outerHTML,
olProcessor, olProcessor,
// The <ol> HTML above is wrapper HTML added on and doesn't // The <ol> HTML above is wrapper HTML added on and doesn't
// have any DSR on it. We want DSR added to it. // have any DSR on it. We want DSR added to it.
@ -530,7 +537,7 @@ References.prototype.insertMissingReferencesIntoDOM = function(refsData, node) {
var ol = doc.createElement('ol'); var ol = doc.createElement('ol');
var dp = DU.getDataParsoid(ol); var dp = DU.getDataParsoid(ol);
DU.addAttributes(ol, { DU.addAttributes(ol, {
'class': 'mw-references', 'class': 'mw-references references',
typeof: 'mw:Extension/references', typeof: 'mw:Extension/references',
about: env.newAboutId(), about: env.newAboutId(),
}); });