diff --git a/chrome/content/zotero/xpcom/style.js b/chrome/content/zotero/xpcom/style.js index 88e9e8d81f..e9a5dd4e15 100644 --- a/chrome/content/zotero/xpcom/style.js +++ b/chrome/content/zotero/xpcom/style.js @@ -648,8 +648,10 @@ Zotero.Style = function (style, path) { Zotero.Styles.ns).replace(/(.+)T([^\+]+)\+?.*/, "$1 $2"); this.locale = Zotero.Utilities.xpathText(doc, '/csl:style/@default-locale', Zotero.Styles.ns) || null; - var shortID = this.styleID.match(/\/?([^/]+)$/)[1]; - this._isAPA = /^apa($|-)/.test(shortID); + this._uppercaseSubtitles = false; + 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._usesAbbreviation = !!Zotero.Utilities.xpath(doc, '//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( new Zotero.Cite.System({ automaticJournalAbbreviations, - uppercaseSubtitles: this._isAPA + uppercaseSubtitles: this._uppercaseSubtitles }), xml, locale, diff --git a/test/tests/styleTest.js b/test/tests/styleTest.js index 6ea188838f..c86a8e7ac7 100644 --- a/test/tests/styleTest.js +++ b/test/tests/styleTest.js @@ -42,4 +42,45 @@ describe("Zotero.Styles", function() { 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'); + }); + }); });