@retorquere/bibtex-parser 8.0.3 → 8.0.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.d.ts +2 -2
- package/index.js +8 -2
- package/package.json +1 -1
- package/verbatim.d.ts +4 -8
- package/verbatim.js +8 -12
package/index.d.ts
CHANGED
|
@@ -124,7 +124,7 @@ export interface Options {
|
|
|
124
124
|
*/
|
|
125
125
|
applyCrossRef?: boolean;
|
|
126
126
|
}
|
|
127
|
-
interface Creator {
|
|
127
|
+
export interface Creator {
|
|
128
128
|
name?: string;
|
|
129
129
|
lastName?: string;
|
|
130
130
|
firstName?: string;
|
|
@@ -134,7 +134,7 @@ interface Creator {
|
|
|
134
134
|
useprefix?: boolean;
|
|
135
135
|
juniorcomma?: boolean;
|
|
136
136
|
}
|
|
137
|
-
interface Entry {
|
|
137
|
+
export interface Entry {
|
|
138
138
|
type: string;
|
|
139
139
|
key: string;
|
|
140
140
|
fields: {
|
package/index.js
CHANGED
|
@@ -670,6 +670,8 @@ class BibTeXParser {
|
|
|
670
670
|
return (node.content[0].type !== 'macro');
|
|
671
671
|
}
|
|
672
672
|
mode(field) {
|
|
673
|
+
if (this.options.verbatimFields && this.options.verbatimFields.find(name => typeof name === 'string' ? (name === field) : field.match(name)))
|
|
674
|
+
return 'verbatim';
|
|
673
675
|
let mode = 'literal';
|
|
674
676
|
for (const [selected, fields] of Object.entries(this.fieldMode)) {
|
|
675
677
|
if (fields.find(match => typeof match === 'string' ? field === match : field.match(match)))
|
|
@@ -897,6 +899,8 @@ class BibTeXParser {
|
|
|
897
899
|
this.options = Object.assign(Object.assign({ caseProtection: 'as-needed', unabbreviations: true, applyCrossRef: (_a = options.applyCrossRef) !== null && _a !== void 0 ? _a : true, fieldMode: {} }, options), { sentenceCase });
|
|
898
900
|
if (this.options.caseProtection === true)
|
|
899
901
|
this.options.caseProtection = 'as-needed';
|
|
902
|
+
if (this.options.verbatimFields)
|
|
903
|
+
this.options.verbatimFields = this.options.verbatimFields.map(f => typeof f === 'string' ? f.toLowerCase() : new RegExp(f.source, f.flags + (f.flags.includes('i') ? '' : 'i')));
|
|
900
904
|
if (typeof this.options.sentenceCase.langids === 'boolean')
|
|
901
905
|
this.options.sentenceCase.langids = this.options.sentenceCase.langids ? English : [];
|
|
902
906
|
this.options.sentenceCase.langids = this.options.sentenceCase.langids.map(langid => langid.toLowerCase());
|
|
@@ -946,6 +950,8 @@ class BibTeXParser {
|
|
|
946
950
|
delete entry.fields[field];
|
|
947
951
|
continue;
|
|
948
952
|
}
|
|
953
|
+
if (this.options.raw)
|
|
954
|
+
continue;
|
|
949
955
|
this.field(entry, field, value, sentenceCase);
|
|
950
956
|
if (field.match(/^keywords\[\d+\]$/)) {
|
|
951
957
|
keywords = [...keywords, entry.fields[field]];
|
|
@@ -1027,7 +1033,7 @@ class BibTeXParser {
|
|
|
1027
1033
|
}
|
|
1028
1034
|
parse(input, options = {}) {
|
|
1029
1035
|
this.reset(options);
|
|
1030
|
-
const base = bibtex.parse(input);
|
|
1036
|
+
const base = bibtex.parse(input, { strings: options.strings });
|
|
1031
1037
|
this.prep(base);
|
|
1032
1038
|
for (const entry of base.entries) {
|
|
1033
1039
|
this.reparse(entry);
|
|
@@ -1038,7 +1044,7 @@ class BibTeXParser {
|
|
|
1038
1044
|
async parseAsync(input, options = {}) {
|
|
1039
1045
|
var _a, e_1, _b, _c;
|
|
1040
1046
|
this.reset(options);
|
|
1041
|
-
const base = await bibtex.promises.parse(input);
|
|
1047
|
+
const base = await bibtex.promises.parse(input, { strings: options.strings });
|
|
1042
1048
|
this.prep(base);
|
|
1043
1049
|
try {
|
|
1044
1050
|
for (var _d = true, _e = __asyncValues(asyncGenerator(base.entries)), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
|
package/package.json
CHANGED
package/verbatim.d.ts
CHANGED
|
@@ -7,16 +7,16 @@ export type Entry = {
|
|
|
7
7
|
export interface ParseError {
|
|
8
8
|
error: string;
|
|
9
9
|
input: string;
|
|
10
|
-
location?: {
|
|
11
|
-
line: number;
|
|
12
|
-
column: number;
|
|
13
|
-
};
|
|
14
10
|
}
|
|
15
11
|
export interface ParserOptions {
|
|
16
12
|
/**
|
|
17
13
|
* stop parsing after `max_entries` entries have been found. Useful for quick detection if a text file is in fact a bibtex file
|
|
18
14
|
*/
|
|
19
15
|
max_entries?: number;
|
|
16
|
+
/**
|
|
17
|
+
* preload these strings
|
|
18
|
+
*/
|
|
19
|
+
strings?: string | Record<string, string>;
|
|
20
20
|
}
|
|
21
21
|
declare class Parser {
|
|
22
22
|
parsing: string;
|
|
@@ -36,10 +36,6 @@ declare class Parser {
|
|
|
36
36
|
private max_entries;
|
|
37
37
|
private keywords;
|
|
38
38
|
constructor(input: string, options?: ParserOptions);
|
|
39
|
-
location(pos: number): {
|
|
40
|
-
line: number;
|
|
41
|
-
column: number;
|
|
42
|
-
};
|
|
43
39
|
parse(): void;
|
|
44
40
|
parseAsync(): Promise<void>;
|
|
45
41
|
private isWhitespace;
|
package/verbatim.js
CHANGED
|
@@ -86,23 +86,20 @@ class Parser {
|
|
|
86
86
|
this.input = input;
|
|
87
87
|
this.parsing = null;
|
|
88
88
|
this.keywords = 0;
|
|
89
|
+
if (typeof options.strings === 'string') {
|
|
90
|
+
this.input = options.strings + '\n' + input; // eslint-disable-line prefer-template
|
|
91
|
+
}
|
|
92
|
+
else if (options.strings) {
|
|
93
|
+
for (const [k, v] of Object.entries(options.strings)) {
|
|
94
|
+
this.default_strings[k.toUpperCase()] = v;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
89
97
|
let pos = input.indexOf('\n');
|
|
90
98
|
while (pos !== -1) {
|
|
91
99
|
this.linebreaks.push(pos);
|
|
92
100
|
pos = input.indexOf('\n', pos + 1);
|
|
93
101
|
}
|
|
94
102
|
}
|
|
95
|
-
location(pos) {
|
|
96
|
-
let line = 1;
|
|
97
|
-
let column = 1;
|
|
98
|
-
for (const linebreak of this.linebreaks) {
|
|
99
|
-
if (pos < linebreak)
|
|
100
|
-
break;
|
|
101
|
-
line++;
|
|
102
|
-
column = pos - linebreak;
|
|
103
|
-
}
|
|
104
|
-
return { line, column };
|
|
105
|
-
}
|
|
106
103
|
parse() {
|
|
107
104
|
this.bibtex();
|
|
108
105
|
this.entries.reverse();
|
|
@@ -232,7 +229,6 @@ class Parser {
|
|
|
232
229
|
if (typeof resolved === 'undefined') {
|
|
233
230
|
this.errors.push({
|
|
234
231
|
error: `Unresolved @string reference ${JSON.stringify(bare)}`,
|
|
235
|
-
location: this.location(this.pos),
|
|
236
232
|
input: bare,
|
|
237
233
|
});
|
|
238
234
|
}
|