Apply subtitle capitalization to additional styles

This also fixes a style initialization error when the style id is
invalid, which was a regression in a0be2da42c.
This commit is contained in:
Dan Stillman 2019-07-01 04:30:47 -04:00
parent d13ffcd9a3
commit f49d5805cd
2 changed files with 46 additions and 3 deletions

View file

@ -648,8 +648,10 @@ Zotero.Style = function (style, path) {
Zotero.Styles.ns).replace(/(.+)T([^\+]+)\+?.*/, "$1 $2"); Zotero.Styles.ns).replace(/(.+)T([^\+]+)\+?.*/, "$1 $2");
this.locale = Zotero.Utilities.xpathText(doc, '/csl:style/@default-locale', this.locale = Zotero.Utilities.xpathText(doc, '/csl:style/@default-locale',
Zotero.Styles.ns) || null; Zotero.Styles.ns) || null;
var shortID = this.styleID.match(/\/?([^/]+)$/)[1]; this._uppercaseSubtitles = false;
this._isAPA = /^apa($|-)/.test(shortID); var uppercaseSubtitlesRE = /^apa($|-)|^(academy-of-management|american-medical-association)/;
var shortIDMatches = this.styleID.match(/\/?([^/]+)$/);
this._uppercaseSubtitles = !!shortIDMatches && uppercaseSubtitlesRE.test(shortIDMatches[1]);
this._class = doc.documentElement.getAttribute("class"); this._class = doc.documentElement.getAttribute("class");
this._usesAbbreviation = !!Zotero.Utilities.xpath(doc, this._usesAbbreviation = !!Zotero.Utilities.xpath(doc,
'//csl:text[(@variable="container-title" and @form="short") or (@variable="container-title-short")][1]', '//csl:text[(@variable="container-title" and @form="short") or (@variable="container-title-short")][1]',
@ -749,7 +751,7 @@ Zotero.Style.prototype.getCiteProc = function(locale, automaticJournalAbbreviati
var citeproc = new Zotero.CiteProc.CSL.Engine( var citeproc = new Zotero.CiteProc.CSL.Engine(
new Zotero.Cite.System({ new Zotero.Cite.System({
automaticJournalAbbreviations, automaticJournalAbbreviations,
uppercaseSubtitles: this._isAPA uppercaseSubtitles: this._uppercaseSubtitles
}), }),
xml, xml,
locale, locale,

View file

@ -42,4 +42,45 @@ describe("Zotero.Styles", function() {
yield Zotero.Styles.install({file: stylePath}, styleID, true); yield Zotero.Styles.install({file: stylePath}, styleID, true);
}) })
}); });
describe("subtitle capitalization", function () {
var item;
before(async function () {
item = createUnsavedDataObject(
'item',
{
itemType: 'journalArticle',
title: 'Foo bar: baz qux'
}
);
item.setField('shortTitle', 'Foo bar');
item.setField('date', '2019');
await item.saveTx();
});
it("should capitalize subtitles in APA", async function () {
var o = Zotero.QuickCopy.getContentFromItems(
[item],
'bibliography=http://www.zotero.org/styles/apa'
);
assert.equal(o.text, 'Foo bar: Baz qux. (2019).\n');
});
it("should capitalize subtitles in AMA", async function () {
var o = Zotero.QuickCopy.getContentFromItems(
[item],
'bibliography=http://www.zotero.org/styles/american-medical-association'
);
assert.equal(o.text, '1. Foo bar: Baz qux. 2019.\n');
});
it("shouldn't capitalize subtitles in Vancouver", async function () {
var o = Zotero.QuickCopy.getContentFromItems(
[item],
'bibliography=http://www.zotero.org/styles/vancouver'
);
assert.equal(o.text, '1. Foo bar: baz qux. 2019; \n');
});
});
}); });