jats-cli 1.0.12 → 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
@@ -6561,7 +6561,7 @@ var require_xml2js = __commonJS({
6561
6561
  var require_xml2json = __commonJS({
6562
6562
  "../../node_modules/xml-js/lib/xml2json.js"(exports, module2) {
6563
6563
  var helper = require_options_helper();
6564
- var xml2js2 = require_xml2js();
6564
+ var xml2js3 = require_xml2js();
6565
6565
  function validateOptions2(userOptions) {
6566
6566
  var options = helper.copyOptions(userOptions);
6567
6567
  helper.ensureSpacesExists(options);
@@ -6570,7 +6570,7 @@ var require_xml2json = __commonJS({
6570
6570
  module2.exports = function(xml, userOptions) {
6571
6571
  var options, js, json2, parentKey;
6572
6572
  options = validateOptions2(userOptions);
6573
- js = xml2js2(xml, options);
6573
+ js = xml2js3(xml, options);
6574
6574
  parentKey = "compact" in options && options.compact ? "_parent" : "parent";
6575
6575
  if ("addParent" in options && options.addParent) {
6576
6576
  json2 = JSON.stringify(js, function(k, v) {
@@ -6942,12 +6942,12 @@ var require_json2xml = __commonJS({
6942
6942
  // ../../node_modules/xml-js/lib/index.js
6943
6943
  var require_lib2 = __commonJS({
6944
6944
  "../../node_modules/xml-js/lib/index.js"(exports, module2) {
6945
- var xml2js2 = require_xml2js();
6945
+ var xml2js3 = require_xml2js();
6946
6946
  var xml2json = require_xml2json();
6947
6947
  var js2xml3 = require_js2xml();
6948
6948
  var json2xml = require_json2xml();
6949
6949
  module2.exports = {
6950
- xml2js: xml2js2,
6950
+ xml2js: xml2js3,
6951
6951
  xml2json,
6952
6952
  js2xml: js2xml3,
6953
6953
  json2xml
@@ -48999,7 +48999,7 @@ var {
48999
48999
  } = import_index.default;
49000
49000
 
49001
49001
  // src/version.ts
49002
- var version = "1.0.12";
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
@@ -56436,6 +56437,7 @@ var import_node_fs4 = __toESM(require("node:fs"), 1);
56436
56437
  var import_node_path3 = __toESM(require("node:path"), 1);
56437
56438
  var import_node_readline = __toESM(require("node:readline"), 1);
56438
56439
  var import_client_s32 = __toESM(require_dist_cjs71(), 1);
56440
+ var import_xml_js2 = __toESM(require_lib2(), 1);
56439
56441
 
56440
56442
  // ../jats-fetch/dist/utils.js
56441
56443
  var import_node_fs3 = __toESM(require("node:fs"), 1);
@@ -57789,6 +57791,7 @@ async function streamToFile(url, dest, fetcher) {
57789
57791
  // ../jats-fetch/dist/pubmed.js
57790
57792
  var EFETCH_URL = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi";
57791
57793
  var ESUMMARY_URL = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi";
57794
+ var OA_URL = "https://www.ncbi.nlm.nih.gov/pmc/utils/oa/oa.fcgi";
57792
57795
  var IDCONV_URL = "https://www.ncbi.nlm.nih.gov/pmc/utils/idconv/v1.0/";
57793
57796
  var LISTING_BASE_URL = "https://ftp.ncbi.nlm.nih.gov/pub/pmc/";
57794
57797
  var LISTING_URL = `${LISTING_BASE_URL}oa_file_list.csv`;
@@ -57811,42 +57814,52 @@ function normalizePMID(session, pmid) {
57811
57814
  }
57812
57815
  return pmid;
57813
57816
  }
57814
- async function convertPMID2PMCID(session, pmid, opts) {
57817
+ async function convertId(session, id, from, to, opts) {
57818
+ var _a, _b, _c;
57819
+ const toc = tic();
57820
+ const resp = await ((_a = opts === null || opts === void 0 ? void 0 : opts.fetcher) !== null && _a !== void 0 ? _a : defaultFetcher)(`${IDCONV_URL}?tool=jats-xml&format=json&ids=${id}`, "json");
57821
+ if (!resp.ok) {
57822
+ session.log.debug(`Failed to convert ${from} ID: ${id}`);
57823
+ return;
57824
+ }
57825
+ const data = await resp.json();
57826
+ const newId = (_c = (_b = data === null || data === void 0 ? void 0 : data.records) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c[to];
57827
+ if (newId) {
57828
+ session.log.debug(toc(`Used nih.gov to transform ${id} to ${newId} in %s.`));
57829
+ }
57830
+ return newId;
57831
+ }
57832
+ async function convertIds(session, ids, from, to, opts) {
57815
57833
  var _a, _b, _c;
57816
- pmid = normalizePMID(session, pmid);
57817
57834
  const toc = tic();
57818
- const resp = await ((_a = opts === null || opts === void 0 ? void 0 : opts.fetcher) !== null && _a !== void 0 ? _a : defaultFetcher)(`${IDCONV_URL}?tool=jats-xml&format=json&ids=${pmid}`, "json");
57835
+ const resp = await ((_a = opts === null || opts === void 0 ? void 0 : opts.fetcher) !== null && _a !== void 0 ? _a : defaultFetcher)(`${IDCONV_URL}?tool=jats-xml&format=json&ids=${ids.join(",")}`, "json");
57819
57836
  if (!resp.ok) {
57820
- session.log.debug(`Failed to convert PubMedID: ${pmid}`);
57837
+ session.log.debug(`Failed to convert ${from} ${ids.length} IDs`);
57821
57838
  return;
57822
57839
  }
57823
57840
  const data = await resp.json();
57824
- const pmcid = (_c = (_b = data === null || data === void 0 ? void 0 : data.records) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.pmcid;
57825
- session.log.debug(toc(`Used nih.gov to transform ${pmid} to ${pmcid} in %s.`));
57841
+ const entries = (_b = data === null || data === void 0 ? void 0 : data.records) === null || _b === void 0 ? void 0 : _b.filter((record) => !!record[from] && !!record[to]).map((record) => [record[from], record[to]]);
57842
+ const newIds = entries ? Object.fromEntries(entries) : {};
57843
+ session.log.debug(toc(`Used nih.gov to transform ${(_c = entries === null || entries === void 0 ? void 0 : entries.length) !== null && _c !== void 0 ? _c : 0}/${ids.length} ${from} to ${to} in %s.`));
57844
+ return newIds;
57845
+ }
57846
+ async function convertPMID2PMCID(session, pmid, opts) {
57847
+ pmid = normalizePMID(session, pmid);
57848
+ const pmcid = await convertId(session, pmid, "pmid", "pmcid", opts);
57826
57849
  return pmcid;
57827
57850
  }
57828
57851
  async function convertPMIDs2DOIs(session, pmids, opts) {
57829
- var _a, _b, _c, _d;
57852
+ var _a, _b, _c;
57830
57853
  pmids = [...new Set(pmids.map((pmid) => normalizePMID(session, pmid)))];
57831
- const pmDois = {};
57832
57854
  const toc = tic();
57833
- const idconvResp = await ((_a = opts === null || opts === void 0 ? void 0 : opts.fetcher) !== null && _a !== void 0 ? _a : defaultFetcher)(`${IDCONV_URL}?tool=jats-xml&format=json&ids=${pmids.join(",")}`, "json");
57834
- if (idconvResp.ok) {
57835
- const data = await idconvResp.json();
57836
- (_b = data === null || data === void 0 ? void 0 : data.records) === null || _b === void 0 ? void 0 : _b.forEach((record) => {
57837
- if (record.doi)
57838
- pmDois[record.pmid] = record.doi;
57839
- });
57840
- const pmDoiCount = Object.keys(pmDois).length;
57841
- if (pmDoiCount === pmids.length) {
57842
- session.log.debug(toc(`Used nih.gov to convert ${pmDoiCount} PMIDs to DOIs in %s.`));
57843
- return pmDois;
57844
- }
57855
+ const pmDois = (_a = await convertIds(session, pmids, "pmid", "doi", opts)) !== null && _a !== void 0 ? _a : {};
57856
+ if (Object.keys(pmDois).length === pmids.length) {
57857
+ return pmDois;
57845
57858
  }
57846
- const esummaryResp = await ((_c = opts === null || opts === void 0 ? void 0 : opts.fetcher) !== null && _c !== void 0 ? _c : defaultFetcher)(`${ESUMMARY_URL}?db=pubmed&format=json&id=${pmids.filter((pmid) => !pmDois[pmid]).join(",")}`, "json");
57859
+ const esummaryResp = await ((_b = opts === null || opts === void 0 ? void 0 : opts.fetcher) !== null && _b !== void 0 ? _b : defaultFetcher)(`${ESUMMARY_URL}?db=pubmed&format=json&id=${pmids.filter((pmid) => !pmDois[pmid]).join(",")}`, "json");
57847
57860
  if (esummaryResp.ok) {
57848
57861
  const data = await esummaryResp.json();
57849
- Object.entries((_d = data === null || data === void 0 ? void 0 : data.result) !== null && _d !== void 0 ? _d : {}).filter(([pmid]) => pmid !== "uids").forEach(([pmid, record]) => {
57862
+ Object.entries((_c = data === null || data === void 0 ? void 0 : data.result) !== null && _c !== void 0 ? _c : {}).filter(([pmid]) => pmid !== "uids").forEach(([pmid, record]) => {
57850
57863
  var _a2, _b2;
57851
57864
  const pmDoi = (_b2 = (_a2 = record.articleids) === null || _a2 === void 0 ? void 0 : _a2.find((articleid) => {
57852
57865
  return articleid.idtype === "doi";
@@ -57917,8 +57930,6 @@ async function getPubMedJatsFromS3(session, pmcid) {
57917
57930
  }
57918
57931
  }
57919
57932
  async function getListingsFile(session, dest, fetcher) {
57920
- if (!dest)
57921
- dest = __dirname;
57922
57933
  if (!import_node_path3.default.extname(dest))
57923
57934
  dest = import_node_path3.default.join(dest, LISTING_FILENAME);
57924
57935
  if (import_node_path3.default.extname(dest) !== ".csv") {
@@ -57963,19 +57974,37 @@ async function searchListingForPMC(listingFile, pmcid) {
57963
57974
  }
57964
57975
  throw new Error(`Article ${pmcid} not found in ${listingFile}`);
57965
57976
  }
57966
- async function downloadAndUnzipPMC(session, entry, outputDir, fetcher) {
57967
- const urlParts = entry.url.split("/");
57977
+ async function getDownloadMetadata(pmcid, fetcher) {
57978
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
57979
+ const resp = await (fetcher !== null && fetcher !== void 0 ? fetcher : defaultFetcher)(`${OA_URL}?format=tgz&id=${pmcid}`, "xml");
57980
+ if (!resp.ok) {
57981
+ throw new Error(`Bad response from ${OA_URL}`);
57982
+ }
57983
+ const oaMeta = (0, import_xml_js2.xml2js)(await resp.text(), { compact: true });
57984
+ if (((_c = (_b = (_a = oaMeta.OA) === null || _a === void 0 ? void 0 : _a.records) === null || _b === void 0 ? void 0 : _b._attributes) === null || _c === void 0 ? void 0 : _c["returned-count"]) !== "1") {
57985
+ throw new Error(`Bad response from ${OA_URL} - returned count is not 1`);
57986
+ }
57987
+ const url = (_h = (_g = (_f = (_e = (_d = oaMeta === null || oaMeta === void 0 ? void 0 : oaMeta.OA) === null || _d === void 0 ? void 0 : _d.records) === null || _e === void 0 ? void 0 : _e.record) === null || _f === void 0 ? void 0 : _f.link) === null || _g === void 0 ? void 0 : _g._attributes) === null || _h === void 0 ? void 0 : _h.href;
57988
+ if (!url) {
57989
+ throw new Error(`Bad response from ${OA_URL} - href is not available`);
57990
+ }
57991
+ const { citation, license } = (_m = (_l = (_k = (_j = oaMeta.OA) === null || _j === void 0 ? void 0 : _j.records) === null || _k === void 0 ? void 0 : _k.record) === null || _l === void 0 ? void 0 : _l._attributes) !== null && _m !== void 0 ? _m : {};
57992
+ return { url, citation, license };
57993
+ }
57994
+ async function downloadAndUnzipPMC(session, url, outputDir, fetcher) {
57995
+ url = url.replace(/^ftp:/, "https:");
57996
+ const urlParts = url.split("/");
57968
57997
  const filename = urlParts[urlParts.length - 1];
57969
57998
  const dest = import_node_path3.default.join(outputDir, filename);
57970
57999
  if (!import_node_fs4.default.existsSync(outputDir)) {
57971
58000
  import_node_fs4.default.mkdirSync(outputDir, { recursive: true });
57972
58001
  }
57973
58002
  if (!import_node_fs4.default.existsSync(dest)) {
57974
- session.log.info(`Downloading PMC data from ${entry.url}`);
57975
- await streamToFile(`${LISTING_BASE_URL}${entry.url}`, dest, fetcher);
58003
+ session.log.info(`Downloading PMC data from ${url}`);
58004
+ await streamToFile(url, dest, fetcher);
57976
58005
  }
57977
58006
  if (!import_node_fs4.default.existsSync(dest)) {
57978
- throw new Error(`Unable to download ${entry.url}`);
58007
+ throw new Error(`Unable to download ${url}`);
57979
58008
  }
57980
58009
  session.log.info(`Extracting PMC data from ${dest} to ${outputDir}`);
57981
58010
  const unzip = makeExecutable(`tar -xf ${dest} -C ${outputDir}`, session.log);
@@ -57995,9 +58024,28 @@ async function downloadAndUnzipPMC(session, entry, outputDir, fetcher) {
57995
58024
  import_node_fs4.default.rmdirSync(zipDir);
57996
58025
  }
57997
58026
  async function getDataFromPMC(session, pmcid, outputDir, listing, fetcher) {
57998
- const listingFile = await getListingsFile(session, listing, fetcher);
57999
- const entry = await searchListingForPMC(listingFile, pmcid);
58000
- await downloadAndUnzipPMC(session, entry, outputDir, fetcher);
58027
+ let url;
58028
+ if (pmcid.endsWith(".tar.gz")) {
58029
+ url = pmcid;
58030
+ } else {
58031
+ if (!pmcid.startsWith("PMC")) {
58032
+ throw new Error("Data may only be downloaded for PMC articles");
58033
+ }
58034
+ try {
58035
+ const metadata = await getDownloadMetadata(pmcid);
58036
+ url = metadata.url;
58037
+ } catch {
58038
+ if (listing) {
58039
+ const listingFile = await getListingsFile(session, listing, fetcher);
58040
+ const entry = await searchListingForPMC(listingFile, pmcid);
58041
+ url = `${LISTING_BASE_URL}${entry.url}`;
58042
+ }
58043
+ }
58044
+ }
58045
+ if (!url) {
58046
+ throw new Error(`Unable to find PMC data download url for: ${pmcid}`);
58047
+ }
58048
+ await downloadAndUnzipPMC(session, url, outputDir, fetcher);
58001
58049
  }
58002
58050
  async function getPubMedJatsFromData(session, pmcid, outputDir, listing, fetcher) {
58003
58051
  await getDataFromPMC(session, pmcid, outputDir, listing, fetcher);
@@ -58149,22 +58197,40 @@ async function downloadJatsFromUrl(session, urlOrDoi, opts = {}) {
58149
58197
  return { success: false, source: urlOrDoi };
58150
58198
  }
58151
58199
  async function jatsFetch(session, input, opts) {
58152
- var _a, _b;
58200
+ var _a;
58153
58201
  if (input === "listing" && !opts.data && !(opts.output && opts.listing)) {
58154
- const dest = await getListingsFile(session, (_a = opts.output) !== null && _a !== void 0 ? _a : opts.listing);
58202
+ const inputDest = (_a = opts.output) !== null && _a !== void 0 ? _a : opts.listing;
58203
+ if (!inputDest) {
58204
+ throw new Error("Destination for listing file must be specified");
58205
+ }
58206
+ const dest = await getListingsFile(session, inputDest);
58155
58207
  session.log.info(`PMC Open Access listing saved to ${dest}`);
58156
58208
  return;
58157
58209
  }
58158
- let output = (_b = opts.output) !== null && _b !== void 0 ? _b : opts.data ? `${input}` : ".";
58210
+ let output = opts.output;
58211
+ let filename;
58212
+ if (input.endsWith(".tar.gz")) {
58213
+ opts.data = true;
58214
+ const foldername = input.split("/").slice(-1)[0].slice(0, -".tar.gz".length);
58215
+ filename = `${foldername}.xml`;
58216
+ if (!output) {
58217
+ output = foldername;
58218
+ }
58219
+ }
58220
+ if (!output)
58221
+ output = opts.data ? `${input}` : ".";
58159
58222
  if (!import_node_path4.default.extname(output)) {
58160
- const filename = input.startsWith("PMC") ? `${input}.xml` : "jats.xml";
58223
+ filename = filename !== null && filename !== void 0 ? filename : input.startsWith("PMC") ? `${input}.xml` : "jats.xml";
58161
58224
  output = import_node_path4.default.join(output, filename);
58162
58225
  }
58163
58226
  if (import_node_path4.default.extname(output) && ![".xml", ".jats"].includes(import_node_path4.default.extname(output).toLowerCase())) {
58164
58227
  throw new Error(`Output must be an XML file or a directory`);
58165
58228
  }
58166
58229
  let result;
58167
- if (input.startsWith("PMC")) {
58230
+ if (opts.data) {
58231
+ result = await getPubMedJatsFromData(session, input, import_node_path4.default.dirname(output), opts.listing);
58232
+ }
58233
+ if (!(result === null || result === void 0 ? void 0 : result.data) && input.startsWith("PMC")) {
58168
58234
  result = await getPubMedJatsFromS3(session, input);
58169
58235
  }
58170
58236
  if (!(result === null || result === void 0 ? void 0 : result.data)) {
@@ -58183,17 +58249,10 @@ async function jatsFetch(session, input, opts) {
58183
58249
  }
58184
58250
  import_node_fs5.default.writeFileSync(output, result.data);
58185
58251
  session.log.info(`JATS written to ${output}`);
58186
- if (!opts.data)
58187
- return;
58188
- if (input.startsWith("PMC")) {
58189
- await getDataFromPMC(session, input, import_node_path4.default.dirname(output), opts.listing);
58190
- } else {
58191
- session.log.error("Data may only be downloaded for PMC articles");
58192
- }
58193
58252
  }
58194
58253
 
58195
58254
  // ../jats-xml/dist/jats.js
58196
- var import_xml_js2 = __toESM(require_lib2(), 1);
58255
+ var import_xml_js3 = __toESM(require_lib2(), 1);
58197
58256
 
58198
58257
  // ../jats-xml/node_modules/unist-util-is/lib/index.js
58199
58258
  var convert2 = (
@@ -58525,7 +58584,7 @@ var Jats = class {
58525
58584
  if (opts === null || opts === void 0 ? void 0 : opts.source)
58526
58585
  this.source = opts.source;
58527
58586
  try {
58528
- this.raw = (0, import_xml_js2.xml2js)(data, { compact: false });
58587
+ this.raw = (0, import_xml_js3.xml2js)(data, { compact: false });
58529
58588
  } catch (error) {
58530
58589
  throw new Error("Problem parsing the JATS document, please ensure it is XML");
58531
58590
  }
@@ -64768,7 +64827,7 @@ var u = (
64768
64827
 
64769
64828
  // ../jats-convert/dist/index.js
64770
64829
  var import_mathml_to_latex = __toESM(require_bundle_min(), 1);
64771
- var import_xml_js3 = __toESM(require_lib2(), 1);
64830
+ var import_xml_js4 = __toESM(require_lib2(), 1);
64772
64831
 
64773
64832
  // ../jats-convert/dist/transforms/admonitions.js
64774
64833
  function admonitionTransform(tree, file) {
@@ -64970,8 +65029,15 @@ function blockNestingTransform(tree) {
64970
65029
  }
64971
65030
 
64972
65031
  // ../jats-convert/dist/transforms/sections.js
65032
+ var SECTION_TYPES = ["sec", "ack", "app"];
64973
65033
  function isSection(node) {
64974
- 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__");
64975
65041
  }
64976
65042
  function recurseSections(tree, depth = 1, titleType) {
64977
65043
  var _a;
@@ -64999,11 +65065,15 @@ function recurseSections(tree, depth = 1, titleType) {
64999
65065
  }
65000
65066
  if (sec.type === "ack")
65001
65067
  sec.part = "acknowledgments";
65068
+ if (sec.type === "app")
65069
+ sec.part = "appendix";
65070
+ sec.type = "sec";
65002
65071
  recurseSections(sec, depth + 1, titleType);
65003
65072
  });
65004
65073
  }
65005
65074
  function sectionTransform(tree, titleType) {
65006
65075
  var _a;
65076
+ liftApps(tree);
65007
65077
  recurseSections(tree, 1, titleType);
65008
65078
  remove(tree, "__delete__");
65009
65079
  const topSections = (_a = tree.children) === null || _a === void 0 ? void 0 : _a.filter((n) => isSection(n));
@@ -65051,6 +65121,38 @@ function abbreviationSectionTransform(tree, frontmatter) {
65051
65121
  });
65052
65122
  remove(tree, "__delete__");
65053
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
+ }
65054
65156
 
65055
65157
  // ../jats-convert/dist/transforms/abstract.js
65056
65158
  function abstractTransform(tree) {
@@ -65090,28 +65192,26 @@ function descriptionFromAbstract(abstract) {
65090
65192
  return `${firstSentence} ${secondSentence}`;
65091
65193
  }
65092
65194
 
65093
- // ../jats-convert/dist/transforms/citations.js
65094
- function citationToMixedCitation(tree) {
65095
- selectAll2("citation", tree).forEach((node) => {
65096
- node.type = "mixed-citation";
65097
- });
65098
- }
65099
-
65100
65195
  // ../jats-convert/dist/transforms/footnotes.js
65101
- function backToBodyTransform(jats) {
65102
- var _a, _b;
65103
- if (!jats.back)
65196
+ function backToBodyTransform(body, back) {
65197
+ var _a;
65198
+ if (!back)
65104
65199
  return;
65105
- const backNodes = (_a = jats.back.children) === null || _a === void 0 ? void 0 : _a.filter((node) => {
65106
- 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);
65107
65202
  });
65108
- 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)
65109
65204
  return;
65110
- jats.body.children.push({ type: "hr" }, ...copyNode(backNodes));
65111
- backNodes.forEach((node) => {
65112
- 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";
65113
65214
  });
65114
- remove(jats.back, "__delete__");
65115
65215
  }
65116
65216
 
65117
65217
  // ../../node_modules/dotenv/config.js
@@ -65270,6 +65370,7 @@ function bibtexFromCite(key, cite, counts, doi2) {
65270
65370
  }
65271
65371
  if (bibtexLines.length === 1) {
65272
65372
  counts.unprocessed += 1;
65373
+ bibtexLines.push(` note = {${toText2(cite)}}`);
65273
65374
  } else {
65274
65375
  counts.bibtex += 1;
65275
65376
  counts.lostRefItems.push(...skipped);
@@ -65322,7 +65423,7 @@ function processRef(ref, pmidCache, fnCount, counts, dois) {
65322
65423
  const footnotes = [];
65323
65424
  const bibtexEntries = [];
65324
65425
  (_b = ref.children) === null || _b === void 0 ? void 0 : _b.forEach((child) => {
65325
- if (["element-citation", "mixed-citation"].includes(child.type)) {
65426
+ if (["element-citation", "mixed-citation", "citation"].includes(child.type)) {
65326
65427
  if (!toText2(child))
65327
65428
  return;
65328
65429
  const cite = processRefCite(child, identifier, pmidCache, counts, dois);
@@ -65343,15 +65444,14 @@ function processRef(ref, pmidCache, fnCount, counts, dois) {
65343
65444
  });
65344
65445
  return { refLookup, footnotes, bibtexEntries };
65345
65446
  }
65346
- async function processJatsReferences(jats, opts) {
65447
+ function processJatsReferences(body, references, opts) {
65347
65448
  var _a, _b;
65348
65449
  const dir = (_a = opts === null || opts === void 0 ? void 0 : opts.dir) !== null && _a !== void 0 ? _a : ".";
65349
65450
  const bibfile = import_node_path5.default.join(dir, "main.bib");
65350
- const refs = jats.references;
65451
+ const pmidCache = (_b = opts === null || opts === void 0 ? void 0 : opts.pmidCache) !== null && _b !== void 0 ? _b : {};
65351
65452
  let refLookup = {};
65352
65453
  const footnotes = [];
65353
65454
  const bibtexEntries = [];
65354
- const pmidCache = await getPMIDLookup(refs, dir);
65355
65455
  const counts = {
65356
65456
  dois: 0,
65357
65457
  bibtex: 0,
@@ -65359,7 +65459,7 @@ async function processJatsReferences(jats, opts) {
65359
65459
  lostRefs: [],
65360
65460
  lostRefItems: []
65361
65461
  };
65362
- refs.forEach((ref) => {
65462
+ references.forEach((ref) => {
65363
65463
  const { refLookup: newRefLookup, footnotes: newFootnotes, bibtexEntries: newBibtexEntries } = processRef(ref, pmidCache, footnotes.length + 1, counts, opts === null || opts === void 0 ? void 0 : opts.dois);
65364
65464
  refLookup = { ...refLookup, ...newRefLookup };
65365
65465
  bibtexEntries.push(...newBibtexEntries);
@@ -65367,7 +65467,7 @@ async function processJatsReferences(jats, opts) {
65367
65467
  });
65368
65468
  if (opts === null || opts === void 0 ? void 0 : opts.logInfo) {
65369
65469
  opts.logInfo.references = {
65370
- total: refs.length,
65470
+ total: references.length,
65371
65471
  dois: counts.dois,
65372
65472
  bibtex: counts.bibtex,
65373
65473
  footnotes: footnotes.length,
@@ -65396,7 +65496,7 @@ async function processJatsReferences(jats, opts) {
65396
65496
  import_node_fs6.default.writeFileSync(bibfile, bibtexEntries.join("\n\n"));
65397
65497
  }
65398
65498
  if (footnotes.length) {
65399
- (_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 });
65400
65500
  }
65401
65501
  return refLookup;
65402
65502
  }
@@ -65462,18 +65562,18 @@ async function resolveJatsCitations(tree, refLookup) {
65462
65562
  }
65463
65563
 
65464
65564
  // ../jats-convert/dist/transforms/index.js
65465
- function basicTransformations(tree, file) {
65466
- sectionTransform(tree);
65467
- typographyTransform(tree);
65468
- admonitionTransform(tree, file);
65469
- figCaptionTitleTransform(tree);
65565
+ function basicTransformations(body, file) {
65566
+ sectionTransform(body);
65567
+ typographyTransform(body);
65568
+ admonitionTransform(body, file);
65569
+ figCaptionTitleTransform(body);
65470
65570
  }
65471
- function journalTransforms(tree) {
65472
- graphicToBioRxivUrl(tree);
65571
+ function journalTransforms(body) {
65572
+ graphicToBioRxivUrl(body);
65473
65573
  }
65474
65574
 
65475
65575
  // ../jats-convert/dist/version.js
65476
- var version3 = "1.0.12";
65576
+ var version3 = "1.0.14";
65477
65577
  var version_default3 = version3;
65478
65578
 
65479
65579
  // ../jats-convert/dist/myst/inlineCitations.js
@@ -65613,6 +65713,35 @@ function expandHyphenatedCites(tree, referenceList) {
65613
65713
  });
65614
65714
  remove(tree, "__delete__");
65615
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
+ }
65616
65745
  function inlineCitationsTransform(tree, referenceIds) {
65617
65746
  let before = "";
65618
65747
  let current = JSON.stringify(tree);
@@ -65625,27 +65754,112 @@ function inlineCitationsTransform(tree, referenceIds) {
65625
65754
  removeCiteSeparators(tree);
65626
65755
  expandHyphenatedCites(tree, referenceIds);
65627
65756
  removeCiteParentheses(tree);
65757
+ removeCiteSuperscript(tree);
65758
+ ensureSpaceBeforeCite(tree);
65628
65759
  current = JSON.stringify(tree);
65629
65760
  }
65630
65761
  }
65631
65762
 
65632
65763
  // ../jats-convert/dist/transforms/supplementary.js
65633
- function floatToEndTransform(jats) {
65764
+ function floatToEndTransform(body) {
65634
65765
  var _a;
65635
- if (!jats.body)
65636
- return;
65637
- const floatSupplementaryMaterial = selectAll2("supplementary-material[position=float]", jats.body);
65766
+ const floatSupplementaryMaterial = selectAll2("supplementary-material[position=float]", body);
65638
65767
  if (floatSupplementaryMaterial.length === 0)
65639
65768
  return;
65640
- (_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" });
65641
65770
  floatSupplementaryMaterial.forEach((node) => {
65642
- var _a2, _b;
65771
+ var _a2;
65643
65772
  const copy = copyNode2(node);
65644
65773
  delete copy.position;
65645
- (_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);
65646
65775
  node.type = "__delete__";
65647
65776
  });
65648
- 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;
65649
65863
  }
65650
65864
 
65651
65865
  // ../jats-convert/dist/index.js
@@ -65694,7 +65908,7 @@ function texMathFromNode(node) {
65694
65908
  });
65695
65909
  }
65696
65910
  });
65697
- return import_mathml_to_latex.MathMLToLaTeX.convert((0, import_xml_js3.js2xml)({ type: "element", name: "root", elements: [math] }));
65911
+ return import_mathml_to_latex.MathMLToLaTeX.convert((0, import_xml_js4.js2xml)({ type: "element", name: "root", elements: [math] }));
65698
65912
  }
65699
65913
  var handlers = {
65700
65914
  body(node, state2) {
@@ -65707,10 +65921,12 @@ var handlers = {
65707
65921
  state2.renderInline(node, "paragraph");
65708
65922
  },
65709
65923
  heading(node, state2) {
65924
+ var _a;
65925
+ const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
65710
65926
  state2.renderInline(node, "heading", {
65711
65927
  enumerated: true,
65712
- label: node.id,
65713
- identifier: node.id,
65928
+ label,
65929
+ identifier,
65714
65930
  depth: node.depth
65715
65931
  });
65716
65932
  },
@@ -65746,27 +65962,39 @@ var handlers = {
65746
65962
  state2.renderInline(node, "listItem");
65747
65963
  },
65748
65964
  ["inline-formula"](node, state2) {
65965
+ var _a;
65749
65966
  const texMath = texMathFromNode(node);
65750
65967
  if (texMath) {
65968
+ const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
65751
65969
  state2.addLeaf("inlineMath", {
65752
65970
  value: texMath,
65753
- label: node.id,
65754
- identifier: node.id
65971
+ label,
65972
+ identifier
65755
65973
  });
65756
65974
  } else {
65757
65975
  state2.renderChildren(node);
65758
65976
  }
65759
65977
  },
65760
65978
  ["disp-formula"](node, state2) {
65979
+ var _a;
65761
65980
  const texMath = texMathFromNode(node);
65981
+ const { label, identifier } = (_a = normalizeLabel(node.id)) !== null && _a !== void 0 ? _a : {};
65762
65982
  if (texMath) {
65763
65983
  state2.addLeaf("math", {
65764
65984
  value: texMath,
65765
- label: node.id,
65766
- identifier: node.id
65985
+ label,
65986
+ identifier
65767
65987
  });
65768
65988
  } else {
65989
+ if (node.id) {
65990
+ state2.openNode("div", { label, identifier });
65991
+ }
65992
+ state2.openNode("paragraph");
65769
65993
  state2.renderChildren(node);
65994
+ state2.closeNode();
65995
+ if (node.id) {
65996
+ state2.closeNode();
65997
+ }
65770
65998
  }
65771
65999
  },
65772
66000
  bold(node, state2) {
@@ -65809,7 +66037,15 @@ var handlers = {
65809
66037
  state2.renderInline(node, "link", { url: node["xlink:href"] });
65810
66038
  },
65811
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
+ }
65812
66045
  state2.renderInline(node, "admonition", { kind: "info" });
66046
+ if (node.id) {
66047
+ state2.closeNode();
66048
+ }
65813
66049
  },
65814
66050
  admonitionTitle(node, state2) {
65815
66051
  state2.renderInline(node, "admonitionTitle");
@@ -65980,6 +66216,9 @@ var handlers = {
65980
66216
  kind: "narrative"
65981
66217
  });
65982
66218
  return;
66219
+ case RefType.app:
66220
+ case RefType.boxedText:
66221
+ case RefType.media:
65983
66222
  case RefType.supplementaryMaterial:
65984
66223
  case RefType.sec:
65985
66224
  case RefType.fig:
@@ -66012,6 +66251,20 @@ var handlers = {
66012
66251
  state2.closeNode();
66013
66252
  }
66014
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
+ },
66015
66268
  media(node, state2) {
66016
66269
  state2.renderInline(node, "link", { url: node["xlink:href"] });
66017
66270
  },
@@ -66021,6 +66274,9 @@ var handlers = {
66021
66274
  caption(node, state2) {
66022
66275
  state2.renderChildren(node);
66023
66276
  },
66277
+ email(node, state2) {
66278
+ state2.renderInline(node, "link", { url: `mailto:${toText2(node)}` });
66279
+ },
66024
66280
  // These nodes can be safely ignored
66025
66281
  label() {
66026
66282
  },
@@ -66123,63 +66379,54 @@ var JatsParser = class {
66123
66379
  }
66124
66380
  };
66125
66381
  var jatsConvertPlugin = function(jats, opts) {
66126
- this.Compiler = (node, file) => {
66127
- if (jats.abstract)
66382
+ this.Compiler = (body, file) => {
66383
+ if (jats.abstract) {
66128
66384
  abstractTransform(jats.abstract);
66129
- const tree = jats.abstract ? {
66130
- type: "root",
66131
- children: [
66385
+ body.children = [
66132
66386
  u("block", { part: "abstract" }, copyNode(jats.abstract).children),
66133
- ...copyNode(node).children
66134
- ]
66135
- } : copyNode(node);
66387
+ ...body.children
66388
+ ];
66389
+ }
66136
66390
  const floatsGroup = selectAll2("floats-group", jats.tree);
66137
66391
  if (floatsGroup.length > 0) {
66138
66392
  floatsGroup.forEach((g) => {
66139
- tree.children.push(...g.children);
66393
+ body.children.push(...g.children);
66140
66394
  });
66141
66395
  }
66142
- basicTransformations(tree, file);
66143
- citationToMixedCitation(tree);
66144
- journalTransforms(tree);
66145
- const state2 = new JatsParser(file, jats, opts !== null && opts !== void 0 ? opts : { handlers });
66146
- 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);
66147
66404
  while (state2.stack.length > 1)
66148
66405
  state2.closeNode();
66406
+ const tree = state2.stack[0];
66149
66407
  if (state2.unhandled.length && (opts === null || opts === void 0 ? void 0 : opts.logInfo)) {
66150
66408
  opts.logInfo.unhandled = [...new Set(state2.unhandled)];
66151
66409
  }
66152
- const referenceData = Object.fromEntries(jats.references.map((bibr) => {
66153
- const id = bibr.id;
66154
- const names = selectAll2("name,string-name", bibr).map((n) => `${toText2(select3("surname", n))}, ${toText2(select3("given-names", n))}`).join(", ");
66155
- const year = toText2(select3("year", bibr));
66156
- const title = toText2(select3("article-title", bibr));
66157
- const source = toText2(select3("source", bibr));
66158
- const volume = toText2(select3("volume", bibr));
66159
- const fpage = toText2(select3("fpage", bibr));
66160
- const lpage = toText2(select3("lpage", bibr));
66161
- const doiElement = selectAll2("ext-link,[pub-id-type=doi]", bibr).find((e2) => doi.validate(toText2(e2)));
66162
- const doiString = doiElement ? toText2(doiElement) : void 0;
66163
- const doiLink = doiString ? ` <a href=${doi.buildUrl(doiString)}>${doiString}</a>` : "";
66164
- return [
66165
- id,
66166
- {
66167
- html: `${names}. (${year}). ${title}. <i>${source}</i>, <i>${volume}</i>, ${fpage}-${lpage}.${doiLink}`,
66168
- doi: doiString
66169
- }
66170
- ];
66171
- }));
66172
- const referenceOrder = [];
66173
- const xrefs = selectAll2("xref[ref-type=bibr]", jats.body);
66174
- xrefs.forEach((xref) => {
66175
- const rid = xref.rid;
66176
- if (!referenceOrder.includes(rid)) {
66177
- referenceOrder.push(rid);
66178
- }
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";
66179
66423
  });
66424
+ if (abstract) {
66425
+ frontmatter.description = descriptionFromAbstract(toText2(abstract));
66426
+ }
66180
66427
  const result = {
66181
- references: { order: referenceOrder, data: referenceData },
66182
- tree: state2.stack[0]
66428
+ tree,
66429
+ frontmatter
66183
66430
  };
66184
66431
  file.result = result;
66185
66432
  return file;
@@ -66188,9 +66435,8 @@ var jatsConvertPlugin = function(jats, opts) {
66188
66435
  return node;
66189
66436
  };
66190
66437
  };
66191
- async function jatsConvertTransform(data, opts) {
66438
+ function jatsConvertTransform(jats, opts) {
66192
66439
  var _a, _b, _c;
66193
- const jats = typeof data === "string" ? new Jats(data) : data;
66194
66440
  if (opts === null || opts === void 0 ? void 0 : opts.logInfo) {
66195
66441
  opts.logInfo.publisher = toText2(select3("publisher-name", jats.tree)) || null;
66196
66442
  opts.logInfo.journal = toText2(select3("journal-title", jats.tree)) || null;
@@ -66211,24 +66457,10 @@ async function jatsConvertTransform(data, opts) {
66211
66457
  }
66212
66458
  opts.logInfo.license = licenseString;
66213
66459
  }
66214
- const { frontmatter } = jats;
66215
66460
  const file = (_b = opts === null || opts === void 0 ? void 0 : opts.vfile) !== null && _b !== void 0 ? _b : new VFile();
66216
- const refLookup = await processJatsReferences(jats, opts);
66217
- floatToEndTransform(jats);
66218
- backToBodyTransform(jats);
66219
66461
  const pipe = unified().use(jatsConvertPlugin, jats, opts);
66220
- pipe.stringify((_c = jats.body) !== null && _c !== void 0 ? _c : { type: "body", children: [] }, file);
66221
- const references = file.result.references;
66222
- const tree = file.result.tree;
66223
- resolveJatsCitations(tree, refLookup);
66224
- inlineCitationsTransform(tree, [...Object.keys(references.data)]);
66225
- abbreviationSectionTransform(tree, frontmatter);
66226
- const abstract = selectAll2("block", tree).find((node) => {
66227
- return node.data && node.data.part === "abstract";
66228
- });
66229
- if (abstract) {
66230
- frontmatter.description = descriptionFromAbstract(toText2(abstract));
66231
- }
66462
+ pipe.stringify(copyNode((_c = jats.body) !== null && _c !== void 0 ? _c : { type: "body", children: [] }), file);
66463
+ const { tree, frontmatter } = file.result;
66232
66464
  if (opts === null || opts === void 0 ? void 0 : opts.logInfo) {
66233
66465
  opts.logInfo.figures = {
66234
66466
  body: selectAll2("fig", jats.body).length,
@@ -66258,17 +66490,30 @@ async function jatsConvertTransform(data, opts) {
66258
66490
  myst: selectAll2("footnoteDefinition", tree).length
66259
66491
  };
66260
66492
  }
66261
- return { tree, jats, references, frontmatter };
66493
+ return { tree, frontmatter };
66262
66494
  }
66263
66495
  async function jatsConvert(session, input, opts) {
66264
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
+ }
66265
66507
  const dir = import_node_path6.default.dirname(input);
66266
66508
  const vfile2 = new VFile();
66267
66509
  vfile2.path = input;
66268
- 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, {
66269
66513
  vfile: vfile2,
66270
66514
  dir,
66271
66515
  logInfo,
66516
+ pmidCache,
66272
66517
  dois: opts === null || opts === void 0 ? void 0 : opts.dois,
66273
66518
  bibtex: opts === null || opts === void 0 ? void 0 : opts.bibtex
66274
66519
  });
@@ -66297,7 +66542,7 @@ async function jatsConvert(session, input, opts) {
66297
66542
 
66298
66543
  // src/convert.ts
66299
66544
  function makeConvertCLI(program3) {
66300
- 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(
66301
66546
  new Option(
66302
66547
  "--frontmatter <frontmatter>",
66303
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.12";
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.12';
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.12",
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.12",
49
- "jats-fetch": "^1.0.12",
50
- "jats-tags": "^1.0.12",
51
- "jats-utils": "^1.0.12",
52
- "jats-xml": "^1.0.12",
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"