@retorquere/bibtex-parser 7.0.7 → 7.0.9
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/grammar.d.ts +1 -1
- package/grammar.js +682 -601
- package/index.js +30 -29
- package/package.json +17 -17
- package/sentence-case.js +1 -1
- package/strings.bib +3243 -0
- package/unabbrev.json +29 -29
package/index.js
CHANGED
|
@@ -148,7 +148,7 @@ exports.fields = {
|
|
|
148
148
|
'file',
|
|
149
149
|
'files',
|
|
150
150
|
'pdf',
|
|
151
|
-
'groups',
|
|
151
|
+
'groups', // jabref unilaterally decided to make this non-standard field verbatim
|
|
152
152
|
'ids',
|
|
153
153
|
'url',
|
|
154
154
|
'verba',
|
|
@@ -299,7 +299,7 @@ class Parser {
|
|
|
299
299
|
ast(input, clean = true) {
|
|
300
300
|
let parsed = [];
|
|
301
301
|
for (const chunk of chunker.parse(input)) {
|
|
302
|
-
const { children } = bibtex.parse(chunk.text, Object.assign(Object.assign({}, this.options), {
|
|
302
|
+
const { children } = bibtex.parse(chunk.text, Object.assign(Object.assign({}, this.options), { combining: unicode2latex_1.combining.commands }));
|
|
303
303
|
if (clean)
|
|
304
304
|
this.clean(children);
|
|
305
305
|
parsed = parsed.concat(children);
|
|
@@ -419,7 +419,7 @@ class Parser {
|
|
|
419
419
|
parseChunk(chunk) {
|
|
420
420
|
this.chunk = chunk.text;
|
|
421
421
|
try {
|
|
422
|
-
let bib = bibtex.parse(chunk.text, Object.assign(Object.assign({}, this.options), {
|
|
422
|
+
let bib = bibtex.parse(chunk.text, Object.assign(Object.assign({}, this.options), { combining: unicode2latex_1.combining.commands }));
|
|
423
423
|
if (bib.kind !== 'Bibliography')
|
|
424
424
|
throw new Error(this.show(bib));
|
|
425
425
|
bib = this.clean(bib);
|
|
@@ -704,14 +704,14 @@ class Parser {
|
|
|
704
704
|
clean_script(node) {
|
|
705
705
|
let m, value, singlechar;
|
|
706
706
|
// recognize combined forms like \^\circ
|
|
707
|
-
if (singlechar = unicode2latex_1.
|
|
707
|
+
if (singlechar = unicode2latex_1.latex2unicode[node.source])
|
|
708
708
|
return this.text(singlechar);
|
|
709
|
-
if ((m = node.source.match(/^([\^_])([^{}]+)$/)) && ((singlechar = unicode2latex_1.
|
|
709
|
+
if ((m = node.source.match(/^([\^_])([^{}]+)$/)) && ((singlechar = unicode2latex_1.latex2unicode[`${m[1]}${m[2]}`]) || (singlechar = unicode2latex_1.latex2unicode[`${m[1]}{${m[2]}}`])))
|
|
710
710
|
return this.text(singlechar);
|
|
711
|
-
if ((m = node.source.match(/^([\^_])\{([^{}]+)\}$/)) && ((singlechar = unicode2latex_1.
|
|
711
|
+
if ((m = node.source.match(/^([\^_])\{([^{}]+)\}$/)) && ((singlechar = unicode2latex_1.latex2unicode[`${m[1]}${m[2]}`]) || (singlechar = unicode2latex_1.latex2unicode[`${m[1]}{${m[2]}}`])))
|
|
712
712
|
return this.text(singlechar);
|
|
713
713
|
const cmd = node.kind === 'SuperscriptCommand' ? '^' : '_';
|
|
714
|
-
if (typeof node.value === 'string' && (singlechar = unicode2latex_1.
|
|
714
|
+
if (typeof node.value === 'string' && (singlechar = unicode2latex_1.latex2unicode[`${cmd}${node.value}`] || unicode2latex_1.latex2unicode[`${cmd}{${node.value}}`])) {
|
|
715
715
|
return this.text(singlechar);
|
|
716
716
|
}
|
|
717
717
|
if (typeof node.value === 'string') {
|
|
@@ -767,13 +767,13 @@ class Parser {
|
|
|
767
767
|
}
|
|
768
768
|
clean_diacritic(node) {
|
|
769
769
|
const char = node.dotless ? `\\${node.character}` : node.character;
|
|
770
|
-
let unicode = unicode2latex_1.
|
|
771
|
-
|| unicode2latex_1.
|
|
772
|
-
|| unicode2latex_1.
|
|
773
|
-
|| unicode2latex_1.
|
|
774
|
-
|| unicode2latex_1.
|
|
775
|
-
if (!unicode && !node.dotless && node.character.length === 1 && unicode2latex_1.
|
|
776
|
-
unicode = node.character + unicode2latex_1.
|
|
770
|
+
let unicode = unicode2latex_1.latex2unicode[`\\${node.mark}{${char}}`]
|
|
771
|
+
|| unicode2latex_1.latex2unicode[`\\${node.mark}${char}`]
|
|
772
|
+
|| unicode2latex_1.latex2unicode[`{\\${node.mark} ${char}}`]
|
|
773
|
+
|| unicode2latex_1.latex2unicode[`{\\${node.mark}${char}}`]
|
|
774
|
+
|| unicode2latex_1.latex2unicode[`\\${node.mark} ${char}`];
|
|
775
|
+
if (!unicode && !node.dotless && node.character.length === 1 && unicode2latex_1.combining.tounicode[node.mark])
|
|
776
|
+
unicode = node.character + unicode2latex_1.combining.tounicode[node.mark];
|
|
777
777
|
if (!unicode && !this.in_preamble)
|
|
778
778
|
return this.error(new TeXError(`Unhandled \\${node.mark}{${char}}`, node, this.chunk));
|
|
779
779
|
return this.text(unicode);
|
|
@@ -781,7 +781,7 @@ class Parser {
|
|
|
781
781
|
clean_symbol(node) {
|
|
782
782
|
if (node.command === '\\')
|
|
783
783
|
return this.text('\n');
|
|
784
|
-
return this.text(unicode2latex_1.
|
|
784
|
+
return this.text(unicode2latex_1.latex2unicode[`\\${node.command}`] || node.command);
|
|
785
785
|
}
|
|
786
786
|
first_text_block(node) {
|
|
787
787
|
if (!node)
|
|
@@ -809,7 +809,7 @@ class Parser {
|
|
|
809
809
|
clean_command(node) {
|
|
810
810
|
var _a;
|
|
811
811
|
let arg, unicode;
|
|
812
|
-
if (unicode = unicode2latex_1.
|
|
812
|
+
if (unicode = unicode2latex_1.latex2unicode[node.source])
|
|
813
813
|
return this.text(unicode);
|
|
814
814
|
switch (node.command) {
|
|
815
815
|
case 'newcommand':
|
|
@@ -827,7 +827,7 @@ class Parser {
|
|
|
827
827
|
return { kind: 'Markup', value: '<li>', source: node.source };
|
|
828
828
|
case 'frac':
|
|
829
829
|
if (arg = this.argument(node, 2)) {
|
|
830
|
-
if (arg[0].kind === 'Text' && arg[1].kind === 'Text' && (unicode = unicode2latex_1.
|
|
830
|
+
if (arg[0].kind === 'Text' && arg[1].kind === 'Text' && (unicode = unicode2latex_1.latex2unicode[`\\frac{${arg[0].value}}{${arg[1].value}}`]))
|
|
831
831
|
return this.text(unicode);
|
|
832
832
|
return this.clean({
|
|
833
833
|
kind: 'Block',
|
|
@@ -854,10 +854,11 @@ class Parser {
|
|
|
854
854
|
case 'else':
|
|
855
855
|
case 'fi':
|
|
856
856
|
case 'makeatletter':
|
|
857
|
+
case 'mathslbb':
|
|
857
858
|
return this.text();
|
|
858
859
|
case 'ElsevierGlyph':
|
|
859
860
|
if (arg = this.argument(node, 'Text')) {
|
|
860
|
-
if (unicode = unicode2latex_1.
|
|
861
|
+
if (unicode = unicode2latex_1.latex2unicode[`\\${node.command}{${arg}}`])
|
|
861
862
|
return this.text(unicode);
|
|
862
863
|
return this.text(String.fromCharCode(parseInt(arg, 16)));
|
|
863
864
|
}
|
|
@@ -888,14 +889,14 @@ class Parser {
|
|
|
888
889
|
break;
|
|
889
890
|
case 'textsuperscript':
|
|
890
891
|
case 'sp':
|
|
891
|
-
if ((arg = this.argument(node, 'Text')) && (unicode = unicode2latex_1.
|
|
892
|
+
if ((arg = this.argument(node, 'Text')) && (unicode = unicode2latex_1.latex2unicode[`^{${arg}}`]))
|
|
892
893
|
return this.text(unicode);
|
|
893
894
|
if (arg = this.argument(node, 'Block'))
|
|
894
895
|
return this.clean(arg);
|
|
895
896
|
break;
|
|
896
897
|
case 'textsubscript':
|
|
897
898
|
case 'sb':
|
|
898
|
-
if ((arg = this.argument(node, 'Text')) && (unicode = unicode2latex_1.
|
|
899
|
+
if ((arg = this.argument(node, 'Text')) && (unicode = unicode2latex_1.latex2unicode[`_{${arg}}`]))
|
|
899
900
|
return this.text(unicode);
|
|
900
901
|
if (arg = this.argument(node, 'Block'))
|
|
901
902
|
return this.clean(arg);
|
|
@@ -923,7 +924,7 @@ class Parser {
|
|
|
923
924
|
if (arg = this.argument(node, 'text')) {
|
|
924
925
|
if (node.command === 'mbox' && !arg)
|
|
925
926
|
return this.text('\u200b');
|
|
926
|
-
unicode = unicode2latex_1.
|
|
927
|
+
unicode = unicode2latex_1.latex2unicode[`\\${node.command}{${arg}}`];
|
|
927
928
|
return this.text(unicode || (node.command === 'hspace' ? ' ' : arg));
|
|
928
929
|
}
|
|
929
930
|
else if (!node.arguments.required.length) {
|
|
@@ -978,7 +979,7 @@ class Parser {
|
|
|
978
979
|
value: JSON.parse(JSON.stringify(this.newcommands[node.command])),
|
|
979
980
|
});
|
|
980
981
|
}
|
|
981
|
-
if (unicode2latex_1.
|
|
982
|
+
if (unicode2latex_1.combining.tounicode[node.command]) {
|
|
982
983
|
node.arguments.required = this.clean(node.arguments.required);
|
|
983
984
|
let block;
|
|
984
985
|
if (node.arguments.required.length === 1 && node.arguments.required[0].kind === 'Text') {
|
|
@@ -1023,15 +1024,15 @@ class Parser {
|
|
|
1023
1024
|
return this.clean({
|
|
1024
1025
|
kind: 'Block',
|
|
1025
1026
|
markup: {},
|
|
1026
|
-
value: [this.text(` ${unicode2latex_1.
|
|
1027
|
+
value: [this.text(` ${unicode2latex_1.combining.tounicode[node.command]}`)].concat(node.arguments.required),
|
|
1027
1028
|
});
|
|
1028
1029
|
}
|
|
1029
1030
|
}
|
|
1030
|
-
if (unicode = unicode2latex_1.
|
|
1031
|
+
if (unicode = unicode2latex_1.latex2unicode[node.source] || unicode2latex_1.latex2unicode[`${node.source}{}`])
|
|
1031
1032
|
return this.text(unicode);
|
|
1032
|
-
if ((unicode = unicode2latex_1.
|
|
1033
|
+
if ((unicode = unicode2latex_1.latex2unicode[`\\${node.command}`] || unicode2latex_1.latex2unicode[`\\${node.command}{}`]) && this.argument(node, 'none'))
|
|
1033
1034
|
return this.text(unicode);
|
|
1034
|
-
if ((arg = this.argument(node, 'Text')) && (unicode = unicode2latex_1.
|
|
1035
|
+
if ((arg = this.argument(node, 'Text')) && (unicode = unicode2latex_1.latex2unicode[`\\${node.command}{${arg}}`]))
|
|
1035
1036
|
return this.text(unicode);
|
|
1036
1037
|
break;
|
|
1037
1038
|
}
|
|
@@ -1324,7 +1325,7 @@ class Parser {
|
|
|
1324
1325
|
}
|
|
1325
1326
|
}
|
|
1326
1327
|
else if (exports.fields.unabbrev.includes(field.name)) { // doesn't get sentence casing anyhow TODO: booktitle does!
|
|
1327
|
-
this.entry.fields[this.field.name].push(
|
|
1328
|
+
this.entry.fields[this.field.name].push(this.options.unabbreviate[this.field.text] || this.field.text);
|
|
1328
1329
|
}
|
|
1329
1330
|
else {
|
|
1330
1331
|
if (this.field.preserveRanges) {
|
|
@@ -1357,7 +1358,7 @@ class Parser {
|
|
|
1357
1358
|
}
|
|
1358
1359
|
}
|
|
1359
1360
|
}
|
|
1360
|
-
this.entry.fields[this.field.name].push(this.convertToSentenceCase(this.field.text)
|
|
1361
|
+
this.entry.fields[this.field.name].push(this.convertToSentenceCase(this.field.text));
|
|
1361
1362
|
}
|
|
1362
1363
|
}
|
|
1363
1364
|
this.field = null;
|
|
@@ -1486,7 +1487,7 @@ class Parser {
|
|
|
1486
1487
|
const cmd = mode === 'sup' ? '^' : '_';
|
|
1487
1488
|
let script = '';
|
|
1488
1489
|
for (const char of chars) {
|
|
1489
|
-
const unicode = unicode2latex_1.
|
|
1490
|
+
const unicode = unicode2latex_1.latex2unicode[`${cmd}${char}`] || unicode2latex_1.latex2unicode[`${cmd}{${char}}`];
|
|
1490
1491
|
script += unicode ? unicode : `<${mode}>${char}</${mode}>`;
|
|
1491
1492
|
}
|
|
1492
1493
|
script = script.replace(new RegExp(`</${mode}><${mode}>`, 'g'), '');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@retorquere/bibtex-parser",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.9",
|
|
4
4
|
"description": "BibTeX parser",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "./index.d.ts",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"tsc": "tsc -d",
|
|
12
12
|
"poststart": "npm run docs",
|
|
13
13
|
"pretest": "npm start",
|
|
14
|
-
"test": "tap
|
|
14
|
+
"test": "tap --timeout 0 --disable-coverage --allow-empty-coverage",
|
|
15
15
|
"snap": "npm test --snapshot",
|
|
16
16
|
"snap:big": "npm test --snapshot --big",
|
|
17
17
|
"minitest": "peggy grammar.peggy && ./build/crossref.py && tsc -d && node i.js",
|
|
@@ -37,31 +37,31 @@
|
|
|
37
37
|
"author": "Emiliano Heyns",
|
|
38
38
|
"license": "ISC",
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@microsoft/api-documenter": "^7.
|
|
41
|
-
"@microsoft/api-extractor": "^7.
|
|
42
|
-
"@types/node": "^20.
|
|
43
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
44
|
-
"@typescript-eslint/parser": "^6.
|
|
40
|
+
"@microsoft/api-documenter": "^7.23.20",
|
|
41
|
+
"@microsoft/api-extractor": "^7.39.4",
|
|
42
|
+
"@types/node": "^20.11.9",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^6.19.1",
|
|
44
|
+
"@typescript-eslint/parser": "^6.19.1",
|
|
45
45
|
"command-line-args": "^5.2.1",
|
|
46
|
-
"csv": "^6.3.
|
|
46
|
+
"csv": "^6.3.6",
|
|
47
47
|
"digital-tree": "^2.0.4",
|
|
48
48
|
"ejs": "^3.1.9",
|
|
49
|
-
"eslint": "^8.
|
|
50
|
-
"eslint-plugin-import": "^2.
|
|
49
|
+
"eslint": "^8.56.0",
|
|
50
|
+
"eslint-plugin-import": "^2.29.1",
|
|
51
51
|
"eslint-plugin-prefer-arrow": "^1.2.3",
|
|
52
|
-
"glob": "^10.3.
|
|
52
|
+
"glob": "^10.3.10",
|
|
53
53
|
"mkdirp": "^3.0.1",
|
|
54
54
|
"node-fetch": "^3.3.2",
|
|
55
55
|
"peggy": "^3.0.2",
|
|
56
|
-
"piscina": "^4.
|
|
56
|
+
"piscina": "^4.3.0",
|
|
57
57
|
"slug": "^8.2.3",
|
|
58
|
-
"tap": "^
|
|
59
|
-
"ts-node": "^10.9.
|
|
60
|
-
"tslib": "^2.6.
|
|
61
|
-
"typescript": "^5.
|
|
58
|
+
"tap": "^18.7.0",
|
|
59
|
+
"ts-node": "^10.9.2",
|
|
60
|
+
"tslib": "^2.6.2",
|
|
61
|
+
"typescript": "^5.3.3"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"unicode2latex": "^
|
|
64
|
+
"unicode2latex": "^4.0.42",
|
|
65
65
|
"xregexp": "^5.1.1"
|
|
66
66
|
},
|
|
67
67
|
"files": [
|
package/sentence-case.js
CHANGED
|
@@ -17,7 +17,7 @@ const re = {
|
|
|
17
17
|
allCaps: new RegExp(`^[${Lu}${N}${No}]+$`),
|
|
18
18
|
skipWords: /^(but|or|yet|so|for|and|nor|a|an|the|at|by|from|in|into|of|on|to|with|updown|as)$/i,
|
|
19
19
|
// chemElements: /^(H|He|Li|Be|B|C|N|O|F|Ne|Na|Mg|Al|Si|P|S|Cl|Ar|K|Ca|Sc|Ti|V|Cr|Mn|Fe|Co|Ni|Cu|Zn|Ga|Ge|As|Se|Br|Kr|Rb|Sr|Y|Zr|Nb|Mo|Tc|Ru|Rh|Pb|Ag|Cd|In|Sn|Sb|Te|I|Xe|Cs|Ba|La|Hf|Ta|W|Re|Os|Ir|Pt|Au|Hg|Tl|Pb|Bi|Po|At|Rn|Fr|Ra|Ac|Rf|Db|Sg|Bh|Hs|Mt|Ds|Rg|Cn|Nh|Fl|Mc|Lv|Ts|Og|La|Ce|Pr|Nd|Pm|Sm|Eu|Gd|Tb|Dy|Ho|Er|Tm|Yb|Lu|Ac|Th|Pa|U|Np|Pu|Am|Cm|Bk|Cf|Es|Fm|Md|No|Lr)$/,
|
|
20
|
-
words: new RegExp(`([\uFFFD${L}${N}${No}]+([\uFFFD${Pc}${L}${N}${No}]*))|(\\s([\uFFFD${Lu}]+[.]){2,})?`, 'g'),
|
|
20
|
+
words: new RegExp(`([\uFFFD${L}${N}${No}]+([\uFFFD${Pc}${L}${N}${No}]*))|(\\s([\uFFFD${Lu}]+[.]){2,})?`, 'g'), // compound words and acronyms
|
|
21
21
|
titleCase: new RegExp(`^[${Lu}][${Ll}${N}${No}]+$`),
|
|
22
22
|
// private aint = XRegExp("^\\p{L}n't(?=$|[\\P{L}])") // isn't
|
|
23
23
|
// private word = XRegExp('^\\p{L}+([-.]\\p{L}+)*') // also match gallium-nitride as one word
|