@retorquere/bibtex-parser 7.0.0 → 7.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +5 -1
- package/package.json +1 -1
- package/sentence-case.js +5 -2
package/index.js
CHANGED
|
@@ -1330,10 +1330,14 @@ class Parser {
|
|
|
1330
1330
|
}
|
|
1331
1331
|
else {
|
|
1332
1332
|
if (this.field.preserveRanges) {
|
|
1333
|
-
|
|
1333
|
+
const allCaps = this.field.text.match(/\s/) && this.field.words.upper && !this.field.words.lower && !this.field.words.other;
|
|
1334
|
+
const seemsSentenceCased = Math.max(this.field.words.upper, this.field.words.lower) > (this.field.words.other + Math.min(this.field.words.upper, this.field.words.lower));
|
|
1335
|
+
if (!allCaps && seemsSentenceCased && this.options.guessAlreadySentenceCased) {
|
|
1334
1336
|
this.preserve(null, null); // , 'mostly sentence cased already')
|
|
1335
1337
|
}
|
|
1336
1338
|
else {
|
|
1339
|
+
if (allCaps)
|
|
1340
|
+
this.field.preserveRanges = [];
|
|
1337
1341
|
const txt = this.field.text.replace(preserveCase.markup, markup => marker.markup.repeat(markup.length));
|
|
1338
1342
|
let match;
|
|
1339
1343
|
preserveCase.sentenceStart.lastIndex = 0;
|
package/package.json
CHANGED
package/sentence-case.js
CHANGED
|
@@ -23,9 +23,11 @@ const re = {
|
|
|
23
23
|
// private word = XRegExp('^\\p{L}+([-.]\\p{L}+)*') // also match gallium-nitride as one word
|
|
24
24
|
// private and = XRegExp('^\\p{Lu}&\\p{Lu}(?=$|[\\P{L}])') // Q&A
|
|
25
25
|
};
|
|
26
|
-
function lowercase(word) {
|
|
26
|
+
function lowercase(word, allcaps) {
|
|
27
27
|
if (!word)
|
|
28
28
|
return word;
|
|
29
|
+
if (allcaps)
|
|
30
|
+
return word.toLowerCase();
|
|
29
31
|
const unmasked = word.replace(/\uFFFD/g, '');
|
|
30
32
|
if (unmasked.match(re.skipWords))
|
|
31
33
|
return word.toLowerCase();
|
|
@@ -41,6 +43,7 @@ function lowercase(word) {
|
|
|
41
43
|
return word.toLowerCase();
|
|
42
44
|
}
|
|
43
45
|
function toSentenceCase(sentence, preserveQuoted = false) {
|
|
46
|
+
const allcaps = sentence === sentence.toUpperCase();
|
|
44
47
|
const preserve = [];
|
|
45
48
|
sentence.replace(/([.?!][\s]+)(<[^>]+>)?([A-Z])/g, (match, end, markup, char, i) => {
|
|
46
49
|
if (!sentence.substring(0, i + 1).match(re.acronym)) {
|
|
@@ -74,7 +77,7 @@ function toSentenceCase(sentence, preserveQuoted = false) {
|
|
|
74
77
|
masked = masked
|
|
75
78
|
.replace(/[;:]\uFFFD*\s+\uFFFD*A\s/g, match => match.toLowerCase())
|
|
76
79
|
.replace(/[–—]\uFFFD*\s*\uFFFD*A\s/g, match => match.toLowerCase())
|
|
77
|
-
.replace(re.words, word => lowercase(word));
|
|
80
|
+
.replace(re.words, word => lowercase(word, allcaps));
|
|
78
81
|
sentence = masked;
|
|
79
82
|
for (const { pos, text } of preserve) {
|
|
80
83
|
sentence = sentence.substring(0, pos) + text + sentence.substring(pos + text.length);
|