From e85300a8245c8f4109fedee7a4d7d6df599bc2a9 Mon Sep 17 00:00:00 2001 From: Frank Bennett Date: Sun, 4 Mar 2018 14:52:22 +0900 Subject: [PATCH] A little more help for page ranges --- src/util_number.js | 10 +++++----- src/util_page.js | 10 ++++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/util_number.js b/src/util_number.js index 4a829951d..0c4ad7685 100644 --- a/src/util_number.js +++ b/src/util_number.js @@ -244,10 +244,10 @@ CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type) info.labelVisibility = false; } - var m = val.match(/^([a-zA-Z0]*)([0-9]+(?:[a-zA-Z]*|[-,a-zA-Z]+))$/); - //var m = val.match(/^([a-zA-Z]0*)([0-9]+(?:[a-zA-Z]*|[-,a-zA-Z]+))$/); + var m = val.match(/^([0-9]*[a-zA-Z]+0*)?([0-9]+(?:[a-zA-Z]*|[-,a-zA-Z]+))$/); + //var m = val.match(/^([0-9]*[a-zA-Z]0*)([0-9]+(?:[a-zA-Z]*|[-,a-zA-Z]+))$/); if (m) { - info.particle = m[1]; + info.particle = m[1] ? m[1] : ""; info.value = m[2]; } else { info.particle = ""; @@ -602,7 +602,7 @@ CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type) } else { str = values[i-1].value + stripHyphenBackslash(values[i-1].joiningSuffix) + values[i].value; } - var m = str.match(/^([a-zA-Z]?0*)([0-9]+)(\s*[^0-9]+\s*)([-,a-zA-Z]?0*)([0-9]+)$/); + var m = str.match(/^((?:[0-9]*[a-zA-Z]+0*))?([0-9]+)(\s*[^0-9]+\s*)([-,a-zA-Z]?0*)([0-9]+)$/); if (m) { var rangeDelimiter = m[3]; rangeDelimiter = fixupRangeDelimiter(variable, val, rangeDelimiter, values[i].numeric); @@ -844,7 +844,7 @@ CSL.Util.outputNumericField = function(state, varname, itemID) { } } if (num.collapsible) { - if (num.value.match(/^[0-9]+$/)) { + if (num.value.match(/^[1-9][0-9]*$/)) { var blob = new CSL.NumericBlob(num.particle, parseInt(num.value, 10), numStyling, itemID); } else { var blob = new CSL.NumericBlob(num.particle, num.value, numStyling, itemID); diff --git a/src/util_page.js b/src/util_page.js index c118cbf99..81b0d09d9 100644 --- a/src/util_page.js +++ b/src/util_page.js @@ -7,7 +7,7 @@ CSL.Util.PageRangeMangler.getFunction = function (state, rangeType) { var range_delimiter = state.getTerm(rangeType + "-range-delimiter"); - rangerex = /([a-zA-Z]*)([0-9]+)\s*(?:\u2013|-)\s*([a-zA-Z]*)([0-9]+)/; + rangerex = /([0-9]*[a-zA-Z]+0*)?([0-9]+)\s*(?:\u2013|-)\s*([0-9]*[a-zA-Z]+0*)?([0-9]+)/; stringify = function (lst) { len = lst.length; @@ -30,8 +30,10 @@ CSL.Util.PageRangeMangler.getFunction = function (state, rangeType) { var delimRex = new RegExp("([^\\\\])[-" + this_range_delimiter + "\\u2013]", "g"); str = str.replace(delimRex, "$1 - ").replace(/\s+-\s+/g, " - "); // Workaround for Internet Explorer - var rexm = new RegExp("([a-zA-Z]*[0-9]+" + hyphens + "[a-zA-Z]*[0-9]+)", "g"); - var rexlst = new RegExp("[a-zA-Z]*[0-9]+" + hyphens + "[a-zA-Z]*[0-9]+"); + //var rexm = new RegExp("((?:[0-9]*[a-zA-Z]+)?[0-9]+" + hyphens + "(?:[0-9]*[a-zA-Z]+)?[0-9]+)", "g"); + //var rexlst = new RegExp("(?:[0-9]*[a-zA-Z]+)?[0-9]+" + hyphens + "(?:[0-9]*[a-zA-Z]+)?[0-9]+"); + var rexm = new RegExp("((?:[0-9]*[a-zA-Z]+0*)?[0-9]+" + hyphens + "(?:[0-9]*[a-zA-Z]+0*)?[0-9]+)", "g"); + var rexlst = new RegExp("(?:[0-9]*[a-zA-Z]+0*)?[0-9]+" + hyphens + "(?:[0-9]*[a-zA-Z]+0*)?[0-9]+"); m = str.match(rexm); lst = str.split(rexlst); if (lst.length === 0) { @@ -58,7 +60,7 @@ CSL.Util.PageRangeMangler.getFunction = function (state, rangeType) { m[4] = m[2].slice(0, (m[2].length - m[4].length)) + m[4]; } if (parseInt(m[2], 10) < parseInt(m[4], 10)) { - m[3] = range_delimiter + m[1]; + m[3] = range_delimiter + (m[1] ? m[1] : ""); lst[pos] = m.slice(1); } }