jats-cli 1.0.13 → 1.0.14

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.14";
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.14";
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,27 +65754,112 @@ 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
@@ -65765,10 +65921,12 @@ var handlers = {
65765
65921
  state2.renderInline(node, "paragraph");
65766
65922
  },
65767
65923
  heading(node, state2) {
65924
+ var _a;
65925
+ const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
65768
65926
  state2.renderInline(node, "heading", {
65769
65927
  enumerated: true,
65770
- label: node.id,
65771
- identifier: node.id,
65928
+ label,
65929
+ identifier,
65772
65930
  depth: node.depth
65773
65931
  });
65774
65932
  },
@@ -65804,27 +65962,39 @@ var handlers = {
65804
65962
  state2.renderInline(node, "listItem");
65805
65963
  },
65806
65964
  ["inline-formula"](node, state2) {
65965
+ var _a;
65807
65966
  const texMath = texMathFromNode(node);
65808
65967
  if (texMath) {
65968
+ const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
65809
65969
  state2.addLeaf("inlineMath", {
65810
65970
  value: texMath,
65811
- label: node.id,
65812
- identifier: node.id
65971
+ label,
65972
+ identifier
65813
65973
  });
65814
65974
  } else {
65815
65975
  state2.renderChildren(node);
65816
65976
  }
65817
65977
  },
65818
65978
  ["disp-formula"](node, state2) {
65979
+ var _a;
65819
65980
  const texMath = texMathFromNode(node);
65981
+ const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
65820
65982
  if (texMath) {
65821
65983
  state2.addLeaf("math", {
65822
65984
  value: texMath,
65823
- label: node.id,
65824
- identifier: node.id
65985
+ label,
65986
+ identifier
65825
65987
  });
65826
65988
  } else {
65989
+ if (node.id) {
65990
+ state2.openNode("div", { label, identifier });
65991
+ }
65992
+ state2.openNode("paragraph");
65827
65993
  state2.renderChildren(node);
65994
+ state2.closeNode();
65995
+ if (node.id) {
65996
+ state2.closeNode();
65997
+ }
65828
65998
  }
65829
65999
  },
65830
66000
  bold(node, state2) {
@@ -65867,7 +66037,15 @@ var handlers = {
65867
66037
  state2.renderInline(node, "link", { url: node["xlink:href"] });
65868
66038
  },
65869
66039
  ["boxed-text"](node, state2) {
66040
+ var _a;
66041
+ if (node.id) {
66042
+ const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
66043
+ state2.openNode("div", { label, identifier });
66044
+ }
65870
66045
  state2.renderInline(node, "admonition", { kind: "info" });
66046
+ if (node.id) {
66047
+ state2.closeNode();
66048
+ }
65871
66049
  },
65872
66050
  admonitionTitle(node, state2) {
65873
66051
  state2.renderInline(node, "admonitionTitle");
@@ -66038,6 +66216,9 @@ var handlers = {
66038
66216
  kind: "narrative"
66039
66217
  });
66040
66218
  return;
66219
+ case RefType.app:
66220
+ case RefType.boxedText:
66221
+ case RefType.media:
66041
66222
  case RefType.supplementaryMaterial:
66042
66223
  case RefType.sec:
66043
66224
  case RefType.fig:
@@ -66070,6 +66251,20 @@ var handlers = {
66070
66251
  state2.closeNode();
66071
66252
  }
66072
66253
  },
66254
+ ["app-group"](node, state2) {
66255
+ state2.renderChildren(node);
66256
+ },
66257
+ app(node, state2) {
66258
+ var _a;
66259
+ if (node.id) {
66260
+ const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
66261
+ state2.openNode("div", { label, identifier });
66262
+ }
66263
+ state2.renderChildren(node);
66264
+ if (node.id) {
66265
+ state2.closeNode();
66266
+ }
66267
+ },
66073
66268
  media(node, state2) {
66074
66269
  state2.renderInline(node, "link", { url: node["xlink:href"] });
66075
66270
  },
@@ -66079,6 +66274,9 @@ var handlers = {
66079
66274
  caption(node, state2) {
66080
66275
  state2.renderChildren(node);
66081
66276
  },
66277
+ email(node, state2) {
66278
+ state2.renderInline(node, "link", { url: `mailto:${toText2(node)}` });
66279
+ },
66082
66280
  // These nodes can be safely ignored
66083
66281
  label() {
66084
66282
  },
@@ -66181,63 +66379,54 @@ var JatsParser = class {
66181
66379
  }
66182
66380
  };
66183
66381
  var jatsConvertPlugin = function(jats, opts) {
66184
- this.Compiler = (node, file) => {
66185
- if (jats.abstract)
66382
+ this.Compiler = (body, file) => {
66383
+ if (jats.abstract) {
66186
66384
  abstractTransform(jats.abstract);
66187
- const tree = jats.abstract ? {
66188
- type: "root",
66189
- children: [
66385
+ body.children = [
66190
66386
  u("block", { part: "abstract" }, copyNode(jats.abstract).children),
66191
- ...copyNode(node).children
66192
- ]
66193
- } : copyNode(node);
66387
+ ...body.children
66388
+ ];
66389
+ }
66194
66390
  const floatsGroup = selectAll2("floats-group", jats.tree);
66195
66391
  if (floatsGroup.length > 0) {
66196
66392
  floatsGroup.forEach((g) => {
66197
- tree.children.push(...g.children);
66393
+ body.children.push(...g.children);
66198
66394
  });
66199
66395
  }
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);
66396
+ floatToEndTransform(body);
66397
+ backToBodyTransform(body, jats.back);
66398
+ dataAvailabilityTransform(body);
66399
+ const refLookup = processJatsReferences(body, jats.references, opts);
66400
+ basicTransformations(body, file);
66401
+ journalTransforms(body);
66402
+ const state2 = new JatsParser(file, jats, opts);
66403
+ state2.renderChildren(body);
66205
66404
  while (state2.stack.length > 1)
66206
66405
  state2.closeNode();
66406
+ const tree = state2.stack[0];
66207
66407
  if (state2.unhandled.length && (opts === null || opts === void 0 ? void 0 : opts.logInfo)) {
66208
66408
  opts.logInfo.unhandled = [...new Set(state2.unhandled)];
66209
66409
  }
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
- }
66410
+ resolveJatsCitations(tree, refLookup);
66411
+ inlineCitationsTransform(tree, jats.references.map(({ id }) => {
66412
+ var _a;
66413
+ const { identifier } = (_a = normalizeLabel(id)) !== null && _a !== void 0 ? _a : {};
66414
+ return identifier;
66415
+ }).filter((id) => !!id));
66416
+ const { frontmatter } = jats;
66417
+ abbreviationSectionTransform(tree, frontmatter);
66418
+ abbreviationFootnoteTransform(tree, frontmatter);
66419
+ abbreviationsFromTree(tree, frontmatter);
66420
+ tableFootnotesToLegend(tree);
66421
+ const abstract = selectAll2("block", tree).find((block) => {
66422
+ return block.data && block.data.part === "abstract";
66237
66423
  });
66424
+ if (abstract) {
66425
+ frontmatter.description = descriptionFromAbstract(toText2(abstract));
66426
+ }
66238
66427
  const result = {
66239
- references: { order: referenceOrder, data: referenceData },
66240
- tree: state2.stack[0]
66428
+ tree,
66429
+ frontmatter
66241
66430
  };
66242
66431
  file.result = result;
66243
66432
  return file;
@@ -66246,9 +66435,8 @@ var jatsConvertPlugin = function(jats, opts) {
66246
66435
  return node;
66247
66436
  };
66248
66437
  };
66249
- async function jatsConvertTransform(data, opts) {
66438
+ function jatsConvertTransform(jats, opts) {
66250
66439
  var _a, _b, _c;
66251
- const jats = typeof data === "string" ? new Jats(data) : data;
66252
66440
  if (opts === null || opts === void 0 ? void 0 : opts.logInfo) {
66253
66441
  opts.logInfo.publisher = toText2(select3("publisher-name", jats.tree)) || null;
66254
66442
  opts.logInfo.journal = toText2(select3("journal-title", jats.tree)) || null;
@@ -66269,24 +66457,10 @@ async function jatsConvertTransform(data, opts) {
66269
66457
  }
66270
66458
  opts.logInfo.license = licenseString;
66271
66459
  }
66272
- const { frontmatter } = jats;
66273
66460
  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
66461
  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
- }
66462
+ pipe.stringify(copyNode((_c = jats.body) !== null && _c !== void 0 ? _c : { type: "body", children: [] }), file);
66463
+ const { tree, frontmatter } = file.result;
66290
66464
  if (opts === null || opts === void 0 ? void 0 : opts.logInfo) {
66291
66465
  opts.logInfo.figures = {
66292
66466
  body: selectAll2("fig", jats.body).length,
@@ -66316,17 +66490,30 @@ async function jatsConvertTransform(data, opts) {
66316
66490
  myst: selectAll2("footnoteDefinition", tree).length
66317
66491
  };
66318
66492
  }
66319
- return { tree, jats, references, frontmatter };
66493
+ return { tree, frontmatter };
66320
66494
  }
66321
66495
  async function jatsConvert(session, input, opts) {
66322
66496
  const logInfo = { jatsVersion: version_default3 };
66497
+ if (!input) {
66498
+ const xmls = import_node_fs7.default.readdirSync(".").filter((file) => import_node_path6.default.extname(file) === ".xml");
66499
+ if (xmls.length === 0) {
66500
+ throw new Error("No JATS xml file found in current directory; please specify input");
66501
+ }
66502
+ if (xmls.length > 1) {
66503
+ throw new Error("Multiple XML files found in current directory; please specify input");
66504
+ }
66505
+ input = xmls[0];
66506
+ }
66323
66507
  const dir = import_node_path6.default.dirname(input);
66324
66508
  const vfile2 = new VFile();
66325
66509
  vfile2.path = input;
66326
- const { tree, frontmatter } = await jatsConvertTransform(import_node_fs7.default.readFileSync(input).toString(), {
66510
+ const jats = new Jats(import_node_fs7.default.readFileSync(input).toString());
66511
+ const pmidCache = await getPMIDLookup(jats.references, dir);
66512
+ const { tree, frontmatter } = jatsConvertTransform(jats, {
66327
66513
  vfile: vfile2,
66328
66514
  dir,
66329
66515
  logInfo,
66516
+ pmidCache,
66330
66517
  dois: opts === null || opts === void 0 ? void 0 : opts.dois,
66331
66518
  bibtex: opts === null || opts === void 0 ? void 0 : opts.bibtex
66332
66519
  });
@@ -66355,7 +66542,7 @@ async function jatsConvert(session, input, opts) {
66355
66542
 
66356
66543
  // src/convert.ts
66357
66544
  function makeConvertCLI(program3) {
66358
- const command = new Command("convert").description("Convert JATS file to MyST mdast json").argument("<input>", "The JATS file").addOption(
66545
+ const command = new Command("convert").description("Convert JATS file to MyST mdast json").argument("[input]", "The JATS file").addOption(
66359
66546
  new Option(
66360
66547
  "--frontmatter <frontmatter>",
66361
66548
  "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.14";
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.14';
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.14",
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.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",
53
53
  "js-yaml": "^4.1.0",
54
54
  "unist-util-is": "^5.2.1",
55
55
  "unist-util-select": "^4.0.0"