@retorquere/bibtex-parser 5.3.0 → 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/index.js CHANGED
@@ -2,11 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.jabref = exports.chunker = exports.promises = exports.ast = exports.parse = exports.fields = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const bibtex = tslib_1.__importStar(require("./grammar"));
6
- const chunker = tslib_1.__importStar(require("./chunker"));
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', 'href'], 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
+ 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,
@@ -859,11 +860,9 @@ class Parser {
859
860
  return this.clean(arg);
860
861
  }
861
862
  break;
862
- // just take the URL? Not the label?
863
863
  case 'href':
864
- if (arg = this.argument(node, 2))
865
- return this.clean(arg[0]);
866
- break;
864
+ node.arguments.required = node.arguments.required.map(a => this.clean(a));
865
+ return node;
867
866
  case 'url':
868
867
  if (arg = this.argument(node, 'Text'))
869
868
  return this.text(arg);
@@ -1052,7 +1051,12 @@ class Parser {
1052
1051
  case 'StringDeclaration':
1053
1052
  break;
1054
1053
  default:
1055
- return this.error(new ParserError(`no converter for ${node.kind}: ${this.show(node)}`, node));
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
+ }
1056
1060
  }
1057
1061
  }
1058
1062
  splitOnce(s, sep, fromEnd = false) {
@@ -1344,6 +1348,13 @@ class Parser {
1344
1348
  this.convert_block(Object.assign(Object.assign({}, node), { kind: 'Block', markup: {} }));
1345
1349
  this.field.text += close;
1346
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>';
1357
+ }
1347
1358
  convert_block(node) {
1348
1359
  const start = this.field.text.length;
1349
1360
  let prefix = '';
@@ -1426,6 +1437,6 @@ exports.promises = {
1426
1437
  return await parser.parseAsync(input);
1427
1438
  },
1428
1439
  };
1429
- exports.chunker = tslib_1.__importStar(require("./chunker"));
1430
- exports.jabref = tslib_1.__importStar(require("./jabref"));
1440
+ exports.chunker = (0, tslib_1.__importStar)(require("./chunker"));
1441
+ exports.jabref = (0, tslib_1.__importStar)(require("./jabref"));
1431
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": "5.3.0",
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 && pegjs grammar.pegjs",
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": "pegjs grammar.pegjs && tsc -d && node i.js",
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",
@@ -34,27 +34,27 @@
34
34
  "author": "Emiliano Heyns",
35
35
  "license": "ISC",
36
36
  "devDependencies": {
37
- "@types/node": "^16.7.1",
38
- "@typescript-eslint/eslint-plugin": "^4.29.2",
39
- "@typescript-eslint/parser": "^4.29.2",
37
+ "@types/node": "^16.11.10",
38
+ "@typescript-eslint/eslint-plugin": "^5.4.0",
39
+ "@typescript-eslint/parser": "^5.4.0",
40
40
  "command-line-args": "^5.2.0",
41
- "csv": "^5.5.0",
41
+ "csv": "^6.0.4",
42
42
  "digital-tree": "^2.0.3",
43
43
  "ejs": "^3.1.6",
44
- "eslint": "^7.32.0",
45
- "eslint-plugin-import": "^2.24.1",
44
+ "eslint": "^8.3.0",
45
+ "eslint-plugin-import": "^2.25.3",
46
46
  "eslint-plugin-prefer-arrow": "^1.2.3",
47
- "jest": "^27.0.6",
48
- "jest-cli": "^27.0.6",
47
+ "jest": "^27.3.1",
48
+ "jest-cli": "^27.3.1",
49
49
  "jest-specific-snapshot": "^5.0.0",
50
50
  "mkdirp": "^1.0.4",
51
- "node-fetch": "^2.6.1",
52
- "pegjs": "^0.10.0",
51
+ "node-fetch": "^3.1.0",
52
+ "peggy": "^1.2.0",
53
53
  "slug": "^5.1.0",
54
- "ts-node": "^10.2.1",
54
+ "ts-node": "^10.4.0",
55
55
  "tslib": "^2.3.1",
56
- "typedoc": "^0.21.6",
57
- "typescript": "^4.3.5"
56
+ "typedoc": "^0.22.9",
57
+ "typescript": "^4.5.2"
58
58
  },
59
59
  "dependencies": {
60
60
  "unicode2latex": "^2.1.36",