Improve test for event-title
substitution
And add comments
Follow-up to 20d0f103f
This commit is contained in:
parent
ebacb83563
commit
c90f8415b3
2 changed files with 12 additions and 2 deletions
|
@ -799,10 +799,16 @@ Zotero.Style.prototype.getCiteProc = function(locale, format, automaticJournalAb
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Temporarily substitute `event-title` for `event`
|
||||||
|
*
|
||||||
|
* Until https://github.com/citation-style-language/styles/issues/6151
|
||||||
|
*/
|
||||||
Zotero.Style.prototype._eventToEventTitle = function (xml) {
|
Zotero.Style.prototype._eventToEventTitle = function (xml) {
|
||||||
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
|
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
|
||||||
.createInstance(Components.interfaces.nsIDOMParser);
|
.createInstance(Components.interfaces.nsIDOMParser);
|
||||||
var doc = parser.parseFromString(xml, "text/xml");
|
var doc = parser.parseFromString(xml, "text/xml");
|
||||||
|
// Ignore styles that already include `event-title`
|
||||||
if (doc.querySelector('[variable*="event-title"]')) {
|
if (doc.querySelector('[variable*="event-title"]')) {
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
@ -813,6 +819,7 @@ Zotero.Style.prototype._eventToEventTitle = function (xml) {
|
||||||
var changed = false;
|
var changed = false;
|
||||||
for (let elem of elems) {
|
for (let elem of elems) {
|
||||||
let variable = elem.getAttribute('variable');
|
let variable = elem.getAttribute('variable');
|
||||||
|
// Must be "event" or "event foo", not, say, "event-place"
|
||||||
if (!/event( |$)/.test(variable)) {
|
if (!/event( |$)/.test(variable)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,9 @@ describe("Zotero.Styles", function() {
|
||||||
<layout>
|
<layout>
|
||||||
<text variable="event"/>
|
<text variable="event"/>
|
||||||
<text value=" - "/>
|
<text value=" - "/>
|
||||||
<text variable="event event-place"/>
|
<text variable="event foo"/>
|
||||||
|
<text value=" - "/>
|
||||||
|
<text variable="event-place"/>
|
||||||
</layout>
|
</layout>
|
||||||
</bibliography>
|
</bibliography>
|
||||||
</style>
|
</style>
|
||||||
|
@ -113,6 +115,7 @@ describe("Zotero.Styles", function() {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
item.setField('conferenceName', 'Conference');
|
item.setField('conferenceName', 'Conference');
|
||||||
|
item.setField('place', 'Place');
|
||||||
await item.saveTx();
|
await item.saveTx();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -121,7 +124,7 @@ describe("Zotero.Styles", function() {
|
||||||
var cslEngine = style.getCiteProc('en-US', 'text');
|
var cslEngine = style.getCiteProc('en-US', 'text');
|
||||||
var text = Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, [item], "text");
|
var text = Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, [item], "text");
|
||||||
cslEngine.free();
|
cslEngine.free();
|
||||||
assert.equal(text, 'Conference - Conference\n');
|
assert.equal(text, 'Conference - Conference - Place\n');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue