jats-cli 1.0.14 → 1.0.16

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.14";
49002
+ var version = "1.0.16";
49003
49003
  var version_default = version;
49004
49004
 
49005
49005
  // src/parse.ts
@@ -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
 
@@ -58217,6 +58236,20 @@ async function jatsFetch(session, input, opts) {
58217
58236
  output = foldername;
58218
58237
  }
58219
58238
  }
58239
+ if (input.match(/^[0-9]+$/)) {
58240
+ const pmcid = await convertPMID2PMCID(session, input);
58241
+ if (pmcid) {
58242
+ session.log.debug(`Resolved input ${input} to PMC ID: ${pmcid}`);
58243
+ input = pmcid;
58244
+ }
58245
+ }
58246
+ if (doi.validate(input)) {
58247
+ const pmcid = await convertDOI2PMCID(session, input);
58248
+ if (pmcid) {
58249
+ session.log.debug(`Resolved input ${input} to PMC ID: ${pmcid}`);
58250
+ input = pmcid;
58251
+ }
58252
+ }
58220
58253
  if (!output)
58221
58254
  output = opts.data ? `${input}` : ".";
58222
58255
  if (!import_node_path4.default.extname(output)) {
@@ -58590,15 +58623,16 @@ var Jats = class {
58590
58623
  }
58591
58624
  const { declaration, elements } = this.raw;
58592
58625
  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") {
58626
+ const filteredElements = elements === null || elements === void 0 ? void 0 : elements.filter((elem) => elem.type !== "comment");
58627
+ if ((filteredElements === null || filteredElements === void 0 ? void 0 : filteredElements.length) && filteredElements[0].type !== "doctype") {
58594
58628
  (_a = this.log) === null || _a === void 0 ? void 0 : _a.warn("JATS is missing DOCTYPE declaration");
58595
- elements.unshift({ type: "doctype" });
58629
+ filteredElements.unshift({ type: "doctype" });
58596
58630
  }
58597
- if (!((elements === null || elements === void 0 ? void 0 : elements.length) === 2 && elements[0].type === "doctype" && hasSingleArticle(elements[1]))) {
58631
+ if (!((filteredElements === null || filteredElements === void 0 ? void 0 : filteredElements.length) === 2 && filteredElements[0].type === "doctype" && hasSingleArticle(filteredElements[1]))) {
58598
58632
  throw new Error("JATS must be structured as <!DOCTYPE><article>...</article>");
58599
58633
  }
58600
- this.doctype = elements[0].doctype;
58601
- const converted = convertToUnist(elements[1]);
58634
+ this.doctype = filteredElements[0].doctype;
58635
+ const converted = convertToUnist(filteredElements[1]);
58602
58636
  this.tree = select2("article", converted);
58603
58637
  (_b = this.log) === null || _b === void 0 ? void 0 : _b.debug(toc("Parsed and converted JATS to unist tree in %s"));
58604
58638
  }
@@ -64835,7 +64869,10 @@ function admonitionTransform(tree, file) {
64835
64869
  captions.forEach((caption) => {
64836
64870
  const title = select3(Tags.title, caption);
64837
64871
  if (!title) {
64838
- fileWarn(file, "", { node: caption, ruleId: RuleId.jatsParses });
64872
+ fileWarn(file, "Encountered boxed-text without title", {
64873
+ node: caption,
64874
+ ruleId: RuleId.jatsParses
64875
+ });
64839
64876
  return;
64840
64877
  }
64841
64878
  caption.type = "admonitionTitle";
@@ -64890,19 +64927,19 @@ function isBioRxiv(tree) {
64890
64927
  const journalId = select3("journal-id[journal-id-type=hwp]", tree);
64891
64928
  return toText2(journalId) === "biorxiv";
64892
64929
  }
64893
- function graphicToBioRxivUrl(tree) {
64894
- if (!isBioRxiv(tree))
64930
+ function graphicToBioRxivUrl(fullTree, body) {
64931
+ if (!isBioRxiv(fullTree))
64895
64932
  return;
64896
64933
  console.log("inside graphics transform");
64897
- const accepted = select3("date[date-type=accepted]", tree);
64934
+ const accepted = select3("date[date-type=accepted]", fullTree);
64898
64935
  if (!accepted)
64899
64936
  return;
64900
64937
  const year = toText2(select3("year", accepted));
64901
64938
  const month = toText2(select3("month", accepted)).padStart(2, "0");
64902
64939
  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("/");
64940
+ const slug = toText2(select3("article-id[pub-id-type=doi]", fullTree)).split("/").slice(1).join("/");
64904
64941
  const urlBase = `https://www.biorxiv.org/content/biorxiv/early/${year}/${month}/${day}/${slug}`;
64905
- selectAll2("fig,table-wrap", tree).forEach((node) => {
64942
+ selectAll2("fig,table-wrap", body).forEach((node) => {
64906
64943
  const figId = node["hwp:id"];
64907
64944
  if (!figId)
64908
64945
  return;
@@ -65568,12 +65605,12 @@ function basicTransformations(body, file) {
65568
65605
  admonitionTransform(body, file);
65569
65606
  figCaptionTitleTransform(body);
65570
65607
  }
65571
- function journalTransforms(body) {
65572
- graphicToBioRxivUrl(body);
65608
+ function journalTransforms(fullTree, body) {
65609
+ graphicToBioRxivUrl(fullTree, body);
65573
65610
  }
65574
65611
 
65575
65612
  // ../jats-convert/dist/version.js
65576
- var version3 = "1.0.14";
65613
+ var version3 = "1.0.16";
65577
65614
  var version_default3 = version3;
65578
65615
 
65579
65616
  // ../jats-convert/dist/myst/inlineCitations.js
@@ -65863,6 +65900,20 @@ function abbreviationsFromText(text) {
65863
65900
  }
65864
65901
 
65865
65902
  // ../jats-convert/dist/index.js
65903
+ var MEDIA_FIGURE_EXTENSIONS = [
65904
+ ".png",
65905
+ ".jpg",
65906
+ ".jpeg",
65907
+ ".svg",
65908
+ ".gif",
65909
+ ".tiff",
65910
+ ".tif",
65911
+ ".eps",
65912
+ ".webp",
65913
+ ".mp4",
65914
+ ".mov",
65915
+ ".avi"
65916
+ ];
65866
65917
  function refTypeToReferenceKind(kind) {
65867
65918
  switch (kind) {
65868
65919
  case RefType.sec:
@@ -66042,7 +66093,7 @@ var handlers = {
66042
66093
  const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
66043
66094
  state2.openNode("div", { label, identifier });
66044
66095
  }
66045
- state2.renderInline(node, "admonition", { kind: "info" });
66096
+ state2.renderInline(node, "admonition", { kind: "note" });
66046
66097
  if (node.id) {
66047
66098
  state2.closeNode();
66048
66099
  }
@@ -66086,7 +66137,7 @@ var handlers = {
66086
66137
  fig(node, state2) {
66087
66138
  var _a;
66088
66139
  const caption = select3("caption", node);
66089
- const graphic = select3("graphic", node);
66140
+ const graphic = select3("graphic,media", node);
66090
66141
  const title = select3("title", node);
66091
66142
  const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
66092
66143
  state2.openNode("container", { label, identifier, kind: "figure" });
@@ -66216,6 +66267,7 @@ var handlers = {
66216
66267
  kind: "narrative"
66217
66268
  });
66218
66269
  return;
66270
+ case RefType.video:
66219
66271
  case RefType.app:
66220
66272
  case RefType.boxedText:
66221
66273
  case RefType.media:
@@ -66241,14 +66293,49 @@ var handlers = {
66241
66293
  }
66242
66294
  },
66243
66295
  ["supplementary-material"](node, state2) {
66244
- var _a;
66245
- if (node.id) {
66246
- const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
66247
- state2.openNode("div", { label, identifier });
66248
- }
66249
- state2.renderChildren(node);
66250
- if (node.id) {
66296
+ var _a, _b, _c, _d, _e;
66297
+ const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
66298
+ let maybeCaption;
66299
+ let media;
66300
+ if (((_b = node.children) === null || _b === void 0 ? void 0 : _b.length) === 1 && node.children[0].type === "media") {
66301
+ media = node.children[0];
66302
+ } else if (((_c = node.children) === null || _c === void 0 ? void 0 : _c.length) === 2 && node.children[0].type === "label" && node.children[1].type === "media") {
66303
+ maybeCaption = node.children[0];
66304
+ media = node.children[1];
66305
+ }
66306
+ const url = media === null || media === void 0 ? void 0 : media["xlink:href"];
66307
+ let caption = (_d = select3("caption", media)) !== null && _d !== void 0 ? _d : maybeCaption;
66308
+ if (((_e = caption === null || caption === void 0 ? void 0 : caption.children) === null || _e === void 0 ? void 0 : _e.length) === 1 && caption.children[0].type === "p") {
66309
+ caption = caption.children[0];
66310
+ }
66311
+ if (url && MEDIA_FIGURE_EXTENSIONS.find((ext) => url.endsWith(ext))) {
66312
+ const title = select3("title", media);
66313
+ state2.openNode("container", { label, identifier, kind: "figure" });
66314
+ const wasInContainer = state2.data.isInContainer;
66315
+ state2.data.isInContainer = true;
66316
+ state2.addLeaf("image", { url });
66317
+ state2.openNode("caption");
66318
+ state2.openNode("link", { url });
66319
+ if (title) {
66320
+ state2.openNode("strong");
66321
+ state2.renderChildren(title);
66322
+ state2.closeNode();
66323
+ }
66324
+ if (caption) {
66325
+ state2.renderChildren(caption);
66326
+ }
66327
+ state2.closeNode();
66328
+ state2.closeNode();
66251
66329
  state2.closeNode();
66330
+ state2.data.isInContainer = wasInContainer;
66331
+ } else {
66332
+ if (node.id) {
66333
+ state2.openNode("div", { label, identifier });
66334
+ }
66335
+ state2.renderChildren(node);
66336
+ if (node.id) {
66337
+ state2.closeNode();
66338
+ }
66252
66339
  }
66253
66340
  },
66254
66341
  ["app-group"](node, state2) {
@@ -66398,7 +66485,7 @@ var jatsConvertPlugin = function(jats, opts) {
66398
66485
  dataAvailabilityTransform(body);
66399
66486
  const refLookup = processJatsReferences(body, jats.references, opts);
66400
66487
  basicTransformations(body, file);
66401
- journalTransforms(body);
66488
+ journalTransforms(jats.tree, body);
66402
66489
  const state2 = new JatsParser(file, jats, opts);
66403
66490
  state2.renderChildren(body);
66404
66491
  while (state2.stack.length > 1)
package/dist/version.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- declare const version = "1.0.14";
1
+ declare const version = "1.0.16";
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.14';
1
+ const version = '1.0.16';
2
2
  export default version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jats-cli",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
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",
@@ -45,11 +45,11 @@
45
45
  "dependencies": {
46
46
  "doi-utils": "^2.0.0",
47
47
  "fair-principles": "^2.0.0",
48
- "jats-convert": "^1.0.14",
49
- "jats-fetch": "^1.0.14",
50
- "jats-tags": "^1.0.14",
51
- "jats-utils": "^1.0.14",
52
- "jats-xml": "^1.0.14",
48
+ "jats-convert": "^1.0.16",
49
+ "jats-fetch": "^1.0.16",
50
+ "jats-tags": "^1.0.16",
51
+ "jats-utils": "^1.0.16",
52
+ "jats-xml": "^1.0.16",
53
53
  "js-yaml": "^4.1.0",
54
54
  "unist-util-is": "^5.2.1",
55
55
  "unist-util-select": "^4.0.0"