jats-cli 1.0.15 → 1.0.17

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/dist/jats.cjs CHANGED
@@ -48999,7 +48999,7 @@ var {
48999
48999
  } = import_index.default;
49000
49000
 
49001
49001
  // src/version.ts
49002
- var version = "1.0.15";
49002
+ var version = "1.0.17";
49003
49003
  var version_default = version;
49004
49004
 
49005
49005
  // src/parse.ts
@@ -49645,7 +49645,7 @@ function writeFileToFolder(filename, data, opts) {
49645
49645
  }
49646
49646
 
49647
49647
  // ../../node_modules/doi-utils/dist/validatePart.js
49648
- var DOI_VALIDATION_PATTERN = /^10.\d{4,9}\/[-._;()/:A-Z0-9]+$/i;
49648
+ var DOI_VALIDATION_PATTERN = /^10\.\d{4,9}\/[-._;()/:A-Z0-9]+$/i;
49649
49649
  function validatePart(possibleDOI) {
49650
49650
  if (!possibleDOI)
49651
49651
  return false;
@@ -49663,10 +49663,10 @@ var doiOrg = {
49663
49663
  };
49664
49664
  var elife = {
49665
49665
  test(url) {
49666
- return url.hostname.endsWith("elifesciences.org") && url.pathname.startsWith("/articles/");
49666
+ return url.hostname.endsWith("elifesciences.org") && /^\/(?:articles|reviewed-preprints)\/\d+$/.test(url.pathname);
49667
49667
  },
49668
49668
  parse(url) {
49669
- return `10.7554/eLife.${url.pathname.replace("/articles/", "")}`;
49669
+ return `10.7554/eLife.${url.pathname.replace(/^\/(?:articles|reviewed-preprints)\//, "")}`;
49670
49670
  }
49671
49671
  };
49672
49672
  var zenodo = {
@@ -49683,7 +49683,7 @@ var biorxiv = {
49683
49683
  },
49684
49684
  parse(url) {
49685
49685
  var _a;
49686
- return (_a = clumpParts(url).find(validatePart)) === null || _a === void 0 ? void 0 : _a.replace(/v([\d]*)$/, "");
49686
+ return (_a = clumpParts(url).find(validatePart)) === null || _a === void 0 ? void 0 : _a.replace(/v\d+(\.[a-zA-Z-]+)?$/, "");
49687
49687
  }
49688
49688
  };
49689
49689
  function clumpParts(url) {
@@ -56426,6 +56426,7 @@ var RefType;
56426
56426
  RefType2["tableFn"] = "table-fn";
56427
56427
  RefType2["ref"] = "ref";
56428
56428
  RefType2["media"] = "media";
56429
+ RefType2["video"] = "video";
56429
56430
  })(RefType || (RefType = {}));
56430
56431
 
56431
56432
  // ../jats-fetch/dist/download.js
@@ -57848,6 +57849,10 @@ async function convertPMID2PMCID(session, pmid, opts) {
57848
57849
  const pmcid = await convertId(session, pmid, "pmid", "pmcid", opts);
57849
57850
  return pmcid;
57850
57851
  }
57852
+ async function convertDOI2PMCID(session, input, opts) {
57853
+ const pmDoi = await convertId(session, input, "doi", "pmcid", opts);
57854
+ return pmDoi;
57855
+ }
57851
57856
  async function convertPMIDs2DOIs(session, pmids, opts) {
57852
57857
  var _a, _b, _c;
57853
57858
  pmids = [...new Set(pmids.map((pmid) => normalizePMID(session, pmid)))];
@@ -58088,8 +58093,21 @@ var joss = {
58088
58093
  return `https://raw.githubusercontent.com/openjournals/joss-papers/master/joss.${id}/${org}.${jossId}.jats`;
58089
58094
  }
58090
58095
  };
58091
- var DEFAULT_RESOLVERS2 = [elife2, plos, joss];
58092
- async function customResolveJatsUrlFromDoi(session, doiString, opts = { resolvers: DEFAULT_RESOLVERS2 }) {
58096
+ var biorxiv2 = {
58097
+ test(url) {
58098
+ return new URL(url).hostname === "www.biorxiv.org";
58099
+ },
58100
+ async jatsUrl(url, fetcher) {
58101
+ const resp = await (fetcher !== null && fetcher !== void 0 ? fetcher : fetch2)(url);
58102
+ const xmlUrl = (await resp.text()).match(/https:\/\/www\.biorxiv\.org\/content\/biorxiv\/[^\s]+\.full\.pdf/);
58103
+ if (!xmlUrl) {
58104
+ throw new Error(`Could not resolve JATS for biorxiv URL: ${url}`);
58105
+ }
58106
+ return xmlUrl[0].replace(".full.pdf", ".source.xml");
58107
+ }
58108
+ };
58109
+ var DEFAULT_RESOLVERS2 = [biorxiv2, elife2, plos, joss];
58110
+ async function customResolveJatsUrlFromDoi(session, doiString, opts) {
58093
58111
  var _a, _b;
58094
58112
  if (!doi.validate(doiString))
58095
58113
  throw new Error(`The doi ${doiString} is not valid`);
@@ -58098,10 +58116,11 @@ async function customResolveJatsUrlFromDoi(session, doiString, opts = { resolver
58098
58116
  const resp = await ((_a = opts === null || opts === void 0 ? void 0 : opts.fetcher) !== null && _a !== void 0 ? _a : fetch2)(doiUrl);
58099
58117
  const articleUrl = resp.url;
58100
58118
  session.log.debug(`Found resolved URL for DOI at ${articleUrl}`);
58101
- const resolver = (_b = opts === null || opts === void 0 ? void 0 : opts.resolvers) === null || _b === void 0 ? void 0 : _b.find((r2) => r2.test(articleUrl));
58119
+ const resolvers = (_b = opts === null || opts === void 0 ? void 0 : opts.resolvers) !== null && _b !== void 0 ? _b : DEFAULT_RESOLVERS2;
58120
+ const resolver = resolvers === null || resolvers === void 0 ? void 0 : resolvers.find((r2) => r2.test(articleUrl));
58102
58121
  if (!resolver)
58103
58122
  throw new Error(`Could not resolve JATS for ${articleUrl}, no resolver matched`);
58104
- const jatsUrl = resolver.jatsUrl(articleUrl);
58123
+ const jatsUrl = await resolver.jatsUrl(articleUrl, opts === null || opts === void 0 ? void 0 : opts.fetcher);
58105
58124
  return jatsUrl;
58106
58125
  }
58107
58126
 
@@ -58159,10 +58178,19 @@ async function downloadJatsFromUrl(session, urlOrDoi, opts = {}) {
58159
58178
  const data = import_node_fs5.default.readFileSync(urlOrDoi).toString();
58160
58179
  return { success: true, source: urlOrDoi, data };
58161
58180
  }
58162
- const expectedUrls = (await Promise.all([
58181
+ const expectedUrls = [];
58182
+ try {
58183
+ expectedUrls.push(await customResolveJatsUrlFromDoi(session, urlOrDoi, opts));
58184
+ } catch {
58185
+ session.log.debug(`No custom resolvers match ${urlOrDoi}`);
58186
+ }
58187
+ expectedUrls.push(...(await Promise.all([
58163
58188
  constructJatsUrlFromPubMedCentral(session, urlOrDoi, opts),
58164
58189
  getJatsUrlFromDoi(session, urlOrDoi, opts)
58165
- ])).filter((u2) => !!u2);
58190
+ ])).filter((u2) => !!u2));
58191
+ if (isUrl(urlOrDoi)) {
58192
+ expectedUrls.push(urlOrDoi);
58193
+ }
58166
58194
  if (expectedUrls.length > 0) {
58167
58195
  session.log.debug(["Trying URLs:\n", ...expectedUrls.map((url) => ` ${url}
58168
58196
  `)].join(" - "));
@@ -58178,22 +58206,7 @@ async function downloadJatsFromUrl(session, urlOrDoi, opts = {}) {
58178
58206
  }
58179
58207
  return { success: false, source: expectedUrls[0] };
58180
58208
  }
58181
- try {
58182
- if (doi.validate(urlOrDoi)) {
58183
- const jatsUrl = await customResolveJatsUrlFromDoi(session, urlOrDoi, opts);
58184
- const data = await downloadFromUrl(session, jatsUrl, opts);
58185
- return { success: true, source: jatsUrl, data };
58186
- }
58187
- if (isUrl(urlOrDoi)) {
58188
- session.log.debug("No resolver matched, and the URL doesn't look like a DOI. We will attempt to download it directly.");
58189
- const data = await downloadFromUrl(session, urlOrDoi, opts);
58190
- return { success: true, source: urlOrDoi, data };
58191
- }
58192
- } catch (error) {
58193
- session.log.debug(error.message);
58194
- return { success: false, source: urlOrDoi };
58195
- }
58196
- session.log.debug(`Could not find ${urlOrDoi} locally, and it doesn't look like a URL or DOI`);
58209
+ session.log.debug(`Could not find ${urlOrDoi} locally or resolve it to a valid JATS url`);
58197
58210
  return { success: false, source: urlOrDoi };
58198
58211
  }
58199
58212
  async function jatsFetch(session, input, opts) {
@@ -58217,6 +58230,20 @@ async function jatsFetch(session, input, opts) {
58217
58230
  output = foldername;
58218
58231
  }
58219
58232
  }
58233
+ if (input.match(/^[0-9]+$/)) {
58234
+ const pmcid = await convertPMID2PMCID(session, input);
58235
+ if (pmcid) {
58236
+ session.log.debug(`Resolved input ${input} to PMC ID: ${pmcid}`);
58237
+ input = pmcid;
58238
+ }
58239
+ }
58240
+ if (doi.validate(input)) {
58241
+ const pmcid = await convertDOI2PMCID(session, input);
58242
+ if (pmcid) {
58243
+ session.log.debug(`Resolved input ${input} to PMC ID: ${pmcid}`);
58244
+ input = pmcid;
58245
+ }
58246
+ }
58220
58247
  if (!output)
58221
58248
  output = opts.data ? `${input}` : ".";
58222
58249
  if (!import_node_path4.default.extname(output)) {
@@ -58590,15 +58617,16 @@ var Jats = class {
58590
58617
  }
58591
58618
  const { declaration, elements } = this.raw;
58592
58619
  this.declaration = declaration === null || declaration === void 0 ? void 0 : declaration.attributes;
58593
- if ((elements === null || elements === void 0 ? void 0 : elements.length) && elements[0].type !== "doctype") {
58620
+ const filteredElements = elements === null || elements === void 0 ? void 0 : elements.filter((elem) => elem.type !== "comment");
58621
+ if ((filteredElements === null || filteredElements === void 0 ? void 0 : filteredElements.length) && filteredElements[0].type !== "doctype") {
58594
58622
  (_a = this.log) === null || _a === void 0 ? void 0 : _a.warn("JATS is missing DOCTYPE declaration");
58595
- elements.unshift({ type: "doctype" });
58623
+ filteredElements.unshift({ type: "doctype" });
58596
58624
  }
58597
- if (!((elements === null || elements === void 0 ? void 0 : elements.length) === 2 && elements[0].type === "doctype" && hasSingleArticle(elements[1]))) {
58625
+ if (!((filteredElements === null || filteredElements === void 0 ? void 0 : filteredElements.length) === 2 && filteredElements[0].type === "doctype" && hasSingleArticle(filteredElements[1]))) {
58598
58626
  throw new Error("JATS must be structured as <!DOCTYPE><article>...</article>");
58599
58627
  }
58600
- this.doctype = elements[0].doctype;
58601
- const converted = convertToUnist(elements[1]);
58628
+ this.doctype = filteredElements[0].doctype;
58629
+ const converted = convertToUnist(filteredElements[1]);
58602
58630
  this.tree = select2("article", converted);
58603
58631
  (_b = this.log) === null || _b === void 0 ? void 0 : _b.debug(toc("Parsed and converted JATS to unist tree in %s"));
58604
58632
  }
@@ -64835,7 +64863,10 @@ function admonitionTransform(tree, file) {
64835
64863
  captions.forEach((caption) => {
64836
64864
  const title = select3(Tags.title, caption);
64837
64865
  if (!title) {
64838
- fileWarn(file, "", { node: caption, ruleId: RuleId.jatsParses });
64866
+ fileWarn(file, "Encountered boxed-text without title", {
64867
+ node: caption,
64868
+ ruleId: RuleId.jatsParses
64869
+ });
64839
64870
  return;
64840
64871
  }
64841
64872
  caption.type = "admonitionTitle";
@@ -64890,19 +64921,19 @@ function isBioRxiv(tree) {
64890
64921
  const journalId = select3("journal-id[journal-id-type=hwp]", tree);
64891
64922
  return toText2(journalId) === "biorxiv";
64892
64923
  }
64893
- function graphicToBioRxivUrl(tree) {
64894
- if (!isBioRxiv(tree))
64924
+ function graphicToBioRxivUrl(fullTree, body) {
64925
+ if (!isBioRxiv(fullTree))
64895
64926
  return;
64896
64927
  console.log("inside graphics transform");
64897
- const accepted = select3("date[date-type=accepted]", tree);
64928
+ const accepted = select3("date[date-type=accepted]", fullTree);
64898
64929
  if (!accepted)
64899
64930
  return;
64900
64931
  const year = toText2(select3("year", accepted));
64901
64932
  const month = toText2(select3("month", accepted)).padStart(2, "0");
64902
64933
  const day = toText2(select3("day", accepted)).padStart(2, "0");
64903
- const slug = toText2(select3("article-id[pub-id-type=doi]", tree)).split("/").slice(1).join("/");
64934
+ const slug = toText2(select3("article-id[pub-id-type=doi]", fullTree)).split("/").slice(1).join("/");
64904
64935
  const urlBase = `https://www.biorxiv.org/content/biorxiv/early/${year}/${month}/${day}/${slug}`;
64905
- selectAll2("fig,table-wrap", tree).forEach((node) => {
64936
+ selectAll2("fig,table-wrap", body).forEach((node) => {
64906
64937
  const figId = node["hwp:id"];
64907
64938
  if (!figId)
64908
64939
  return;
@@ -65568,12 +65599,12 @@ function basicTransformations(body, file) {
65568
65599
  admonitionTransform(body, file);
65569
65600
  figCaptionTitleTransform(body);
65570
65601
  }
65571
- function journalTransforms(body) {
65572
- graphicToBioRxivUrl(body);
65602
+ function journalTransforms(fullTree, body) {
65603
+ graphicToBioRxivUrl(fullTree, body);
65573
65604
  }
65574
65605
 
65575
65606
  // ../jats-convert/dist/version.js
65576
- var version3 = "1.0.15";
65607
+ var version3 = "1.0.17";
65577
65608
  var version_default3 = version3;
65578
65609
 
65579
65610
  // ../jats-convert/dist/myst/inlineCitations.js
@@ -66056,7 +66087,7 @@ var handlers = {
66056
66087
  const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
66057
66088
  state2.openNode("div", { label, identifier });
66058
66089
  }
66059
- state2.renderInline(node, "admonition", { kind: "info" });
66090
+ state2.renderInline(node, "admonition", { kind: "note" });
66060
66091
  if (node.id) {
66061
66092
  state2.closeNode();
66062
66093
  }
@@ -66100,7 +66131,7 @@ var handlers = {
66100
66131
  fig(node, state2) {
66101
66132
  var _a;
66102
66133
  const caption = select3("caption", node);
66103
- const graphic = select3("graphic", node);
66134
+ const graphic = select3("graphic,media", node);
66104
66135
  const title = select3("title", node);
66105
66136
  const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
66106
66137
  state2.openNode("container", { label, identifier, kind: "figure" });
@@ -66230,6 +66261,7 @@ var handlers = {
66230
66261
  kind: "narrative"
66231
66262
  });
66232
66263
  return;
66264
+ case RefType.video:
66233
66265
  case RefType.app:
66234
66266
  case RefType.boxedText:
66235
66267
  case RefType.media:
@@ -66447,7 +66479,7 @@ var jatsConvertPlugin = function(jats, opts) {
66447
66479
  dataAvailabilityTransform(body);
66448
66480
  const refLookup = processJatsReferences(body, jats.references, opts);
66449
66481
  basicTransformations(body, file);
66450
- journalTransforms(body);
66482
+ journalTransforms(jats.tree, body);
66451
66483
  const state2 = new JatsParser(file, jats, opts);
66452
66484
  state2.renderChildren(body);
66453
66485
  while (state2.stack.length > 1)
package/dist/version.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- declare const version = "1.0.15";
1
+ declare const version = "1.0.17";
2
2
  export default version;
3
3
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
- const version = '1.0.15';
1
+ const version = '1.0.17';
2
2
  export default version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jats-cli",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "Typescript CLI for with JATS",
5
5
  "author": "Rowan Cockett <rowan@continuous.foundation>",
6
6
  "homepage": "https://github.com/continuous-foundation/jats",
@@ -43,13 +43,13 @@
43
43
  "url": "https://github.com/continuous-foundation/jats/issues"
44
44
  },
45
45
  "dependencies": {
46
- "doi-utils": "^2.0.0",
46
+ "doi-utils": "^2.0.6",
47
47
  "fair-principles": "^2.0.0",
48
- "jats-convert": "^1.0.15",
49
- "jats-fetch": "^1.0.15",
50
- "jats-tags": "^1.0.15",
51
- "jats-utils": "^1.0.15",
52
- "jats-xml": "^1.0.15",
48
+ "jats-convert": "^1.0.17",
49
+ "jats-fetch": "^1.0.17",
50
+ "jats-tags": "^1.0.17",
51
+ "jats-utils": "^1.0.17",
52
+ "jats-xml": "^1.0.17",
53
53
  "js-yaml": "^4.1.0",
54
54
  "unist-util-is": "^5.2.1",
55
55
  "unist-util-select": "^4.0.0"