jats-cli 1.0.13 → 1.0.15

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/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # jats-cli
2
2
 
3
3
  [![jats-cli on npm](https://img.shields.io/npm/v/jats-cli.svg)](https://www.npmjs.com/package/jats-cli)
4
- [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/curvenote/jats/blob/main/LICENSE)
5
- [![CI](https://github.com/curvenote/jats/workflows/CI/badge.svg)](https://github.com/curvenote/jats-cli/actions)
4
+ [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/continuous-foundation/jats/blob/main/LICENSE)
5
+ [![CI](https://github.com/continuous-foundation/jats/workflows/CI/badge.svg)](https://github.com/continuous-foundation/jats-cli/actions)
6
6
 
7
7
  Node CLI for working with JATS XML documents.
8
8
 
@@ -93,7 +93,7 @@ As of v1.0.0 this package is [ESM only](https://gist.github.com/sindresorhus/a39
93
93
 
94
94
  <p style="text-align: center; color: #aaa; padding-top: 50px">
95
95
  Made with love by
96
- <a href="https://curvenote.com" target="_blank" style="color: #aaa">
97
- <img src="https://cdn.curvenote.com/brand/logo-blue-icon.png" style="height: 1em" /> Curvenote
96
+ <a href="https://continuous.foundation" target="_blank" style="color: #aaa">
97
+ Continuous Science Foundation <img src="https://continuous.foundation/images/logo-small.svg" style="height: 1em" />
98
98
  </a>
99
99
  </p>
package/dist/convert.js CHANGED
@@ -4,7 +4,7 @@ import { clirun, getSession } from 'myst-cli-utils';
4
4
  function makeConvertCLI(program) {
5
5
  const command = new Command('convert')
6
6
  .description('Convert JATS file to MyST mdast json')
7
- .argument('<input>', 'The JATS file')
7
+ .argument('[input]', 'The JATS file')
8
8
  .addOption(new Option('--frontmatter <frontmatter>', 'Treat JATS frontmatter fields as page or project, or ignore if not specified').choices(['page', 'project']))
9
9
  .addOption(new Option('--no-doi, --no-dois', 'By default, DOIs are used for references when available, to be later resolved against doi.org. This option disables that behavior and creates bibtex entries for citations with DOIs.'))
10
10
  .addOption(new Option('--no-bib, --no-bibtex', 'By default, a bibtex file will be written with referenced citations. This option prevents writing that file'))
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.13";
49002
+ var version = "1.0.15";
49003
49003
  var version_default = version;
49004
49004
 
49005
49005
  // src/parse.ts
@@ -56425,6 +56425,7 @@ var RefType;
56425
56425
  RefType2["table"] = "table";
56426
56426
  RefType2["tableFn"] = "table-fn";
56427
56427
  RefType2["ref"] = "ref";
56428
+ RefType2["media"] = "media";
56428
56429
  })(RefType || (RefType = {}));
56429
56430
 
56430
56431
  // ../jats-fetch/dist/download.js
@@ -65028,8 +65029,15 @@ function blockNestingTransform(tree) {
65028
65029
  }
65029
65030
 
65030
65031
  // ../jats-convert/dist/transforms/sections.js
65032
+ var SECTION_TYPES = ["sec", "ack", "app"];
65031
65033
  function isSection(node) {
65032
- return node.type === "sec" || node.type === "ack";
65034
+ return SECTION_TYPES.includes(node.type);
65035
+ }
65036
+ function liftApps(tree) {
65037
+ selectAll2("app-group", tree).forEach((group) => {
65038
+ group.type = "__lift__";
65039
+ });
65040
+ liftChildren(tree, "__lift__");
65033
65041
  }
65034
65042
  function recurseSections(tree, depth = 1, titleType) {
65035
65043
  var _a;
@@ -65057,11 +65065,15 @@ function recurseSections(tree, depth = 1, titleType) {
65057
65065
  }
65058
65066
  if (sec.type === "ack")
65059
65067
  sec.part = "acknowledgments";
65068
+ if (sec.type === "app")
65069
+ sec.part = "appendix";
65070
+ sec.type = "sec";
65060
65071
  recurseSections(sec, depth + 1, titleType);
65061
65072
  });
65062
65073
  }
65063
65074
  function sectionTransform(tree, titleType) {
65064
65075
  var _a;
65076
+ liftApps(tree);
65065
65077
  recurseSections(tree, 1, titleType);
65066
65078
  remove(tree, "__delete__");
65067
65079
  const topSections = (_a = tree.children) === null || _a === void 0 ? void 0 : _a.filter((n) => isSection(n));
@@ -65109,6 +65121,38 @@ function abbreviationSectionTransform(tree, frontmatter) {
65109
65121
  });
65110
65122
  remove(tree, "__delete__");
65111
65123
  }
65124
+ function abbreviationFootnoteTransform(tree, frontmatter) {
65125
+ const fnDefs = selectAll2("footnoteDefinition", tree);
65126
+ const fnRefs = selectAll2("footnoteReference", tree).map(({ identifier }) => identifier);
65127
+ fnDefs.forEach((fnDef) => {
65128
+ var _a;
65129
+ if (fnDef.identifier && fnRefs.includes(fnDef.identifier))
65130
+ return;
65131
+ if (((_a = fnDef.children) === null || _a === void 0 ? void 0 : _a.length) !== 1)
65132
+ return;
65133
+ if (fnDef.children[0].type !== "paragraph")
65134
+ return;
65135
+ const fnText = toText2(fnDef.children[0]);
65136
+ const abbrPrefix = "abbreviations: ";
65137
+ if (!fnText.toLowerCase().startsWith(abbrPrefix))
65138
+ return;
65139
+ const abbreviations = fnText.slice(abbrPrefix.length).replace(/\.$/, "").split(/;\s*/g);
65140
+ const entries = abbreviations.map((abbr) => {
65141
+ const parts = abbr.split(/[,:]\s*/g);
65142
+ if (parts.length !== 2)
65143
+ return void 0;
65144
+ if (parts[0].match(/\s/))
65145
+ return void 0;
65146
+ return [parts[0], parts[1]];
65147
+ });
65148
+ if (entries.findIndex((entry) => !entry) !== -1)
65149
+ return;
65150
+ const newAbbreviations = Object.fromEntries(entries);
65151
+ frontmatter.abbreviations = { ...frontmatter.abbreviations, ...newAbbreviations };
65152
+ fnDef.type = "__delete__";
65153
+ });
65154
+ remove(tree, "__delete__");
65155
+ }
65112
65156
 
65113
65157
  // ../jats-convert/dist/transforms/abstract.js
65114
65158
  function abstractTransform(tree) {
@@ -65148,28 +65192,26 @@ function descriptionFromAbstract(abstract) {
65148
65192
  return `${firstSentence} ${secondSentence}`;
65149
65193
  }
65150
65194
 
65151
- // ../jats-convert/dist/transforms/citations.js
65152
- function citationToMixedCitation(tree) {
65153
- selectAll2("citation", tree).forEach((node) => {
65154
- node.type = "mixed-citation";
65155
- });
65156
- }
65157
-
65158
65195
  // ../jats-convert/dist/transforms/footnotes.js
65159
- function backToBodyTransform(jats) {
65160
- var _a, _b;
65161
- if (!jats.back)
65196
+ function backToBodyTransform(body, back) {
65197
+ var _a;
65198
+ if (!back)
65162
65199
  return;
65163
- const backNodes = (_a = jats.back.children) === null || _a === void 0 ? void 0 : _a.filter((node) => {
65164
- return ["fn-group", "sec", "ack"].includes(node.type);
65200
+ const backNodes = (_a = back.children) === null || _a === void 0 ? void 0 : _a.filter((node) => {
65201
+ return ["fn-group", "sec", "ack", "app-group"].includes(node.type);
65165
65202
  });
65166
- if (!((_b = jats.body) === null || _b === void 0 ? void 0 : _b.children) || backNodes.length === 0)
65203
+ if (!(body === null || body === void 0 ? void 0 : body.children) || backNodes.length === 0)
65167
65204
  return;
65168
- jats.body.children.push({ type: "hr" }, ...copyNode(backNodes));
65169
- backNodes.forEach((node) => {
65170
- node.type = "__delete__";
65205
+ body.children.push({ type: "hr" }, ...copyNode(backNodes));
65206
+ }
65207
+ function tableFootnotesToLegend(tree) {
65208
+ const tableFns = selectAll2("legend > footnoteDefinition", tree);
65209
+ const fnRefs = selectAll2("footnoteReference", tree).map(({ identifier }) => identifier);
65210
+ tableFns.forEach((tableFn) => {
65211
+ if (tableFn.identifier && fnRefs.includes(tableFn.identifier))
65212
+ return;
65213
+ tableFn.type = "paragraph";
65171
65214
  });
65172
- remove(jats.back, "__delete__");
65173
65215
  }
65174
65216
 
65175
65217
  // ../../node_modules/dotenv/config.js
@@ -65328,6 +65370,7 @@ function bibtexFromCite(key, cite, counts, doi2) {
65328
65370
  }
65329
65371
  if (bibtexLines.length === 1) {
65330
65372
  counts.unprocessed += 1;
65373
+ bibtexLines.push(` note = {${toText2(cite)}}`);
65331
65374
  } else {
65332
65375
  counts.bibtex += 1;
65333
65376
  counts.lostRefItems.push(...skipped);
@@ -65380,7 +65423,7 @@ function processRef(ref, pmidCache, fnCount, counts, dois) {
65380
65423
  const footnotes = [];
65381
65424
  const bibtexEntries = [];
65382
65425
  (_b = ref.children) === null || _b === void 0 ? void 0 : _b.forEach((child) => {
65383
- if (["element-citation", "mixed-citation"].includes(child.type)) {
65426
+ if (["element-citation", "mixed-citation", "citation"].includes(child.type)) {
65384
65427
  if (!toText2(child))
65385
65428
  return;
65386
65429
  const cite = processRefCite(child, identifier, pmidCache, counts, dois);
@@ -65401,15 +65444,14 @@ function processRef(ref, pmidCache, fnCount, counts, dois) {
65401
65444
  });
65402
65445
  return { refLookup, footnotes, bibtexEntries };
65403
65446
  }
65404
- async function processJatsReferences(jats, opts) {
65447
+ function processJatsReferences(body, references, opts) {
65405
65448
  var _a, _b;
65406
65449
  const dir = (_a = opts === null || opts === void 0 ? void 0 : opts.dir) !== null && _a !== void 0 ? _a : ".";
65407
65450
  const bibfile = import_node_path5.default.join(dir, "main.bib");
65408
- const refs = jats.references;
65451
+ const pmidCache = (_b = opts === null || opts === void 0 ? void 0 : opts.pmidCache) !== null && _b !== void 0 ? _b : {};
65409
65452
  let refLookup = {};
65410
65453
  const footnotes = [];
65411
65454
  const bibtexEntries = [];
65412
- const pmidCache = await getPMIDLookup(refs, dir);
65413
65455
  const counts = {
65414
65456
  dois: 0,
65415
65457
  bibtex: 0,
@@ -65417,7 +65459,7 @@ async function processJatsReferences(jats, opts) {
65417
65459
  lostRefs: [],
65418
65460
  lostRefItems: []
65419
65461
  };
65420
- refs.forEach((ref) => {
65462
+ references.forEach((ref) => {
65421
65463
  const { refLookup: newRefLookup, footnotes: newFootnotes, bibtexEntries: newBibtexEntries } = processRef(ref, pmidCache, footnotes.length + 1, counts, opts === null || opts === void 0 ? void 0 : opts.dois);
65422
65464
  refLookup = { ...refLookup, ...newRefLookup };
65423
65465
  bibtexEntries.push(...newBibtexEntries);
@@ -65425,7 +65467,7 @@ async function processJatsReferences(jats, opts) {
65425
65467
  });
65426
65468
  if (opts === null || opts === void 0 ? void 0 : opts.logInfo) {
65427
65469
  opts.logInfo.references = {
65428
- total: refs.length,
65470
+ total: references.length,
65429
65471
  dois: counts.dois,
65430
65472
  bibtex: counts.bibtex,
65431
65473
  footnotes: footnotes.length,
@@ -65454,7 +65496,7 @@ async function processJatsReferences(jats, opts) {
65454
65496
  import_node_fs6.default.writeFileSync(bibfile, bibtexEntries.join("\n\n"));
65455
65497
  }
65456
65498
  if (footnotes.length) {
65457
- (_b = jats.body) === null || _b === void 0 ? void 0 : _b.children.push({ type: "fn-group", children: footnotes });
65499
+ body.children.push({ type: "fn-group", children: footnotes });
65458
65500
  }
65459
65501
  return refLookup;
65460
65502
  }
@@ -65520,18 +65562,18 @@ async function resolveJatsCitations(tree, refLookup) {
65520
65562
  }
65521
65563
 
65522
65564
  // ../jats-convert/dist/transforms/index.js
65523
- function basicTransformations(tree, file) {
65524
- sectionTransform(tree);
65525
- typographyTransform(tree);
65526
- admonitionTransform(tree, file);
65527
- figCaptionTitleTransform(tree);
65565
+ function basicTransformations(body, file) {
65566
+ sectionTransform(body);
65567
+ typographyTransform(body);
65568
+ admonitionTransform(body, file);
65569
+ figCaptionTitleTransform(body);
65528
65570
  }
65529
- function journalTransforms(tree) {
65530
- graphicToBioRxivUrl(tree);
65571
+ function journalTransforms(body) {
65572
+ graphicToBioRxivUrl(body);
65531
65573
  }
65532
65574
 
65533
65575
  // ../jats-convert/dist/version.js
65534
- var version3 = "1.0.13";
65576
+ var version3 = "1.0.15";
65535
65577
  var version_default3 = version3;
65536
65578
 
65537
65579
  // ../jats-convert/dist/myst/inlineCitations.js
@@ -65671,6 +65713,35 @@ function expandHyphenatedCites(tree, referenceList) {
65671
65713
  });
65672
65714
  remove(tree, "__delete__");
65673
65715
  }
65716
+ function removeCiteSuperscript(tree) {
65717
+ const citeGroupParents = selectAll2(":has(> citeGroup)", tree);
65718
+ citeGroupParents.forEach((parent3) => {
65719
+ if (parent3.type !== "superscript")
65720
+ return;
65721
+ if (parent3.children.length !== 1)
65722
+ return;
65723
+ parent3.type = "__lift__";
65724
+ });
65725
+ liftChildren(tree, "__lift__");
65726
+ }
65727
+ function ensureSpaceBeforeCite(tree) {
65728
+ const citeGroupParents = selectAll2(":has(> text + citeGroup)", tree);
65729
+ citeGroupParents.forEach((parent3) => {
65730
+ parent3.children.forEach((child, index2) => {
65731
+ var _a, _b;
65732
+ if (child.type !== "text")
65733
+ return;
65734
+ const citeChild = parent3.children[index2 + 1];
65735
+ if ((citeChild === null || citeChild === void 0 ? void 0 : citeChild.type) !== "citeGroup")
65736
+ return;
65737
+ if ((_a = child.value) === null || _a === void 0 ? void 0 : _a.match(/\s+$/))
65738
+ return;
65739
+ if ((_b = child.value) === null || _b === void 0 ? void 0 : _b.match(/[[(]$/))
65740
+ return;
65741
+ child.value = `${child.value} `;
65742
+ });
65743
+ });
65744
+ }
65674
65745
  function inlineCitationsTransform(tree, referenceIds) {
65675
65746
  let before = "";
65676
65747
  let current = JSON.stringify(tree);
@@ -65683,30 +65754,129 @@ function inlineCitationsTransform(tree, referenceIds) {
65683
65754
  removeCiteSeparators(tree);
65684
65755
  expandHyphenatedCites(tree, referenceIds);
65685
65756
  removeCiteParentheses(tree);
65757
+ removeCiteSuperscript(tree);
65758
+ ensureSpaceBeforeCite(tree);
65686
65759
  current = JSON.stringify(tree);
65687
65760
  }
65688
65761
  }
65689
65762
 
65690
65763
  // ../jats-convert/dist/transforms/supplementary.js
65691
- function floatToEndTransform(jats) {
65764
+ function floatToEndTransform(body) {
65692
65765
  var _a;
65693
- if (!jats.body)
65694
- return;
65695
- const floatSupplementaryMaterial = selectAll2("supplementary-material[position=float]", jats.body);
65766
+ const floatSupplementaryMaterial = selectAll2("supplementary-material[position=float]", body);
65696
65767
  if (floatSupplementaryMaterial.length === 0)
65697
65768
  return;
65698
- (_a = jats.body.children) === null || _a === void 0 ? void 0 : _a.push({ type: "hr" });
65769
+ (_a = body.children) === null || _a === void 0 ? void 0 : _a.push({ type: "hr" });
65699
65770
  floatSupplementaryMaterial.forEach((node) => {
65700
- var _a2, _b;
65771
+ var _a2;
65701
65772
  const copy = copyNode2(node);
65702
65773
  delete copy.position;
65703
- (_b = (_a2 = jats.body) === null || _a2 === void 0 ? void 0 : _a2.children) === null || _b === void 0 ? void 0 : _b.push(copy);
65774
+ (_a2 = body === null || body === void 0 ? void 0 : body.children) === null || _a2 === void 0 ? void 0 : _a2.push(copy);
65704
65775
  node.type = "__delete__";
65705
65776
  });
65706
- remove(jats.body, "__delete__");
65777
+ remove(body, "__delete__");
65778
+ }
65779
+
65780
+ // ../jats-convert/dist/transforms/parts.js
65781
+ function dataAvailabilityTransform(tree) {
65782
+ const dataAvailability = selectAll2("sec[sec-type=data-availability]", tree);
65783
+ dataAvailability.forEach((node) => {
65784
+ const titles = selectAll2("title", node);
65785
+ titles.forEach((title) => {
65786
+ if (toText(title).toLowerCase() === "data availability") {
65787
+ title.type = "__delete__";
65788
+ }
65789
+ });
65790
+ });
65791
+ remove(tree, "__delete__");
65792
+ }
65793
+
65794
+ // ../jats-convert/dist/myst/abbreviations.js
65795
+ function abbreviationsFromTree(tree, frontmatter) {
65796
+ let abbreviations = {};
65797
+ const paragraphs = selectAll2("paragraph", tree);
65798
+ paragraphs.forEach((paragraph) => {
65799
+ const text = toText2(paragraph);
65800
+ abbreviations = {
65801
+ ...abbreviations,
65802
+ ...abbreviationsFromText(text)
65803
+ };
65804
+ });
65805
+ frontmatter.abbreviations = { ...frontmatter.abbreviations, ...abbreviations };
65806
+ }
65807
+ function maybeStopWord(word) {
65808
+ return word.length < 5;
65809
+ }
65810
+ function exploreAbbrPossibilities(letter, possibilities) {
65811
+ const newPossibilities = [];
65812
+ possibilities.forEach(({ prev, next }) => {
65813
+ if (prev === null || prev === void 0 ? void 0 : prev.includes(letter)) {
65814
+ newPossibilities.push({
65815
+ prev: prev.slice(prev.indexOf(letter) + 1),
65816
+ next
65817
+ });
65818
+ }
65819
+ for (const [i2, n] of next.entries()) {
65820
+ if (n.startsWith(letter)) {
65821
+ newPossibilities.push({
65822
+ prev: next[i2].slice(1),
65823
+ next: next.slice(i2 + 1)
65824
+ });
65825
+ }
65826
+ if (!prev || !maybeStopWord(n)) {
65827
+ break;
65828
+ }
65829
+ }
65830
+ });
65831
+ return newPossibilities;
65832
+ }
65833
+ function abbreviationsFromText(text) {
65834
+ const abbreviations = {};
65835
+ const textList = text.split(" ");
65836
+ textList.forEach((word, index2) => {
65837
+ var _a;
65838
+ const abbr = (_a = word.match(/^\(([^\s]{2,})\).{0,1}/)) === null || _a === void 0 ? void 0 : _a[1];
65839
+ if (!abbr)
65840
+ return;
65841
+ const possibleWords = [];
65842
+ let wordIndex = index2 - 1;
65843
+ while (textList[wordIndex] && possibleWords.filter((w) => w.length > 4).length < abbr.length) {
65844
+ possibleWords.unshift(textList[wordIndex]);
65845
+ wordIndex--;
65846
+ }
65847
+ for (const i2 of Array(possibleWords.length).keys()) {
65848
+ let possibilities = [
65849
+ {
65850
+ next: possibleWords.slice(i2).map((w) => w.toLowerCase())
65851
+ }
65852
+ ];
65853
+ abbr.split("").filter((letter) => letter.match(/^[a-zA-Z]$/)).forEach((letter) => {
65854
+ possibilities = exploreAbbrPossibilities(letter.toLowerCase(), possibilities);
65855
+ });
65856
+ if (possibilities.filter(({ next }) => next.length === 0).length) {
65857
+ abbreviations[abbr] = possibleWords.slice(i2).join(" ");
65858
+ break;
65859
+ }
65860
+ }
65861
+ });
65862
+ return abbreviations;
65707
65863
  }
65708
65864
 
65709
65865
  // ../jats-convert/dist/index.js
65866
+ var MEDIA_FIGURE_EXTENSIONS = [
65867
+ ".png",
65868
+ ".jpg",
65869
+ ".jpeg",
65870
+ ".svg",
65871
+ ".gif",
65872
+ ".tiff",
65873
+ ".tif",
65874
+ ".eps",
65875
+ ".webp",
65876
+ ".mp4",
65877
+ ".mov",
65878
+ ".avi"
65879
+ ];
65710
65880
  function refTypeToReferenceKind(kind) {
65711
65881
  switch (kind) {
65712
65882
  case RefType.sec:
@@ -65765,10 +65935,12 @@ var handlers = {
65765
65935
  state2.renderInline(node, "paragraph");
65766
65936
  },
65767
65937
  heading(node, state2) {
65938
+ var _a;
65939
+ const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
65768
65940
  state2.renderInline(node, "heading", {
65769
65941
  enumerated: true,
65770
- label: node.id,
65771
- identifier: node.id,
65942
+ label,
65943
+ identifier,
65772
65944
  depth: node.depth
65773
65945
  });
65774
65946
  },
@@ -65804,27 +65976,39 @@ var handlers = {
65804
65976
  state2.renderInline(node, "listItem");
65805
65977
  },
65806
65978
  ["inline-formula"](node, state2) {
65979
+ var _a;
65807
65980
  const texMath = texMathFromNode(node);
65808
65981
  if (texMath) {
65982
+ const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
65809
65983
  state2.addLeaf("inlineMath", {
65810
65984
  value: texMath,
65811
- label: node.id,
65812
- identifier: node.id
65985
+ label,
65986
+ identifier
65813
65987
  });
65814
65988
  } else {
65815
65989
  state2.renderChildren(node);
65816
65990
  }
65817
65991
  },
65818
65992
  ["disp-formula"](node, state2) {
65993
+ var _a;
65819
65994
  const texMath = texMathFromNode(node);
65995
+ const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
65820
65996
  if (texMath) {
65821
65997
  state2.addLeaf("math", {
65822
65998
  value: texMath,
65823
- label: node.id,
65824
- identifier: node.id
65999
+ label,
66000
+ identifier
65825
66001
  });
65826
66002
  } else {
66003
+ if (node.id) {
66004
+ state2.openNode("div", { label, identifier });
66005
+ }
66006
+ state2.openNode("paragraph");
65827
66007
  state2.renderChildren(node);
66008
+ state2.closeNode();
66009
+ if (node.id) {
66010
+ state2.closeNode();
66011
+ }
65828
66012
  }
65829
66013
  },
65830
66014
  bold(node, state2) {
@@ -65867,7 +66051,15 @@ var handlers = {
65867
66051
  state2.renderInline(node, "link", { url: node["xlink:href"] });
65868
66052
  },
65869
66053
  ["boxed-text"](node, state2) {
66054
+ var _a;
66055
+ if (node.id) {
66056
+ const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
66057
+ state2.openNode("div", { label, identifier });
66058
+ }
65870
66059
  state2.renderInline(node, "admonition", { kind: "info" });
66060
+ if (node.id) {
66061
+ state2.closeNode();
66062
+ }
65871
66063
  },
65872
66064
  admonitionTitle(node, state2) {
65873
66065
  state2.renderInline(node, "admonitionTitle");
@@ -66038,6 +66230,9 @@ var handlers = {
66038
66230
  kind: "narrative"
66039
66231
  });
66040
66232
  return;
66233
+ case RefType.app:
66234
+ case RefType.boxedText:
66235
+ case RefType.media:
66041
66236
  case RefType.supplementaryMaterial:
66042
66237
  case RefType.sec:
66043
66238
  case RefType.fig:
@@ -66060,6 +66255,55 @@ var handlers = {
66060
66255
  }
66061
66256
  },
66062
66257
  ["supplementary-material"](node, state2) {
66258
+ var _a, _b, _c, _d, _e;
66259
+ const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
66260
+ let maybeCaption;
66261
+ let media;
66262
+ if (((_b = node.children) === null || _b === void 0 ? void 0 : _b.length) === 1 && node.children[0].type === "media") {
66263
+ media = node.children[0];
66264
+ } else if (((_c = node.children) === null || _c === void 0 ? void 0 : _c.length) === 2 && node.children[0].type === "label" && node.children[1].type === "media") {
66265
+ maybeCaption = node.children[0];
66266
+ media = node.children[1];
66267
+ }
66268
+ const url = media === null || media === void 0 ? void 0 : media["xlink:href"];
66269
+ let caption = (_d = select3("caption", media)) !== null && _d !== void 0 ? _d : maybeCaption;
66270
+ 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") {
66271
+ caption = caption.children[0];
66272
+ }
66273
+ if (url && MEDIA_FIGURE_EXTENSIONS.find((ext) => url.endsWith(ext))) {
66274
+ const title = select3("title", media);
66275
+ state2.openNode("container", { label, identifier, kind: "figure" });
66276
+ const wasInContainer = state2.data.isInContainer;
66277
+ state2.data.isInContainer = true;
66278
+ state2.addLeaf("image", { url });
66279
+ state2.openNode("caption");
66280
+ state2.openNode("link", { url });
66281
+ if (title) {
66282
+ state2.openNode("strong");
66283
+ state2.renderChildren(title);
66284
+ state2.closeNode();
66285
+ }
66286
+ if (caption) {
66287
+ state2.renderChildren(caption);
66288
+ }
66289
+ state2.closeNode();
66290
+ state2.closeNode();
66291
+ state2.closeNode();
66292
+ state2.data.isInContainer = wasInContainer;
66293
+ } else {
66294
+ if (node.id) {
66295
+ state2.openNode("div", { label, identifier });
66296
+ }
66297
+ state2.renderChildren(node);
66298
+ if (node.id) {
66299
+ state2.closeNode();
66300
+ }
66301
+ }
66302
+ },
66303
+ ["app-group"](node, state2) {
66304
+ state2.renderChildren(node);
66305
+ },
66306
+ app(node, state2) {
66063
66307
  var _a;
66064
66308
  if (node.id) {
66065
66309
  const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
@@ -66079,6 +66323,9 @@ var handlers = {
66079
66323
  caption(node, state2) {
66080
66324
  state2.renderChildren(node);
66081
66325
  },
66326
+ email(node, state2) {
66327
+ state2.renderInline(node, "link", { url: `mailto:${toText2(node)}` });
66328
+ },
66082
66329
  // These nodes can be safely ignored
66083
66330
  label() {
66084
66331
  },
@@ -66181,63 +66428,54 @@ var JatsParser = class {
66181
66428
  }
66182
66429
  };
66183
66430
  var jatsConvertPlugin = function(jats, opts) {
66184
- this.Compiler = (node, file) => {
66185
- if (jats.abstract)
66431
+ this.Compiler = (body, file) => {
66432
+ if (jats.abstract) {
66186
66433
  abstractTransform(jats.abstract);
66187
- const tree = jats.abstract ? {
66188
- type: "root",
66189
- children: [
66434
+ body.children = [
66190
66435
  u("block", { part: "abstract" }, copyNode(jats.abstract).children),
66191
- ...copyNode(node).children
66192
- ]
66193
- } : copyNode(node);
66436
+ ...body.children
66437
+ ];
66438
+ }
66194
66439
  const floatsGroup = selectAll2("floats-group", jats.tree);
66195
66440
  if (floatsGroup.length > 0) {
66196
66441
  floatsGroup.forEach((g) => {
66197
- tree.children.push(...g.children);
66442
+ body.children.push(...g.children);
66198
66443
  });
66199
66444
  }
66200
- basicTransformations(tree, file);
66201
- citationToMixedCitation(tree);
66202
- journalTransforms(tree);
66203
- const state2 = new JatsParser(file, jats, opts !== null && opts !== void 0 ? opts : { handlers });
66204
- state2.renderChildren(tree);
66445
+ floatToEndTransform(body);
66446
+ backToBodyTransform(body, jats.back);
66447
+ dataAvailabilityTransform(body);
66448
+ const refLookup = processJatsReferences(body, jats.references, opts);
66449
+ basicTransformations(body, file);
66450
+ journalTransforms(body);
66451
+ const state2 = new JatsParser(file, jats, opts);
66452
+ state2.renderChildren(body);
66205
66453
  while (state2.stack.length > 1)
66206
66454
  state2.closeNode();
66455
+ const tree = state2.stack[0];
66207
66456
  if (state2.unhandled.length && (opts === null || opts === void 0 ? void 0 : opts.logInfo)) {
66208
66457
  opts.logInfo.unhandled = [...new Set(state2.unhandled)];
66209
66458
  }
66210
- const referenceData = Object.fromEntries(jats.references.map((bibr) => {
66211
- const id = bibr.id;
66212
- const names = selectAll2("name,string-name", bibr).map((n) => `${toText2(select3("surname", n))}, ${toText2(select3("given-names", n))}`).join(", ");
66213
- const year = toText2(select3("year", bibr));
66214
- const title = toText2(select3("article-title", bibr));
66215
- const source = toText2(select3("source", bibr));
66216
- const volume = toText2(select3("volume", bibr));
66217
- const fpage = toText2(select3("fpage", bibr));
66218
- const lpage = toText2(select3("lpage", bibr));
66219
- const doiElement = selectAll2("ext-link,[pub-id-type=doi]", bibr).find((e2) => doi.validate(toText2(e2)));
66220
- const doiString = doiElement ? toText2(doiElement) : void 0;
66221
- const doiLink = doiString ? ` <a href=${doi.buildUrl(doiString)}>${doiString}</a>` : "";
66222
- return [
66223
- id,
66224
- {
66225
- html: `${names}. (${year}). ${title}. <i>${source}</i>, <i>${volume}</i>, ${fpage}-${lpage}.${doiLink}`,
66226
- doi: doiString
66227
- }
66228
- ];
66229
- }));
66230
- const referenceOrder = [];
66231
- const xrefs = selectAll2("xref[ref-type=bibr]", jats.body);
66232
- xrefs.forEach((xref) => {
66233
- const rid = xref.rid;
66234
- if (!referenceOrder.includes(rid)) {
66235
- referenceOrder.push(rid);
66236
- }
66459
+ resolveJatsCitations(tree, refLookup);
66460
+ inlineCitationsTransform(tree, jats.references.map(({ id }) => {
66461
+ var _a;
66462
+ const { identifier } = (_a = normalizeLabel(id)) !== null && _a !== void 0 ? _a : {};
66463
+ return identifier;
66464
+ }).filter((id) => !!id));
66465
+ const { frontmatter } = jats;
66466
+ abbreviationSectionTransform(tree, frontmatter);
66467
+ abbreviationFootnoteTransform(tree, frontmatter);
66468
+ abbreviationsFromTree(tree, frontmatter);
66469
+ tableFootnotesToLegend(tree);
66470
+ const abstract = selectAll2("block", tree).find((block) => {
66471
+ return block.data && block.data.part === "abstract";
66237
66472
  });
66473
+ if (abstract) {
66474
+ frontmatter.description = descriptionFromAbstract(toText2(abstract));
66475
+ }
66238
66476
  const result = {
66239
- references: { order: referenceOrder, data: referenceData },
66240
- tree: state2.stack[0]
66477
+ tree,
66478
+ frontmatter
66241
66479
  };
66242
66480
  file.result = result;
66243
66481
  return file;
@@ -66246,9 +66484,8 @@ var jatsConvertPlugin = function(jats, opts) {
66246
66484
  return node;
66247
66485
  };
66248
66486
  };
66249
- async function jatsConvertTransform(data, opts) {
66487
+ function jatsConvertTransform(jats, opts) {
66250
66488
  var _a, _b, _c;
66251
- const jats = typeof data === "string" ? new Jats(data) : data;
66252
66489
  if (opts === null || opts === void 0 ? void 0 : opts.logInfo) {
66253
66490
  opts.logInfo.publisher = toText2(select3("publisher-name", jats.tree)) || null;
66254
66491
  opts.logInfo.journal = toText2(select3("journal-title", jats.tree)) || null;
@@ -66269,24 +66506,10 @@ async function jatsConvertTransform(data, opts) {
66269
66506
  }
66270
66507
  opts.logInfo.license = licenseString;
66271
66508
  }
66272
- const { frontmatter } = jats;
66273
66509
  const file = (_b = opts === null || opts === void 0 ? void 0 : opts.vfile) !== null && _b !== void 0 ? _b : new VFile();
66274
- const refLookup = await processJatsReferences(jats, opts);
66275
- floatToEndTransform(jats);
66276
- backToBodyTransform(jats);
66277
66510
  const pipe = unified().use(jatsConvertPlugin, jats, opts);
66278
- pipe.stringify((_c = jats.body) !== null && _c !== void 0 ? _c : { type: "body", children: [] }, file);
66279
- const references = file.result.references;
66280
- const tree = file.result.tree;
66281
- resolveJatsCitations(tree, refLookup);
66282
- inlineCitationsTransform(tree, [...Object.keys(references.data)]);
66283
- abbreviationSectionTransform(tree, frontmatter);
66284
- const abstract = selectAll2("block", tree).find((node) => {
66285
- return node.data && node.data.part === "abstract";
66286
- });
66287
- if (abstract) {
66288
- frontmatter.description = descriptionFromAbstract(toText2(abstract));
66289
- }
66511
+ pipe.stringify(copyNode((_c = jats.body) !== null && _c !== void 0 ? _c : { type: "body", children: [] }), file);
66512
+ const { tree, frontmatter } = file.result;
66290
66513
  if (opts === null || opts === void 0 ? void 0 : opts.logInfo) {
66291
66514
  opts.logInfo.figures = {
66292
66515
  body: selectAll2("fig", jats.body).length,
@@ -66316,17 +66539,30 @@ async function jatsConvertTransform(data, opts) {
66316
66539
  myst: selectAll2("footnoteDefinition", tree).length
66317
66540
  };
66318
66541
  }
66319
- return { tree, jats, references, frontmatter };
66542
+ return { tree, frontmatter };
66320
66543
  }
66321
66544
  async function jatsConvert(session, input, opts) {
66322
66545
  const logInfo = { jatsVersion: version_default3 };
66546
+ if (!input) {
66547
+ const xmls = import_node_fs7.default.readdirSync(".").filter((file) => import_node_path6.default.extname(file) === ".xml");
66548
+ if (xmls.length === 0) {
66549
+ throw new Error("No JATS xml file found in current directory; please specify input");
66550
+ }
66551
+ if (xmls.length > 1) {
66552
+ throw new Error("Multiple XML files found in current directory; please specify input");
66553
+ }
66554
+ input = xmls[0];
66555
+ }
66323
66556
  const dir = import_node_path6.default.dirname(input);
66324
66557
  const vfile2 = new VFile();
66325
66558
  vfile2.path = input;
66326
- const { tree, frontmatter } = await jatsConvertTransform(import_node_fs7.default.readFileSync(input).toString(), {
66559
+ const jats = new Jats(import_node_fs7.default.readFileSync(input).toString());
66560
+ const pmidCache = await getPMIDLookup(jats.references, dir);
66561
+ const { tree, frontmatter } = jatsConvertTransform(jats, {
66327
66562
  vfile: vfile2,
66328
66563
  dir,
66329
66564
  logInfo,
66565
+ pmidCache,
66330
66566
  dois: opts === null || opts === void 0 ? void 0 : opts.dois,
66331
66567
  bibtex: opts === null || opts === void 0 ? void 0 : opts.bibtex
66332
66568
  });
@@ -66355,7 +66591,7 @@ async function jatsConvert(session, input, opts) {
66355
66591
 
66356
66592
  // src/convert.ts
66357
66593
  function makeConvertCLI(program3) {
66358
- const command = new Command("convert").description("Convert JATS file to MyST mdast json").argument("<input>", "The JATS file").addOption(
66594
+ const command = new Command("convert").description("Convert JATS file to MyST mdast json").argument("[input]", "The JATS file").addOption(
66359
66595
  new Option(
66360
66596
  "--frontmatter <frontmatter>",
66361
66597
  "Treat JATS frontmatter fields as page or project, or ignore if not specified"
package/dist/version.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- declare const version = "1.0.13";
1
+ declare const version = "1.0.15";
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.13';
1
+ const version = '1.0.15';
2
2
  export default version;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "jats-cli",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "Typescript CLI for with JATS",
5
- "author": "Rowan Cockett <rowan@curvenote.com>",
6
- "homepage": "https://github.com/curvenote/jats",
5
+ "author": "Rowan Cockett <rowan@continuous.foundation>",
6
+ "homepage": "https://github.com/continuous-foundation/jats",
7
7
  "license": "MIT",
8
8
  "sideEffects": false,
9
9
  "type": "module",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",
25
- "url": "git+https://github.com/curvenote/jats.git"
25
+ "url": "git+https://github.com/continuous-foundation/jats.git"
26
26
  },
27
27
  "bin": {
28
28
  "jats": "./dist/jats.cjs"
@@ -40,16 +40,16 @@
40
40
  "build": "npm-run-all -l clean copy:version -p build:esm build:cli"
41
41
  },
42
42
  "bugs": {
43
- "url": "https://github.com/curvenote/jats/issues"
43
+ "url": "https://github.com/continuous-foundation/jats/issues"
44
44
  },
45
45
  "dependencies": {
46
46
  "doi-utils": "^2.0.0",
47
47
  "fair-principles": "^2.0.0",
48
- "jats-convert": "^1.0.13",
49
- "jats-fetch": "^1.0.13",
50
- "jats-tags": "^1.0.13",
51
- "jats-utils": "^1.0.13",
52
- "jats-xml": "^1.0.13",
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",
53
53
  "js-yaml": "^4.1.0",
54
54
  "unist-util-is": "^5.2.1",
55
55
  "unist-util-select": "^4.0.0"