Merge pull request #402 from adam3smith/transform-sentence
Change Transform text so that sentence case capitalizes after :, ?, ! Th...
This commit is contained in:
commit
c1c2f6b9de
2 changed files with 12 additions and 3 deletions
|
@ -1947,7 +1947,12 @@
|
||||||
var newVal = Zotero.Utilities.capitalizeTitle(val.toLowerCase(), true);
|
var newVal = Zotero.Utilities.capitalizeTitle(val.toLowerCase(), true);
|
||||||
break;
|
break;
|
||||||
case 'sentence':
|
case 'sentence':
|
||||||
var newVal = val.length ? val[0].toUpperCase()+val.substr(1).toLowerCase() : val;
|
// capitalize the first letter, including after beginning punctuation
|
||||||
|
// capitalize after :, ?, ! and remove space(s) before those analogous to capitalizeTitle function
|
||||||
|
// also deal with initial punctuation here - open quotes and Spanish beginning quotation marks
|
||||||
|
newVal = val.toLowerCase();
|
||||||
|
newVal = newVal.replace(/(([:\?!]\s*|^)([\'\"¡¿“‘„«\s]+)?[^\s])/g, function (x) {
|
||||||
|
return x.replace(/\s+/m, " ").toUpperCase();});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw ("Invalid transform mode '" + mode + "' in zoteroitembox.textTransform()");
|
throw ("Invalid transform mode '" + mode + "' in zoteroitembox.textTransform()");
|
||||||
|
|
|
@ -757,13 +757,17 @@ Zotero.Utilities = {
|
||||||
// not first or last word
|
// not first or last word
|
||||||
&& i != 0 && i != lastWordIndex
|
&& i != 0 && i != lastWordIndex
|
||||||
// does not follow a colon
|
// does not follow a colon
|
||||||
&& (previousWordIndex == -1 || words[previousWordIndex][words[previousWordIndex].length-1] != ":")
|
&& (previousWordIndex == -1 || words[previousWordIndex][words[previousWordIndex].length-1].search(/[:\?!]/)==-1)
|
||||||
) {
|
) {
|
||||||
words[i] = lowerCaseVariant;
|
words[i] = lowerCaseVariant;
|
||||||
} else {
|
} else {
|
||||||
// this is not a skip word or comes after a colon;
|
// this is not a skip word or comes after a colon;
|
||||||
// we must capitalize
|
// we must capitalize
|
||||||
words[i] = upperCaseVariant.substr(0, 1) + lowerCaseVariant.substr(1);
|
// handle punctuation in the beginning, including multiple, as in "¿Qué pasa?"
|
||||||
|
var punct = words[i].match(/^[\'\"¡¿“‘„«\s]+/);
|
||||||
|
punct = punct ? punct[0].length+1 : 1;
|
||||||
|
words[i] = words[i].length ? words[i].substr(0, punct).toUpperCase() +
|
||||||
|
words[i].substr(punct).toLowerCase() : words[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue