@retorquere/bibtex-parser 5.2.3 → 6.0.0
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/chunker.js +1 -0
- package/grammar.d.ts +2 -2
- package/grammar.js +1780 -2107
- package/index.d.ts +2 -1
- package/index.js +46 -21
- package/jabref.js +1 -1
- package/package.json +21 -22
- package/strings.bib +261 -261
package/index.d.ts
CHANGED
|
@@ -120,7 +120,7 @@ export interface Bibliography {
|
|
|
120
120
|
*/
|
|
121
121
|
entries: Entry[];
|
|
122
122
|
/**
|
|
123
|
-
* `@comment`s found in the bibtex file.
|
|
123
|
+
* `@comment`s found in the bibtex file.
|
|
124
124
|
*/
|
|
125
125
|
comments: string[];
|
|
126
126
|
/**
|
|
@@ -264,3 +264,4 @@ export declare const promises: {
|
|
|
264
264
|
parse(input: string, options?: ParserOptions): Promise<Bibliography>;
|
|
265
265
|
};
|
|
266
266
|
export * as chunker from './chunker';
|
|
267
|
+
export * as jabref from './jabref';
|
package/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.chunker = exports.promises = exports.ast = exports.parse = exports.fields = void 0;
|
|
3
|
+
exports.jabref = exports.chunker = exports.promises = exports.ast = exports.parse = exports.fields = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
|
|
6
|
-
const
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
6
|
+
const bibtex = (0, tslib_1.__importStar)(require("./grammar"));
|
|
7
|
+
const chunker = (0, tslib_1.__importStar)(require("./chunker"));
|
|
7
8
|
const jabref_1 = require("./jabref");
|
|
8
9
|
const unicode2latex_1 = require("unicode2latex");
|
|
9
|
-
const crossref_json_1 = tslib_1.__importDefault(require("./crossref.json"));
|
|
10
|
+
const crossref_json_1 = (0, tslib_1.__importDefault)(require("./crossref.json"));
|
|
10
11
|
class ParserError extends Error {
|
|
11
12
|
constructor(message, node) {
|
|
12
13
|
super(message); // 'Error' breaks prototype chain here
|
|
@@ -192,7 +193,7 @@ class Parser {
|
|
|
192
193
|
options.sentenceCase = false;
|
|
193
194
|
options.caseProtection = false;
|
|
194
195
|
}
|
|
195
|
-
this.options = Object.assign({ caseProtection: 'as-needed', verbatimFields: [/^citeulike-linkout-[0-9]+$/, ...exports.fields.verbatim], verbatimCommands: ['url'
|
|
196
|
+
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);
|
|
196
197
|
const markup_defaults = {
|
|
197
198
|
enquote: { open: '\u201c', close: '\u201d' },
|
|
198
199
|
sub: { open: '<sub>', close: '</sub>' },
|
|
@@ -325,7 +326,7 @@ class Parser {
|
|
|
325
326
|
}
|
|
326
327
|
}
|
|
327
328
|
}
|
|
328
|
-
const { comments, jabref } = jabref_1.parse(this.comments);
|
|
329
|
+
const { comments, jabref } = (0, jabref_1.parse)(this.comments);
|
|
329
330
|
return {
|
|
330
331
|
errors: this.errors,
|
|
331
332
|
entries: this.entries,
|
|
@@ -453,9 +454,7 @@ class Parser {
|
|
|
453
454
|
return (kind === 'none');
|
|
454
455
|
// expect 'n' text arguments
|
|
455
456
|
if (typeof kind === 'number') {
|
|
456
|
-
|
|
457
|
-
return false;
|
|
458
|
-
return node.arguments.required;
|
|
457
|
+
return node.arguments.required.length === kind ? node.arguments.required : false;
|
|
459
458
|
}
|
|
460
459
|
// return first argument if it's the only one
|
|
461
460
|
if (node.arguments.required.length !== 1)
|
|
@@ -463,9 +462,15 @@ class Parser {
|
|
|
463
462
|
// loose checking for text
|
|
464
463
|
if (kind === 'text') {
|
|
465
464
|
const first = node.arguments.required[0];
|
|
466
|
-
if (first.kind === 'Block'
|
|
467
|
-
|
|
468
|
-
|
|
465
|
+
if (first.kind === 'Block') {
|
|
466
|
+
switch (first.value.length) {
|
|
467
|
+
case 0:
|
|
468
|
+
return '';
|
|
469
|
+
case 1:
|
|
470
|
+
if (first.value[0].kind === 'Text')
|
|
471
|
+
return first.value[0].value;
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
469
474
|
}
|
|
470
475
|
// fall back to strict kind check
|
|
471
476
|
kind = 'Text';
|
|
@@ -843,21 +848,21 @@ class Parser {
|
|
|
843
848
|
case 'ocirc':
|
|
844
849
|
case 'mbox':
|
|
845
850
|
if (arg = this.argument(node, 'text')) {
|
|
851
|
+
if (node.command === 'mbox' && !arg)
|
|
852
|
+
return this.text('\u200b');
|
|
846
853
|
unicode = unicode2latex_1.latex[`\\${node.command}{${arg}}`];
|
|
847
854
|
return this.text(unicode || (node.command === 'hspace' ? ' ' : arg));
|
|
848
855
|
}
|
|
849
856
|
else if (!node.arguments.required.length) {
|
|
850
|
-
return this.text();
|
|
857
|
+
return (node.command === 'mbox') ? this.text('\u200b') : this.text();
|
|
851
858
|
}
|
|
852
859
|
else if (arg = this.argument(node, 'Block')) {
|
|
853
860
|
return this.clean(arg);
|
|
854
861
|
}
|
|
855
862
|
break;
|
|
856
|
-
// just take the URL? Not the label?
|
|
857
863
|
case 'href':
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
break;
|
|
864
|
+
node.arguments.required = node.arguments.required.map(a => this.clean(a));
|
|
865
|
+
return node;
|
|
861
866
|
case 'url':
|
|
862
867
|
if (arg = this.argument(node, 'Text'))
|
|
863
868
|
return this.text(arg);
|
|
@@ -1046,7 +1051,12 @@ class Parser {
|
|
|
1046
1051
|
case 'StringDeclaration':
|
|
1047
1052
|
break;
|
|
1048
1053
|
default:
|
|
1049
|
-
|
|
1054
|
+
if (node.kind === 'RegularCommand' && node.command === 'href') {
|
|
1055
|
+
this.convert_href(node);
|
|
1056
|
+
}
|
|
1057
|
+
else {
|
|
1058
|
+
return this.error(new ParserError(`no converter for ${node.kind}: ${this.show(node)}`, node));
|
|
1059
|
+
}
|
|
1050
1060
|
}
|
|
1051
1061
|
}
|
|
1052
1062
|
splitOnce(s, sep, fromEnd = false) {
|
|
@@ -1327,9 +1337,23 @@ class Parser {
|
|
|
1327
1337
|
}
|
|
1328
1338
|
}
|
|
1329
1339
|
convert_environment(node) {
|
|
1330
|
-
|
|
1340
|
+
const [open, close] = {
|
|
1341
|
+
enumerate: ['<ol>', '</ol>'],
|
|
1342
|
+
itemize: ['<ul>', '</ul>'],
|
|
1343
|
+
quotation: ['<blockquote>', '</blockquote>'],
|
|
1344
|
+
}[node.env] || ['', ''];
|
|
1345
|
+
if (!open)
|
|
1346
|
+
this.error(new TeXError(`Unhandled \\${node.env}{...}`, node, this.chunk));
|
|
1347
|
+
this.field.text += open;
|
|
1331
1348
|
this.convert_block(Object.assign(Object.assign({}, node), { kind: 'Block', markup: {} }));
|
|
1332
|
-
this.field.text +=
|
|
1349
|
+
this.field.text += close;
|
|
1350
|
+
}
|
|
1351
|
+
convert_href(node) {
|
|
1352
|
+
this.field.text += '<a href="';
|
|
1353
|
+
this.convert(node.arguments.required[0]);
|
|
1354
|
+
this.field.text += '">';
|
|
1355
|
+
this.convert(node.arguments.required[1]);
|
|
1356
|
+
this.field.text += '</a>';
|
|
1333
1357
|
}
|
|
1334
1358
|
convert_block(node) {
|
|
1335
1359
|
const start = this.field.text.length;
|
|
@@ -1413,5 +1437,6 @@ exports.promises = {
|
|
|
1413
1437
|
return await parser.parseAsync(input);
|
|
1414
1438
|
},
|
|
1415
1439
|
};
|
|
1416
|
-
exports.chunker = tslib_1.__importStar(require("./chunker"));
|
|
1440
|
+
exports.chunker = (0, tslib_1.__importStar)(require("./chunker"));
|
|
1441
|
+
exports.jabref = (0, tslib_1.__importStar)(require("./jabref"));
|
|
1417
1442
|
//# sourceMappingURL=index.js.map
|
package/jabref.js
CHANGED
|
@@ -53,7 +53,7 @@ function parse(comments) {
|
|
|
53
53
|
return true;
|
|
54
54
|
});
|
|
55
55
|
if (decoded.groupsversion)
|
|
56
|
-
result.groupsversion = parseInt(decoded.groupsversion[0].trim()) || decoded.groupsversion[0];
|
|
56
|
+
result.groupsversion = parseInt(decoded.groupsversion[0].trim()) || decoded.groupsversion[0]; // eslint-disable-line @typescript-eslint/no-unsafe-argument
|
|
57
57
|
if (decoded.fileDirectory)
|
|
58
58
|
result.fileDirectory = decoded.fileDirectory[0];
|
|
59
59
|
if (decoded.databaseType)
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@retorquere/bibtex-parser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "BibTeX parser",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"check-env": "node -e 'console.log(process.env)' | grep npm",
|
|
8
8
|
"lint": "eslint . --ext .ts --cache --cache-location .eslintcache/",
|
|
9
|
-
"prestart": "npm run lint &&
|
|
9
|
+
"prestart": "npm run lint && peggy grammar.peggy",
|
|
10
10
|
"start": "tsc -d",
|
|
11
11
|
"poststart": "npm run docs",
|
|
12
12
|
"pretest": "npm start",
|
|
13
13
|
"test": "node test/jest",
|
|
14
14
|
"presnap": "npm start",
|
|
15
15
|
"snap": "node test/jest --updateSnapshot",
|
|
16
|
-
"minitest": "
|
|
16
|
+
"minitest": "peggy grammar.peggy && tsc -d && node i.js",
|
|
17
17
|
"list": "tar tvf $(npm pack)",
|
|
18
18
|
"prepublishOnly": "npm start",
|
|
19
19
|
"abbr": "./build/abbr.py",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"postversion": "git push --follow-tags",
|
|
22
22
|
"update-cases": "curl -s https://raw.githubusercontent.com/retorquere/zotero-better-bibtex/master/test/loaded.json | jq -r '.[] | select(test(\"\\\\.bib((la)?tex)?$\"))' | rsync -av --delete -m --files-from=- ../better-bibtex/test/fixtures/ test/better-bibtex/",
|
|
23
23
|
"docs": "rm -rf docs && typedoc --name 'BibTeX parser' index.ts && touch docs/.nojekyll",
|
|
24
|
-
"prencu": "git submodule update --init --recursive --remote && git submodule foreach git reset --hard && git submodule foreach git checkout master && git submodule foreach git pull origin master",
|
|
24
|
+
"prencu": "git submodule update --init --recursive --remote && git submodule foreach git reset --hard && git submodule foreach git checkout master && git submodule foreach git pull origin master && git add abbrv.jabref.org",
|
|
25
25
|
"ncu": "ncu -u && npm i && git add package.json package-lock.json && git commit -m ncu"
|
|
26
26
|
},
|
|
27
27
|
"repository": {
|
|
@@ -34,32 +34,31 @@
|
|
|
34
34
|
"author": "Emiliano Heyns",
|
|
35
35
|
"license": "ISC",
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@types/node": "^16.
|
|
38
|
-
"@typescript-eslint/eslint-plugin": "^4.
|
|
39
|
-
"@typescript-eslint/parser": "^4.
|
|
40
|
-
"command-line-args": "^5.
|
|
41
|
-
"csv": "^
|
|
37
|
+
"@types/node": "^16.11.10",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^5.4.0",
|
|
39
|
+
"@typescript-eslint/parser": "^5.4.0",
|
|
40
|
+
"command-line-args": "^5.2.0",
|
|
41
|
+
"csv": "^6.0.4",
|
|
42
42
|
"digital-tree": "^2.0.3",
|
|
43
43
|
"ejs": "^3.1.6",
|
|
44
|
-
"eslint": "^
|
|
45
|
-
"eslint-plugin-import": "^2.
|
|
44
|
+
"eslint": "^8.3.0",
|
|
45
|
+
"eslint-plugin-import": "^2.25.3",
|
|
46
46
|
"eslint-plugin-prefer-arrow": "^1.2.3",
|
|
47
|
-
"jest": "^27.
|
|
48
|
-
"jest-cli": "^27.
|
|
47
|
+
"jest": "^27.3.1",
|
|
48
|
+
"jest-cli": "^27.3.1",
|
|
49
49
|
"jest-specific-snapshot": "^5.0.0",
|
|
50
|
-
"markdown": "^0.5.0",
|
|
51
50
|
"mkdirp": "^1.0.4",
|
|
52
|
-
"node-fetch": "^
|
|
53
|
-
"
|
|
51
|
+
"node-fetch": "^3.1.0",
|
|
52
|
+
"peggy": "^1.2.0",
|
|
54
53
|
"slug": "^5.1.0",
|
|
55
|
-
"ts-node": "^10.
|
|
56
|
-
"tslib": "^2.3.
|
|
57
|
-
"typedoc": "^0.
|
|
58
|
-
"typescript": "^4.
|
|
54
|
+
"ts-node": "^10.4.0",
|
|
55
|
+
"tslib": "^2.3.1",
|
|
56
|
+
"typedoc": "^0.22.9",
|
|
57
|
+
"typescript": "^4.5.2"
|
|
59
58
|
},
|
|
60
59
|
"dependencies": {
|
|
61
|
-
"unicode2latex": "^2.1.
|
|
62
|
-
"xregexp": "^5.0
|
|
60
|
+
"unicode2latex": "^2.1.36",
|
|
61
|
+
"xregexp": "^5.1.0"
|
|
63
62
|
},
|
|
64
63
|
"files": [
|
|
65
64
|
"package.json",
|