@retorquere/bibtex-parser 5.2.5 → 6.1.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>' },
@@ -202,7 +203,7 @@ class Parser {
202
203
  smallCaps: { open: '<span style="font-variant:small-caps;">', close: '</span>' },
203
204
  caseProtect: { open: '<span class="nocase">', close: '</span>' },
204
205
  roman: { open: '', close: '' },
205
- fixedWidth: { open: '', close: '' },
206
+ fixedWidth: { open: '<tt>', close: '</tt>' },
206
207
  };
207
208
  // patch in because the options will likely not have enquote and case-protect
208
209
  for (const [markup, { open, close }] of Object.entries(markup_defaults)) {
@@ -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) {
@@ -1333,9 +1337,23 @@ class Parser {
1333
1337
  }
1334
1338
  }
1335
1339
  convert_environment(node) {
1336
- this.field.text += { enumerate: '<ol>', itemize: '<ul>' }[node.env];
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;
1337
1348
  this.convert_block(Object.assign(Object.assign({}, node), { kind: 'Block', markup: {} }));
1338
- this.field.text += { enumerate: '</ol>', itemize: '</ul>' }[node.env];
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>';
1339
1357
  }
1340
1358
  convert_block(node) {
1341
1359
  const start = this.field.text.length;
@@ -1419,6 +1437,6 @@ exports.promises = {
1419
1437
  return await parser.parseAsync(input);
1420
1438
  },
1421
1439
  };
1422
- exports.chunker = tslib_1.__importStar(require("./chunker"));
1423
- 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"));
1424
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.2.5",
3
+ "version": "6.1.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",
@@ -21,8 +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 && git add abbrv.jabref.org",
25
- "ncu": "ncu -u && npm i && git add package.json package-lock.json && git commit -m ncu"
24
+ "ncu": "./build/submodules.py && ncu -u && npm i && git add package.json package-lock.json && git commit -m ncu"
26
25
  },
27
26
  "repository": {
28
27
  "type": "git",
@@ -34,27 +33,27 @@
34
33
  "author": "Emiliano Heyns",
35
34
  "license": "ISC",
36
35
  "devDependencies": {
37
- "@types/node": "^16.7.1",
38
- "@typescript-eslint/eslint-plugin": "^4.29.2",
39
- "@typescript-eslint/parser": "^4.29.2",
36
+ "@types/node": "^16.11.12",
37
+ "@typescript-eslint/eslint-plugin": "^5.6.0",
38
+ "@typescript-eslint/parser": "^5.6.0",
40
39
  "command-line-args": "^5.2.0",
41
- "csv": "^5.5.0",
40
+ "csv": "^6.0.4",
42
41
  "digital-tree": "^2.0.3",
43
42
  "ejs": "^3.1.6",
44
- "eslint": "^7.32.0",
45
- "eslint-plugin-import": "^2.24.1",
43
+ "eslint": "^8.4.1",
44
+ "eslint-plugin-import": "^2.25.3",
46
45
  "eslint-plugin-prefer-arrow": "^1.2.3",
47
- "jest": "^27.0.6",
48
- "jest-cli": "^27.0.6",
46
+ "jest": "^27.4.4",
47
+ "jest-cli": "^27.4.4",
49
48
  "jest-specific-snapshot": "^5.0.0",
50
49
  "mkdirp": "^1.0.4",
51
- "node-fetch": "^2.6.1",
52
- "pegjs": "^0.10.0",
50
+ "node-fetch": "^3.1.0",
51
+ "peggy": "^1.2.0",
53
52
  "slug": "^5.1.0",
54
- "ts-node": "^10.2.1",
53
+ "ts-node": "^10.4.0",
55
54
  "tslib": "^2.3.1",
56
- "typedoc": "^0.21.6",
57
- "typescript": "^4.3.5"
55
+ "typedoc": "^0.22.10",
56
+ "typescript": "^4.5.3"
58
57
  },
59
58
  "dependencies": {
60
59
  "unicode2latex": "^2.1.36",