From e8f129e8b6d70ba722b4c9f2f78b7da820dee2de Mon Sep 17 00:00:00 2001 From: Frank Bennett Date: Sat, 20 Jul 2019 12:41:34 +0900 Subject: [PATCH] Bump version, update CHANGES, bundle as 1.2.18 --- CHANGES.txt | 11 +++++++++++ citeproc.js | 23 +++++++++++++++++------ citeproc_commonjs.js | 23 +++++++++++++++++------ package.json | 4 ++-- 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 2e7f0de2c..dc2e6fde0 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,16 @@ Summary of changes to citeproc-js since version 1.2 release. +========================= +Changes in version 1.2.18 +========================= + +- On URL with form="short", truncate to host only, and include protocol + prefix only if no leading www + +- Force alignment of title-short casing with main title + + https://forums.zotero.org/discussion/comment/335938/ + ========================= Changes in version 1.2.17 ========================= diff --git a/citeproc.js b/citeproc.js index cd5095501..2d9d0ef17 100644 --- a/citeproc.js +++ b/citeproc.js @@ -743,18 +743,22 @@ var CSL = { // If short title exists and matches exactly to a split-point, use that split-point only. // Otherwise if there is just one split-point, use that as main/sub split. // Otherwise use all split-points ... which is handled in titleCaseSentenceOrNormal, not here. - if (shortTitle && shortTitle === vals[title.title]) { + if (shortTitle && shortTitle.toLowerCase() === vals[title.title].toLowerCase()) { vals[title.main] = vals[title.title]; vals[title.subjoin] = ""; vals[title.sub] = ""; } else if (shortTitle) { // check for valid match to shortTitle - var checkAhead = vals[title.title].slice(shortTitle.replace(/[\?\!]+$/, "").length); - var m = CSL.TITLE_SPLIT_REGEXP.matchfirst.exec(checkAhead); - if (m) { - vals[title.main] = shortTitle; + var tail = vals[title.title].slice(shortTitle.replace(/[\?\!]+$/, "").length); + var top = vals[title.title].replace(tail.replace(/^[\?\!]+/, ""), "").trim(); + var m = CSL.TITLE_SPLIT_REGEXP.matchfirst.exec(tail); + if (m && top.toLowerCase() === shortTitle.toLowerCase()) { + vals[title.main] = top; vals[title.subjoin] = m[1].replace(/[\?\!]+(\s*)$/, "$1"); - vals[title.sub] = checkAhead.replace(CSL.TITLE_SPLIT_REGEXP.matchfirst, ""); + vals[title.sub] = tail.replace(CSL.TITLE_SPLIT_REGEXP.matchfirst, ""); + if (this.opt.development_extensions.force_short_title_casing_alignment) { + vals[title["short"]] = vals[title.main]; + } } else { var splitTitle = CSL.TITLE_SPLIT(vals[title.title]); if (splitTitle.length == 3) { @@ -6176,6 +6180,7 @@ CSL.Engine.Opt = function () { this.development_extensions.throw_on_empty = false; this.development_extensions.strict_inputs = true; this.development_extensions.prioritize_disambiguate_condition = false; + this.development_extensions.force_short_title_casing_alignment = true; }; CSL.Engine.Tmp = function () { @@ -14983,6 +14988,12 @@ CSL.Node.text = { if (this.variables[0]) { value = state.getVariable(Item, this.variables[0], form); if (value) { + if (this.variables[0] === "URL" && form === "short") { + value = value.replace(/(.*\.[^\/]+)\/.*/, "$1"); + if (value.match(/\/\/www\./)) { + value = value.replace(/https?:\/\//, ""); + } + } // true is for non-suppression of periods if (state.opt.development_extensions.wrap_url_and_doi) { if (!this.decorations.length || this.decorations[0][0] !== "@" + this.variables[0]) { diff --git a/citeproc_commonjs.js b/citeproc_commonjs.js index 270564bc9..9d27f51ff 100644 --- a/citeproc_commonjs.js +++ b/citeproc_commonjs.js @@ -743,18 +743,22 @@ var CSL = { // If short title exists and matches exactly to a split-point, use that split-point only. // Otherwise if there is just one split-point, use that as main/sub split. // Otherwise use all split-points ... which is handled in titleCaseSentenceOrNormal, not here. - if (shortTitle && shortTitle === vals[title.title]) { + if (shortTitle && shortTitle.toLowerCase() === vals[title.title].toLowerCase()) { vals[title.main] = vals[title.title]; vals[title.subjoin] = ""; vals[title.sub] = ""; } else if (shortTitle) { // check for valid match to shortTitle - var checkAhead = vals[title.title].slice(shortTitle.replace(/[\?\!]+$/, "").length); - var m = CSL.TITLE_SPLIT_REGEXP.matchfirst.exec(checkAhead); - if (m) { - vals[title.main] = shortTitle; + var tail = vals[title.title].slice(shortTitle.replace(/[\?\!]+$/, "").length); + var top = vals[title.title].replace(tail.replace(/^[\?\!]+/, ""), "").trim(); + var m = CSL.TITLE_SPLIT_REGEXP.matchfirst.exec(tail); + if (m && top.toLowerCase() === shortTitle.toLowerCase()) { + vals[title.main] = top; vals[title.subjoin] = m[1].replace(/[\?\!]+(\s*)$/, "$1"); - vals[title.sub] = checkAhead.replace(CSL.TITLE_SPLIT_REGEXP.matchfirst, ""); + vals[title.sub] = tail.replace(CSL.TITLE_SPLIT_REGEXP.matchfirst, ""); + if (this.opt.development_extensions.force_short_title_casing_alignment) { + vals[title["short"]] = vals[title.main]; + } } else { var splitTitle = CSL.TITLE_SPLIT(vals[title.title]); if (splitTitle.length == 3) { @@ -6176,6 +6180,7 @@ CSL.Engine.Opt = function () { this.development_extensions.throw_on_empty = false; this.development_extensions.strict_inputs = true; this.development_extensions.prioritize_disambiguate_condition = false; + this.development_extensions.force_short_title_casing_alignment = true; }; CSL.Engine.Tmp = function () { @@ -14983,6 +14988,12 @@ CSL.Node.text = { if (this.variables[0]) { value = state.getVariable(Item, this.variables[0], form); if (value) { + if (this.variables[0] === "URL" && form === "short") { + value = value.replace(/(.*\.[^\/]+)\/.*/, "$1"); + if (value.match(/\/\/www\./)) { + value = value.replace(/https?:\/\//, ""); + } + } // true is for non-suppression of periods if (state.opt.development_extensions.wrap_url_and_doi) { if (!this.decorations.length || this.decorations[0][0] !== "@" + this.variables[0]) { diff --git a/package.json b/package.json index edadcb0d3..0571b28db 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "citeproc", - "version": "2.2.17", - "description": "The citeproc-js citation formatting module, in CommonJS format. This version is based on citeproc-js 1.2.17", + "version": "2.2.18", + "description": "The citeproc-js citation formatting module, in CommonJS format. This version is based on citeproc-js 1.2.18", "main": "citeproc_commonjs.js", "repository": { "type": "git",