From 693cd926d55d1b257c28e0da5a70172db1ab6986 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 22 Sep 2020 14:55:08 -0400 Subject: [PATCH] Apply subtitle capitalization to dependent styles based on parent If a style specifies a style like APA that wants uppercase subtitles, the dependent style should have them too. https://forums.zotero.org/discussion/comment/364864/#Comment_364864 --- chrome/content/zotero/xpcom/style.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/chrome/content/zotero/xpcom/style.js b/chrome/content/zotero/xpcom/style.js index b0da8ecf03..4bdda3694d 100644 --- a/chrome/content/zotero/xpcom/style.js +++ b/chrome/content/zotero/xpcom/style.js @@ -649,12 +649,6 @@ Zotero.Style = function (style, path) { this.locale = Zotero.Utilities.xpathText(doc, '/csl:style/@default-locale', Zotero.Styles.ns) || null; - // APA and some similar styles capitalize the first word of subtitles - this._uppercaseSubtitles = false; - var uppercaseSubtitlesRE = /^apa($|-)|^(academy-of-management|freshwater-science)/; - 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]', @@ -698,6 +692,11 @@ Zotero.Style.prototype.getCiteProc = function(locale, automaticJournalAbbreviati } } + // APA and some similar styles capitalize the first word of subtitles + var uppercaseSubtitlesRE = /^apa($|-)|^academy-of-management($|-)|^(freshwater-science)/; + var shortIDMatches = this.styleID.match(/\/?([^/]+)$/); + var uppercaseSubtitles = !!shortIDMatches && uppercaseSubtitlesRE.test(shortIDMatches[1]); + // determine version of parent style var overrideLocale = false; // to force dependent style locale if(this.source) { @@ -717,7 +716,14 @@ Zotero.Style.prototype.getCiteProc = function(locale, automaticJournalAbbreviati overrideLocale = true; locale = this.locale; } - } else { + + // Turn on uppercase subtitles if parent style matches + if (!uppercaseSubtitles) { + let shortIDMatches = parentStyle.styleID.match(/\/?([^/]+)$/); + uppercaseSubtitles = !!shortIDMatches && uppercaseSubtitlesRE.test(shortIDMatches[1]); + } + } + else { var version = this._version; } @@ -754,7 +760,7 @@ Zotero.Style.prototype.getCiteProc = function(locale, automaticJournalAbbreviati var citeproc = new Zotero.CiteProc.CSL.Engine( new Zotero.Cite.System({ automaticJournalAbbreviations, - uppercaseSubtitles: this._uppercaseSubtitles + uppercaseSubtitles }), xml, locale,