@manuscripts/transform 3.0.66 → 3.0.68-LEAN-4574.2

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.
Files changed (44) hide show
  1. package/dist/cjs/index.js +2 -3
  2. package/dist/cjs/jats/exporter/citeproc.js +164 -0
  3. package/dist/cjs/jats/exporter/jats-exporter.js +85 -196
  4. package/dist/cjs/jats/importer/jats-dom-parser.js +50 -63
  5. package/dist/cjs/lib/citeproc.js +13 -0
  6. package/dist/cjs/lib/credit-roles.js +76 -0
  7. package/dist/cjs/lib/utils.js +17 -1
  8. package/dist/cjs/schema/index.js +1 -0
  9. package/dist/cjs/schema/nodes/bibliography_element.js +3 -1
  10. package/dist/cjs/schema/nodes/bibliography_item.js +3 -7
  11. package/dist/cjs/schema/nodes/comment.js +3 -1
  12. package/dist/cjs/schema/nodes/contributor.js +1 -0
  13. package/dist/cjs/schema/nodes/list.js +3 -45
  14. package/dist/cjs/version.js +1 -1
  15. package/dist/es/index.js +1 -1
  16. package/dist/es/jats/exporter/citeproc.js +156 -0
  17. package/dist/es/jats/exporter/jats-exporter.js +63 -196
  18. package/dist/es/jats/importer/jats-dom-parser.js +52 -65
  19. package/dist/es/lib/citeproc.js +9 -0
  20. package/dist/es/lib/credit-roles.js +73 -0
  21. package/dist/es/lib/utils.js +15 -0
  22. package/dist/es/schema/index.js +1 -0
  23. package/dist/es/schema/nodes/bibliography_element.js +1 -0
  24. package/dist/es/schema/nodes/bibliography_item.js +1 -6
  25. package/dist/es/schema/nodes/comment.js +1 -0
  26. package/dist/es/schema/nodes/contributor.js +1 -0
  27. package/dist/es/schema/nodes/list.js +2 -42
  28. package/dist/es/version.js +1 -1
  29. package/dist/types/index.d.ts +1 -1
  30. package/dist/types/jats/exporter/citeproc.d.ts +18 -0
  31. package/dist/types/jats/exporter/jats-exporter.d.ts +5 -29
  32. package/dist/types/jats/importer/jats-dom-parser.d.ts +2 -2
  33. package/dist/types/lib/citeproc.d.ts +3 -0
  34. package/dist/types/lib/credit-roles.d.ts +32 -0
  35. package/dist/types/lib/utils.d.ts +2 -1
  36. package/dist/types/schema/index.d.ts +1 -0
  37. package/dist/types/schema/nodes/bibliography_element.d.ts +1 -0
  38. package/dist/types/schema/nodes/bibliography_item.d.ts +9 -9
  39. package/dist/types/schema/nodes/citation.d.ts +3 -4
  40. package/dist/types/schema/nodes/comment.d.ts +3 -3
  41. package/dist/types/schema/nodes/contributor.d.ts +6 -0
  42. package/dist/types/schema/nodes/list.d.ts +5 -11
  43. package/dist/types/version.d.ts +1 -1
  44. package/package.json +5 -7
@@ -19,7 +19,6 @@ exports.JATSDOMParser = void 0;
19
19
  const json_schema_1 = require("@manuscripts/json-schema");
20
20
  const prosemirror_model_1 = require("prosemirror-model");
21
21
  const utils_1 = require("../../lib/utils");
22
- const schema_1 = require("../../schema");
23
22
  const jats_comments_1 = require("./jats-comments");
24
23
  class JATSDOMParser {
25
24
  constructor(sectionCategories, schema) {
@@ -131,11 +130,22 @@ class JATSDOMParser {
131
130
  this.getAddressLine = (element, index) => {
132
131
  return ((0, utils_1.getTrimmedTextContent)(element, `addr-line:nth-of-type(${index})`) || '');
133
132
  };
134
- this.choosePublicationType = (element) => {
135
- var _a;
136
- const citationElement = element.querySelector('element-citation, mixed-citation');
137
- const type = citationElement === null || citationElement === void 0 ? void 0 : citationElement.getAttribute('publication-type');
138
- return type ? (_a = schema_1.publicationTypeToPM[type]) !== null && _a !== void 0 ? _a : type : 'article-journal';
133
+ this.getRefType = (element) => {
134
+ const citation = element.querySelector('element-citation, mixed-citation');
135
+ const type = citation === null || citation === void 0 ? void 0 : citation.getAttribute('publication-type');
136
+ if (!type) {
137
+ return 'article-journal';
138
+ }
139
+ switch (type) {
140
+ case 'journal':
141
+ return 'article-journal';
142
+ case 'web':
143
+ return 'webpage';
144
+ case 'data':
145
+ return 'dataset';
146
+ default:
147
+ return type;
148
+ }
139
149
  };
140
150
  this.getFigContent = (node) => {
141
151
  const element = node;
@@ -154,18 +164,6 @@ class JATSDOMParser {
154
164
  }
155
165
  return prosemirror_model_1.Fragment.from(content);
156
166
  };
157
- this.parseRefLiteral = (element) => {
158
- var _a;
159
- const mixedCitation = element.querySelector('mixed-citation');
160
- const hasDirectTextNodeWithLetters = Array.from((_a = mixedCitation === null || mixedCitation === void 0 ? void 0 : mixedCitation.childNodes) !== null && _a !== void 0 ? _a : []).some((node) => {
161
- var _a;
162
- return node.nodeType === Node.TEXT_NODE &&
163
- ((_a = node.textContent) === null || _a === void 0 ? void 0 : _a.match(/[A-Za-z]+/g));
164
- });
165
- if (hasDirectTextNodeWithLetters) {
166
- return (0, utils_1.getTrimmedTextContent)(mixedCitation);
167
- }
168
- };
169
167
  this.parseRefPages = (element) => {
170
168
  const fpage = (0, utils_1.getTrimmedTextContent)(element, 'fpage');
171
169
  const lpage = (0, utils_1.getTrimmedTextContent)(element, 'lpage');
@@ -174,10 +172,9 @@ class JATSDOMParser {
174
172
  }
175
173
  };
176
174
  this.parseRef = (element) => {
177
- var _a, _b;
178
175
  return {
179
176
  id: element.id,
180
- type: this.choosePublicationType(element),
177
+ type: this.getRefType(element),
181
178
  comment: (0, utils_1.getTrimmedTextContent)(element, 'comment'),
182
179
  volume: (0, utils_1.getTrimmedTextContent)(element, 'volume'),
183
180
  issue: (0, utils_1.getTrimmedTextContent)(element, 'issue'),
@@ -195,23 +192,13 @@ class JATSDOMParser {
195
192
  institution: (0, utils_1.getTrimmedTextContent)(element, 'institution'),
196
193
  locator: (0, utils_1.getTrimmedTextContent)(element, 'elocation-id'),
197
194
  'container-title': (0, utils_1.getHTMLContent)(element, 'source'),
198
- title: (_b = (_a = (0, utils_1.getHTMLContent)(element, 'article-title')) !== null && _a !== void 0 ? _a : (0, utils_1.getHTMLContent)(element, 'data-title')) !== null && _b !== void 0 ? _b : (0, utils_1.getHTMLContent)(element, 'part-title'),
199
- author: this.getNameContent(element, 'person-group[person-group-type="author"] > *'),
200
- editor: this.getNameContent(element, 'person-group[person-group-type="editor"] > *'),
201
- literal: this.parseRefLiteral(element),
195
+ title: (0, utils_1.getHTMLContent)(element, 'article-title, data-title, part-title'),
196
+ author: this.getNameContent(element, 'author'),
197
+ editor: this.getNameContent(element, 'editor'),
198
+ literal: (0, utils_1.getTrimmedTextContent)(element, 'mixed-citation'),
202
199
  accessed: this.getDateContent(element, 'date-in-citation'),
203
200
  'event-date': this.getDateContent(element, 'conf-date'),
204
- issued: (0, utils_1.getTrimmedTextContent)(element.querySelector('element-citation, mixed-citation'), ':scope > year')
205
- ? (0, json_schema_1.buildBibliographicDate)({
206
- 'date-parts': [
207
- [
208
- (0, utils_1.getTrimmedTextContent)(element.querySelector('element-citation, mixed-citation'), ':scope > year') || '',
209
- (0, utils_1.getTrimmedTextContent)(element.querySelector('element-citation, mixed-citation'), ':scope > month') || '',
210
- (0, utils_1.getTrimmedTextContent)(element.querySelector('element-citation, mixed-citation'), ':scope > day') || '',
211
- ],
212
- ],
213
- })
214
- : undefined,
201
+ issued: this.getIssuedDateContent(element),
215
202
  page: this.parseRefPages(element),
216
203
  };
217
204
  };
@@ -407,7 +394,7 @@ class JATSDOMParser {
407
394
  }
408
395
  }
409
396
  return {
410
- id: element.getAttribute('id'),
397
+ id: element.getAttribute('id') || undefined,
411
398
  role: (0, utils_1.getTrimmedTextContent)(element, 'role'),
412
399
  affiliations,
413
400
  corresp,
@@ -421,6 +408,7 @@ class JATSDOMParser {
421
408
  ObjectType: json_schema_1.ObjectTypes.BibliographicName,
422
409
  },
423
410
  ORCIDIdentifier: (0, utils_1.getTrimmedTextContent)(element, 'contrib-id[contrib-id-type="orcid"]'),
411
+ CRediTRoles: (0, utils_1.getCRediTRoleRole)(element),
424
412
  priority: this.parsePriority(element.getAttribute('priority')),
425
413
  email: (0, utils_1.getTrimmedTextContent)(element, 'email') || '',
426
414
  prefix: (0, utils_1.getTrimmedTextContent)(element, 'prefix'),
@@ -1062,30 +1050,22 @@ class JATSDOMParser {
1062
1050
  }
1063
1051
  }
1064
1052
  }
1065
- getNameContent(element, query) {
1066
- const buildName = (node) => {
1067
- const name = (0, json_schema_1.buildBibliographicName)({});
1068
- const given = (0, utils_1.getTrimmedTextContent)(node, 'given-names');
1069
- const family = (0, utils_1.getTrimmedTextContent)(node, 'surname');
1070
- if (given) {
1071
- name.given = given;
1072
- }
1073
- if (family) {
1074
- name.family = family;
1075
- }
1076
- if (node.nodeName === 'collab') {
1077
- name.literal = (0, utils_1.getTrimmedTextContent)(node);
1078
- }
1079
- return name;
1080
- };
1081
- const personNodes = element.querySelectorAll(query);
1082
- if (personNodes.length) {
1083
- return Array.from(personNodes).map(buildName);
1053
+ getNameContent(element, type) {
1054
+ const query = `person-group[person-group-type="${type}"] > *`;
1055
+ const groups = [...element.querySelectorAll(query)];
1056
+ if (!groups.length) {
1057
+ return;
1084
1058
  }
1059
+ return groups.map((node) => ({
1060
+ given: (0, utils_1.getTrimmedTextContent)(node, 'given-names'),
1061
+ family: (0, utils_1.getTrimmedTextContent)(node, 'surname'),
1062
+ literal: node.nodeName === 'collab' ? (0, utils_1.getTrimmedTextContent)(node) : undefined,
1063
+ }));
1085
1064
  }
1086
1065
  getDateContent(element, query) {
1087
- const buildDate = (element) => {
1088
- const isoDate = element.getAttribute('iso-8601-date');
1066
+ const date = element.querySelector(query);
1067
+ if (date) {
1068
+ const isoDate = date.getAttribute('iso-8601-date');
1089
1069
  if (!isoDate) {
1090
1070
  return;
1091
1071
  }
@@ -1095,14 +1075,21 @@ class JATSDOMParser {
1095
1075
  parsedDate.getMonth() + 1,
1096
1076
  parsedDate.getDate(),
1097
1077
  ];
1098
- return (0, json_schema_1.buildBibliographicDate)({
1078
+ return {
1099
1079
  'date-parts': [parts],
1100
- });
1101
- };
1102
- const dateElement = element.querySelector(query);
1103
- if (dateElement) {
1104
- return buildDate(dateElement);
1080
+ };
1081
+ }
1082
+ }
1083
+ getIssuedDateContent(element) {
1084
+ const year = (0, utils_1.getTrimmedTextContent)(element, ':scope > * > year');
1085
+ if (!year) {
1086
+ return;
1105
1087
  }
1088
+ const month = (0, utils_1.getTrimmedTextContent)(element, ':scope > * > month');
1089
+ const day = (0, utils_1.getTrimmedTextContent)(element, ':scope > * > day');
1090
+ return {
1091
+ 'date-parts': [[year, month !== null && month !== void 0 ? month : '', day !== null && day !== void 0 ? day : '']],
1092
+ };
1106
1093
  }
1107
1094
  }
1108
1095
  exports.JATSDOMParser = JATSDOMParser;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildCiteprocCitation = void 0;
4
+ const buildCiteprocCitation = (citation) => ({
5
+ citationID: citation.id,
6
+ citationItems: citation.rids.map((rid) => ({
7
+ id: rid,
8
+ })),
9
+ properties: {
10
+ noteIndex: 0,
11
+ },
12
+ });
13
+ exports.buildCiteprocCitation = buildCiteprocCitation;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2025 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.CRediTRoleUrls = void 0;
19
+ exports.CRediTRoleUrls = new Map([
20
+ [
21
+ "Conceptualization",
22
+ 'https://credit.niso.org/contributor-roles/conceptualization/',
23
+ ],
24
+ [
25
+ "Data curation",
26
+ 'https://credit.niso.org/contributor-roles/data-curation/',
27
+ ],
28
+ [
29
+ "Formal analysis",
30
+ 'https://credit.niso.org/contributor-roles/formal-analysis/',
31
+ ],
32
+ [
33
+ "Funding acquisition",
34
+ 'https://credit.niso.org/contributor-roles/funding-acquisition/',
35
+ ],
36
+ [
37
+ "Investigation",
38
+ 'https://credit.niso.org/contributor-roles/investigation/',
39
+ ],
40
+ [
41
+ "Methodology",
42
+ 'https://credit.niso.org/contributor-roles/methodology/',
43
+ ],
44
+ [
45
+ "ProjectAdministration",
46
+ 'https://credit.niso.org/contributor-roles/project-administration/',
47
+ ],
48
+ [
49
+ "Resources",
50
+ 'https://credit.niso.org/contributor-roles/resources/',
51
+ ],
52
+ [
53
+ "Software",
54
+ 'https://credit.niso.org/contributor-roles/software/',
55
+ ],
56
+ [
57
+ "Supervision",
58
+ 'https://credit.niso.org/contributor-roles/supervision/',
59
+ ],
60
+ [
61
+ "Validation",
62
+ 'https://credit.niso.org/contributor-roles/validation/',
63
+ ],
64
+ [
65
+ "Visualization",
66
+ 'https://credit.niso.org/contributor-roles/visualization/',
67
+ ],
68
+ [
69
+ "Writing \u2013 original draft",
70
+ 'https://credit.niso.org/contributor-roles/writing-original-draft/',
71
+ ],
72
+ [
73
+ "Writing \u2013 review & editing",
74
+ 'https://credit.niso.org/contributor-roles/writing-review-editing/',
75
+ ],
76
+ ]);
@@ -15,9 +15,10 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.dateToTimestamp = exports.getHTMLContent = exports.getTrimmedTextContent = exports.findParentNodeClosestToPos = exports.isInBibliographySection = exports.isInGraphicalAbstractSection = exports.findNodePositions = exports.iterateChildren = void 0;
18
+ exports.getCRediTRoleRole = exports.dateToTimestamp = exports.getHTMLContent = exports.getTrimmedTextContent = exports.findParentNodeClosestToPos = exports.isInBibliographySection = exports.isInGraphicalAbstractSection = exports.findNodePositions = exports.iterateChildren = void 0;
19
19
  const jats_parser_utils_1 = require("../jats/importer/jats-parser-utils");
20
20
  const schema_1 = require("../schema");
21
+ const credit_roles_1 = require("./credit-roles");
21
22
  function* iterateChildren(node, recurse = false) {
22
23
  for (let i = 0; i < node.childCount; i++) {
23
24
  const child = node.child(i);
@@ -102,3 +103,18 @@ const dateToTimestamp = (dateElement) => {
102
103
  return Date.UTC(values[0], values[1] - 1, values[2]) / 1000;
103
104
  };
104
105
  exports.dateToTimestamp = dateToTimestamp;
106
+ function getCRediTRoleRole(elem) {
107
+ const sources = elem.querySelectorAll('role[vocab="CRediT"][vocab-identifier="http://credit.niso.org/"][vocab-term][vocab-term-identifier]');
108
+ const results = [];
109
+ sources.forEach((source) => {
110
+ if (source &&
111
+ credit_roles_1.CRediTRoleUrls.has(source.getAttribute('vocab-term'))) {
112
+ const result = {
113
+ vocabTerm: source.getAttribute('vocab-term'),
114
+ };
115
+ results.push(result);
116
+ }
117
+ });
118
+ return results;
119
+ }
120
+ exports.getCRediTRoleRole = getCRediTRoleRole;
@@ -159,6 +159,7 @@ __exportStar(require("./nodes/placeholder_element"), exports);
159
159
  __exportStar(require("./nodes/pullquote_element"), exports);
160
160
  __exportStar(require("./nodes/section"), exports);
161
161
  __exportStar(require("./nodes/section_title"), exports);
162
+ __exportStar(require("./nodes/section_label"), exports);
162
163
  __exportStar(require("./nodes/supplement"), exports);
163
164
  __exportStar(require("./nodes/supplements"), exports);
164
165
  __exportStar(require("./nodes/table"), exports);
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.bibliographyElement = void 0;
18
+ exports.isBibliographyElementNode = exports.bibliographyElement = void 0;
19
19
  exports.bibliographyElement = {
20
20
  content: 'bibliography_item*',
21
21
  attrs: {
@@ -41,3 +41,5 @@ exports.bibliographyElement = {
41
41
  return dom;
42
42
  },
43
43
  };
44
+ const isBibliographyElementNode = (node) => node.type === node.type.schema.nodes.bibliography_element;
45
+ exports.isBibliographyElementNode = isBibliographyElementNode;
@@ -15,13 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.bibliographyItem = exports.publicationTypeToPM = void 0;
19
- exports.publicationTypeToPM = {
20
- journal: 'article-journal',
21
- web: 'webpage',
22
- data: 'dataset',
23
- preprint: 'article-journal',
24
- };
18
+ exports.isBibliographyItemNode = exports.bibliographyItem = void 0;
25
19
  exports.bibliographyItem = {
26
20
  content: 'inline{0}',
27
21
  attrs: {
@@ -58,3 +52,5 @@ exports.bibliographyItem = {
58
52
  selectable: false,
59
53
  group: 'block',
60
54
  };
55
+ const isBibliographyItemNode = (node) => node.type === node.type.schema.nodes.bibliography_item;
56
+ exports.isBibliographyItemNode = isBibliographyItemNode;
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.comment = void 0;
18
+ exports.isCommentNode = exports.comment = void 0;
19
19
  exports.comment = {
20
20
  attrs: {
21
21
  id: { default: '' },
@@ -27,3 +27,5 @@ exports.comment = {
27
27
  originalText: { default: '' },
28
28
  },
29
29
  };
30
+ const isCommentNode = (node) => node.type === node.type.schema.nodes.comment;
31
+ exports.isCommentNode = isCommentNode;
@@ -17,6 +17,7 @@ exports.contributor = {
17
17
  isJointContributor: { default: undefined },
18
18
  ORCIDIdentifier: { default: undefined },
19
19
  priority: { default: undefined },
20
+ CRediTRoles: { default: [] },
20
21
  dataTracked: { default: null },
21
22
  contents: { default: '' },
22
23
  prefix: { default: '' },
@@ -1,55 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isListNode = exports.listItem = exports.list = exports.getListType = exports.getJatsListType = void 0;
3
+ exports.isListNode = exports.listItem = exports.list = void 0;
4
4
  const json_schema_1 = require("@manuscripts/json-schema");
5
- const getJatsListType = (cssStyle) => {
6
- switch (cssStyle) {
7
- case 'disc':
8
- return 'bullet';
9
- case 'decimal':
10
- return 'order';
11
- case 'lower-alpha':
12
- return 'alpha-lower';
13
- case 'upper-alpha':
14
- return 'alpha-upper';
15
- case 'lower-roman':
16
- return 'roman-lower';
17
- case 'upper-roman':
18
- return 'roman-upper';
19
- case 'simple':
20
- return 'none';
21
- default:
22
- return 'none';
23
- }
24
- };
25
- exports.getJatsListType = getJatsListType;
26
- const getListType = (style) => {
27
- switch (style) {
28
- case 'bullet':
29
- return { type: 'ul', style: 'disc' };
30
- case 'order':
31
- return { type: 'ul', style: 'decimal' };
32
- case 'alpha-lower':
33
- return { type: 'ul', style: 'lower-alpha' };
34
- case 'alpha-upper':
35
- return { type: 'ul', style: 'upper-alpha' };
36
- case 'roman-lower':
37
- return { type: 'ul', style: 'lower-roman' };
38
- case 'roman-upper':
39
- return { type: 'ul', style: 'upper-roman' };
40
- case 'simple':
41
- default:
42
- return { type: 'ul', style: 'none' };
43
- }
44
- };
45
- exports.getListType = getListType;
46
5
  exports.list = {
47
6
  content: 'list_item+',
48
7
  group: 'block list element',
49
8
  attrs: {
50
9
  id: { default: '' },
51
- dataTracked: { default: null },
52
10
  listStyleType: { default: null },
11
+ dataTracked: { default: null },
53
12
  },
54
13
  parseDOM: [
55
14
  {
@@ -75,9 +34,8 @@ exports.list = {
75
34
  ],
76
35
  toDOM: (node) => {
77
36
  const list = node;
78
- const { type } = (0, exports.getListType)(list.attrs.listStyleType);
79
37
  return [
80
- type,
38
+ 'ul',
81
39
  {
82
40
  id: list.attrs.id,
83
41
  'list-type': list.attrs.listStyleType,
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "3.0.66";
4
+ exports.VERSION = "3.0.68-LEAN-4574.2";
package/dist/es/index.js CHANGED
@@ -5,8 +5,8 @@ export * from './jats/types';
5
5
  export * from './lib/footnotes';
6
6
  export * from './lib/utils';
7
7
  export * from './lib/section-categories';
8
+ export * from './lib/citeproc';
8
9
  export * from './schema';
9
10
  export { migrateFor } from './schema/migration/migrate';
10
- export { isSectionLabelNode } from './schema/nodes/section_label';
11
11
  export * from './transformer';
12
12
  export * from './types';
@@ -0,0 +1,156 @@
1
+ /*!
2
+ * © 2025 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import Citeproc from 'citeproc';
17
+ const normalizeID = (id) => id.replace(/:/g, '_');
18
+ const labelOnly = /^<label>.+<\/label>$/;
19
+ export const initJats = () => {
20
+ if (Citeproc.Output.Formats.jats) {
21
+ return;
22
+ }
23
+ Citeproc.Output.Formats.jats = Object.assign(Object.assign({}, Citeproc.Output.Formats.html), { text_escape: function (text) {
24
+ return text !== null && text !== void 0 ? text : '';
25
+ }, bibstart: '<ref-list>', bibend: '</ref-list>', '@font-style/italic': '<italic>%%STRING%%</italic>', '@font-style/oblique': '<italic>%%STRING%%</italic>', '@font-style/normal': false, '@font-variant/small-caps': '<smallcaps>%%STRING%%</smallcaps>', '@font-variant/normal': false, '@font-weight/bold': '<bold>%%STRING%%</bold>', '@font-weight/normal': false, '@font-weight/light': false, '@text-decoration/none': false, '@text-decoration/underline': '<underline>%%STRING%%</underline>', '@vertical-align/sup': '<sup>%%STRING%%</sup>', '@vertical-align/sub': '<sub>%%STRING%%</sub>', '@vertical-align/baseline': false, '@bibliography/entry': function (state, str) {
26
+ const id = this.system_id;
27
+ const item = state.registry.registry[id].ref;
28
+ const type = getPublicationType(item);
29
+ str = str.trim();
30
+ if (labelOnly.test(str)) {
31
+ return `<ref id="${normalizeID(id)}">${str}<mixed-citation publication-type="${type}">${item.literal}</mixed-citation></ref>`;
32
+ }
33
+ else if (str.includes('mixed-citation')) {
34
+ return `<ref id="${normalizeID(id)}">${str.replace('%%TYPE%%', type)}</ref>`;
35
+ }
36
+ else {
37
+ return `<ref id="${normalizeID(id)}"><mixed-citation publication-type="${type}">${str}</mixed-citation></ref>`;
38
+ }
39
+ }, '@display/block': false, '@display/left-margin': function (state, str) {
40
+ return `<label>${str}</label>`;
41
+ }, '@display/right-inline': function (state, str) {
42
+ return `<mixed-citation publication-type="%%TYPE%%">${str}</mixed-citation>`;
43
+ }, '@display/indent': false, '@URL/true': false, '@DOI/true': false });
44
+ const name = Citeproc.NameOutput.prototype._renderOnePersonalName;
45
+ Citeproc.NameOutput.prototype._renderOnePersonalName = function (...args) {
46
+ const area = this.state.tmp.area;
47
+ const blob = name.call(this, ...args);
48
+ if (blob && area === 'bibliography') {
49
+ blob.strings.prefix = '<string-name>';
50
+ blob.strings.suffix = '</string-name>';
51
+ }
52
+ return blob;
53
+ };
54
+ const given = Citeproc.NameOutput.prototype._givenName;
55
+ Citeproc.NameOutput.prototype._givenName = function (...args) {
56
+ const area = this.state.tmp.area;
57
+ const info = given.call(this, ...args);
58
+ if (info.blob && area === 'bibliography') {
59
+ info.blob.strings.prefix = '<given-names>';
60
+ info.blob.strings.suffix = '</given-names>';
61
+ }
62
+ return info;
63
+ };
64
+ const family = Citeproc.NameOutput.prototype._familyName;
65
+ Citeproc.NameOutput.prototype._familyName = function (...args) {
66
+ const area = this.state.tmp.area;
67
+ const blob = family.call(this, ...args);
68
+ if (blob && area === 'bibliography') {
69
+ blob.strings.prefix = '<surname>';
70
+ blob.strings.suffix = '</surname>';
71
+ }
72
+ return blob;
73
+ };
74
+ };
75
+ const namesWrapper = (type) => (str) => `<person-group person-group-type="${type}">${str}</person-group>`;
76
+ const formatDate = (date) => {
77
+ let output = date.year;
78
+ if (date.month) {
79
+ output += '-' + String(date.month).padStart(2, '0');
80
+ if (date.day) {
81
+ output += '-' + String(date.day).padStart(2, '0');
82
+ }
83
+ }
84
+ return output;
85
+ };
86
+ const getPublicationType = (item) => {
87
+ switch (item.type) {
88
+ case 'article-journal':
89
+ return 'journal';
90
+ case 'webpage':
91
+ return 'page';
92
+ case 'dataset':
93
+ return 'data';
94
+ default:
95
+ return item.type;
96
+ }
97
+ };
98
+ const wrappers = {
99
+ author: namesWrapper('author'),
100
+ issued: (str, item) => str.replace(item.issued.year, `<year>${item.issued.year}</year>`),
101
+ 'container-title': (str) => `<source>${str}</source>`,
102
+ volume: (str) => `<volume>${str}</volume>`,
103
+ issue: (str) => `<issue>${str}</issue>`,
104
+ supplement: (str) => `<supplement>${str}</supplement>`,
105
+ page: (str) => {
106
+ let fpage = str;
107
+ let lpage;
108
+ const parts = str.split('-');
109
+ if (parts.length === 2) {
110
+ fpage = parts[0];
111
+ lpage = parts[1];
112
+ }
113
+ str = str.replace(fpage, `<fpage>${fpage}</fpage>`);
114
+ if (lpage) {
115
+ str = str.replace(lpage, `<lpage>${lpage}</lpage>`);
116
+ }
117
+ return str;
118
+ },
119
+ title: (str, item) => {
120
+ const type = item.type;
121
+ switch (type) {
122
+ case 'dataset':
123
+ return `<data-title>${str}</data-title>`;
124
+ case 'article-journal':
125
+ case 'preprint':
126
+ return `<article-title>${str}</article-title>`;
127
+ default:
128
+ return `<part-title>${str}</part-title>`;
129
+ }
130
+ },
131
+ std: (str) => `<pub-id pub-id-type="std-designation">${str}</pub-id>`,
132
+ 'collection-title': (str) => `<series>${str}</series>`,
133
+ edition: (str) => `<edition>${str}</edition>`,
134
+ publisher: (str) => `<publisher-name>${str}</publisher-name>`,
135
+ 'publisher-place': (str) => `<publisher-loc>${str}</publisher-loc>`,
136
+ event: (str) => `<conf-name>${str}</conf-name>`,
137
+ 'event-place': (str) => `<conf-loc>${str}</conf-loc>`,
138
+ 'number-of-pages': (str) => `<size units="pages">${str}</size>`,
139
+ institution: (str) => `<institution>${str}</institution>`,
140
+ locator: (str) => `<elocation-id>${str}</elocation-id>`,
141
+ editor: namesWrapper('editor'),
142
+ accessed: (str, item) => `<date-in-citation content-type="access-date" iso-8601-date="${formatDate(item.accessed)}">${str}</date-in-citation>`,
143
+ 'event-date': (str, item) => `<conf-date iso-8601-date="${formatDate(item['event-date'])}">${str}</conf-date>`,
144
+ DOI: (str) => `<pub-id pub-id-type="doi">${str}</pub-id>`,
145
+ URL: (str) => `<ext-link ext-link-type="uri" xlink:href="${str}">${str}</ext-link>`,
146
+ };
147
+ export const jatsVariableWrapper = (params, pre, str, post) => {
148
+ if (str && params.context === 'bibliography') {
149
+ const name = params.variableNames[0];
150
+ const fn = wrappers[name];
151
+ if (fn) {
152
+ str = fn(str, params.itemData);
153
+ }
154
+ }
155
+ return `${pre}${str !== null && str !== void 0 ? str : ''}${post}`;
156
+ };