Skip to content

Commit

Permalink
A little more help for page ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
fbennett committed Mar 4, 2018
1 parent 2ab68fb commit e85300a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/util_number.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions src/util_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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);
}
}
Expand Down

0 comments on commit e85300a

Please sign in to comment.