@retorquere/bibtex-parser 6.4.4 → 6.4.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 +7 -0
- package/index.js +11 -3
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -63,6 +63,13 @@ export interface Entry {
|
|
|
63
63
|
* will be set to `true` if sentence casing was applied to the entry
|
|
64
64
|
*/
|
|
65
65
|
sentenceCased?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* list of fields that have been inherited/donated using crossref/xdata
|
|
68
|
+
*/
|
|
69
|
+
crossref: {
|
|
70
|
+
donated: string[];
|
|
71
|
+
inherited: string[];
|
|
72
|
+
};
|
|
66
73
|
}
|
|
67
74
|
/**
|
|
68
75
|
* Markup mapping. As the bibtex file is parsed, markup will be transformed according to this table
|
package/index.js
CHANGED
|
@@ -387,12 +387,16 @@ class Parser {
|
|
|
387
387
|
}
|
|
388
388
|
return this.parsed();
|
|
389
389
|
}
|
|
390
|
-
|
|
390
|
+
applyCrossrefField(parent, parentfield, child, childfield) {
|
|
391
391
|
let applied = false;
|
|
392
392
|
for (const field of ['fields', 'creators']) {
|
|
393
393
|
if (!child[field][childfield] && parent[field][parentfield]) {
|
|
394
394
|
child[field][childfield] = parent[field][parentfield];
|
|
395
395
|
applied = true;
|
|
396
|
+
if (!child.crossref.inherited.includes(childfield))
|
|
397
|
+
child.crossref.inherited.push(childfield);
|
|
398
|
+
if (!parent.crossref.donated.includes(parentfield))
|
|
399
|
+
parent.crossref.donated.push(parentfield);
|
|
396
400
|
}
|
|
397
401
|
}
|
|
398
402
|
return applied;
|
|
@@ -408,11 +412,11 @@ class Parser {
|
|
|
408
412
|
for (const mappings of [crossref_json_1.default[entry.type], crossref_json_1.default['*']].filter(m => m)) {
|
|
409
413
|
for (const mapping of [mappings[parent.type], mappings['*']].filter(m => m)) {
|
|
410
414
|
for (const [target, source] of Object.entries(mapping)) {
|
|
411
|
-
if (this.
|
|
415
|
+
if (this.applyCrossrefField(parent, source, entry, target))
|
|
412
416
|
applied = true;
|
|
413
417
|
}
|
|
414
418
|
for (const field of (fields_json_1.default[entry.type] || [])) {
|
|
415
|
-
if (this.
|
|
419
|
+
if (this.applyCrossrefField(parent, field, entry, field))
|
|
416
420
|
applied = true;
|
|
417
421
|
}
|
|
418
422
|
}
|
|
@@ -1297,6 +1301,10 @@ class Parser {
|
|
|
1297
1301
|
type: node.type,
|
|
1298
1302
|
fields: {},
|
|
1299
1303
|
creators: {},
|
|
1304
|
+
crossref: {
|
|
1305
|
+
inherited: [],
|
|
1306
|
+
donated: [],
|
|
1307
|
+
},
|
|
1300
1308
|
};
|
|
1301
1309
|
this.entries.push(this.entry);
|
|
1302
1310
|
// order these first for language-dependent sentence casing
|