@retorquere/bibtex-parser 6.3.2 → 6.3.3
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 +27 -19
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -23,6 +23,7 @@ class SentenceCaser {
|
|
|
23
23
|
this.allCaps = (0, xregexp_1.default)('^\\p{Lu}+$');
|
|
24
24
|
this.aint = (0, xregexp_1.default)("^\\p{L}n't(?=$|[\\P{L}])"); // isn't
|
|
25
25
|
this.word = (0, xregexp_1.default)('^\\p{L}+(-\\p{L}+)*'); // also match gallium-nitride as one word
|
|
26
|
+
this.and = (0, xregexp_1.default)('^\\p{Lu}&\\p{Lu}(?=$|[\\P{L}])'); // Q&A
|
|
26
27
|
}
|
|
27
28
|
convert(text, ignoreHTML = false) {
|
|
28
29
|
this.input = text;
|
|
@@ -51,44 +52,51 @@ class SentenceCaser {
|
|
|
51
52
|
});
|
|
52
53
|
}
|
|
53
54
|
}
|
|
55
|
+
this.input = this.input.replace(/[;:]\s+A\s/g, match => match.toLowerCase());
|
|
56
|
+
this.input = this.input.replace(/[–—]\s*A\s/g, match => match.toLowerCase());
|
|
54
57
|
let m;
|
|
55
58
|
while (this.input) {
|
|
56
59
|
if (m = xregexp_1.default.exec(this.input, this.quoted)) { // "Hello There"
|
|
57
|
-
this.add(m[0], true);
|
|
60
|
+
this.add(m[0], undefined, true);
|
|
58
61
|
}
|
|
59
62
|
else if (m = xregexp_1.default.exec(this.input, this.acronym)) { // U.S.
|
|
60
|
-
this.add(m[0],
|
|
63
|
+
this.add(m[0], undefined, true);
|
|
61
64
|
}
|
|
62
65
|
else if (m = xregexp_1.default.exec(this.input, this.aint)) { // isn't
|
|
63
|
-
this.add(m[0]);
|
|
66
|
+
this.add(m[0], undefined, false);
|
|
64
67
|
}
|
|
65
68
|
else if (m = xregexp_1.default.exec(this.input, this.word)) {
|
|
66
|
-
this.add(m[0]);
|
|
69
|
+
this.add(m[0], '-', false);
|
|
70
|
+
}
|
|
71
|
+
else if (m = xregexp_1.default.exec(this.input, this.and)) {
|
|
72
|
+
this.add(m[0], undefined, true);
|
|
67
73
|
}
|
|
68
74
|
else {
|
|
69
|
-
this.add(this.input[0]);
|
|
75
|
+
this.add(this.input[0], undefined, false);
|
|
70
76
|
}
|
|
71
77
|
}
|
|
72
78
|
return restore(this.result, text, preserve);
|
|
73
79
|
}
|
|
74
|
-
add(word, keep
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
add(word, splitter, keep) {
|
|
81
|
+
if (splitter) {
|
|
82
|
+
word = word.split(splitter).map((part, i) => {
|
|
83
|
+
if ((keep || this.sentenceStart) && i === 0)
|
|
84
|
+
return part;
|
|
85
|
+
if (xregexp_1.default.exec(part, this.innerCaps))
|
|
86
|
+
return part;
|
|
87
|
+
if (xregexp_1.default.exec(part, this.allCaps))
|
|
88
|
+
return part;
|
|
81
89
|
return part.toLowerCase();
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
90
|
+
}).join(splitter);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
if (!keep)
|
|
94
|
+
word = word.toLowerCase();
|
|
95
|
+
}
|
|
88
96
|
this.result += word;
|
|
89
97
|
this.input = this.input.substr(word.length);
|
|
90
98
|
if (!word.match(/^\s+$/)) {
|
|
91
|
-
this.sentenceStart = !!word.match(/^[.?!]$/);
|
|
99
|
+
this.sentenceStart = !!word.match(/^[.?!]$/) || (word.length === 2 && word[1] === '.'); // Vitamin A. Vitamin B.
|
|
92
100
|
}
|
|
93
101
|
}
|
|
94
102
|
}
|