@retorquere/bibtex-parser 6.3.2 → 6.3.5
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 +28 -20
- package/package.json +10 -10
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
|
}
|
|
@@ -282,7 +290,7 @@ class Parser {
|
|
|
282
290
|
options.sentenceCase = false;
|
|
283
291
|
options.caseProtection = false;
|
|
284
292
|
}
|
|
285
|
-
this.options = Object.assign({ caseProtection: 'as-needed', verbatimFields: [/^citeulike-linkout-[0-9]+$/, ...exports.fields.verbatim], verbatimCommands: ['url'], unnestFields: [...exports.fields.title, ...exports.fields.unnest, ...exports.fields.verbatim], unnestMode: 'unwrap', htmlFields: exports.fields.html, guessAlreadySentenceCased: true, applyCrossRef: options.applyCrossRef || typeof options.applyCrossRef === 'undefined', markup: {} }, options);
|
|
293
|
+
this.options = Object.assign({ caseProtection: 'as-needed', verbatimFields: [/^citeulike-linkout-[0-9]+$/, /^bdsk-url-[0-9]+$/, ...exports.fields.verbatim], verbatimCommands: ['url'], unnestFields: [...exports.fields.title, ...exports.fields.unnest, ...exports.fields.verbatim], unnestMode: 'unwrap', htmlFields: exports.fields.html, guessAlreadySentenceCased: true, applyCrossRef: options.applyCrossRef || typeof options.applyCrossRef === 'undefined', markup: {} }, options);
|
|
286
294
|
const markup_defaults = {
|
|
287
295
|
enquote: { open: '\u201c', close: '\u201d' },
|
|
288
296
|
sub: { open: '<sub>', close: '</sub>' },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@retorquere/bibtex-parser",
|
|
3
|
-
"version": "6.3.
|
|
3
|
+
"version": "6.3.5",
|
|
4
4
|
"description": "BibTeX parser",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -32,27 +32,27 @@
|
|
|
32
32
|
"author": "Emiliano Heyns",
|
|
33
33
|
"license": "ISC",
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@types/node": "^17.0.
|
|
36
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
37
|
-
"@typescript-eslint/parser": "^5.
|
|
35
|
+
"@types/node": "^17.0.31",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^5.22.0",
|
|
37
|
+
"@typescript-eslint/parser": "^5.22.0",
|
|
38
38
|
"command-line-args": "^5.2.1",
|
|
39
39
|
"csv": "^6.0.5",
|
|
40
40
|
"digital-tree": "^2.0.4",
|
|
41
|
-
"ejs": "^3.1.
|
|
42
|
-
"eslint": "^8.
|
|
41
|
+
"ejs": "^3.1.7",
|
|
42
|
+
"eslint": "^8.15.0",
|
|
43
43
|
"eslint-plugin-import": "^2.26.0",
|
|
44
44
|
"eslint-plugin-prefer-arrow": "^1.2.3",
|
|
45
45
|
"glob": "^8.0.1",
|
|
46
46
|
"mkdirp": "^1.0.4",
|
|
47
|
-
"node-fetch": "^3.2.
|
|
47
|
+
"node-fetch": "^3.2.4",
|
|
48
48
|
"peggy": "^1.2.0",
|
|
49
49
|
"piscina": "^3.2.0",
|
|
50
50
|
"slug": "^5.3.0",
|
|
51
|
-
"tap": "^16.0
|
|
51
|
+
"tap": "^16.2.0",
|
|
52
52
|
"ts-node": "^10.7.0",
|
|
53
|
-
"tslib": "^2.
|
|
53
|
+
"tslib": "^2.4.0",
|
|
54
54
|
"typedoc": "^0.22.15",
|
|
55
|
-
"typescript": "^4.6.
|
|
55
|
+
"typescript": "^4.6.4"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"unicode2latex": "^3.0.0",
|