From a0be2da42c2901483858a19439ccb983f70027ec Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 21 Apr 2019 17:03:16 -0400 Subject: [PATCH] Automatically capitalize subtitle for APA styles Applied to all styles with ids matching 'apa($|-)' Currently limited to colons, but Juris-M/citeproc-js#74 may extend this to other punctuation Closes #1681 --- chrome/content/zotero/xpcom/cite.js | 13 ++++++++++--- chrome/content/zotero/xpcom/style.js | 7 ++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js index 68db2afede..d9d0c7c727 100644 --- a/chrome/content/zotero/xpcom/cite.js +++ b/chrome/content/zotero/xpcom/cite.js @@ -584,13 +584,20 @@ Zotero.Cite.getAbbreviation = new function() { /** * citeproc-js system object + * * @class + * @param {Object} options + * @param {Boolean} [options.automaticJournalAbbreviations] + * @param {Boolean} [options.uppercaseSubtitles] */ -Zotero.Cite.System = function(automaticJournalAbbreviations) { - if(automaticJournalAbbreviations) { +Zotero.Cite.System = function ({ automaticJournalAbbreviations, uppercaseSubtitles }) { + if (automaticJournalAbbreviations) { this.getAbbreviation = Zotero.Cite.getAbbreviation; } -} + if (uppercaseSubtitles) { + this.uppercase_subtitles = true; // eslint-disable-line camelcase + } +}; Zotero.Cite.System.prototype = { /** diff --git a/chrome/content/zotero/xpcom/style.js b/chrome/content/zotero/xpcom/style.js index a65b949eab..88e9e8d81f 100644 --- a/chrome/content/zotero/xpcom/style.js +++ b/chrome/content/zotero/xpcom/style.js @@ -648,6 +648,8 @@ 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._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]', @@ -745,7 +747,10 @@ Zotero.Style.prototype.getCiteProc = function(locale, automaticJournalAbbreviati try { var citeproc = new Zotero.CiteProc.CSL.Engine( - new Zotero.Cite.System(automaticJournalAbbreviations), + new Zotero.Cite.System({ + automaticJournalAbbreviations, + uppercaseSubtitles: this._isAPA + }), xml, locale, overrideLocale