@manuscripts/transform 1.5.8 → 2.0.0

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 (133) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/cjs/jats/importer/index.js +1 -3
  3. package/dist/cjs/jats/importer/jats-body-dom-parser.js +23 -227
  4. package/dist/cjs/jats/importer/jats-body-transformations.js +110 -201
  5. package/dist/cjs/jats/importer/jats-comments.js +100 -98
  6. package/dist/cjs/jats/importer/jats-front-parser.js +87 -81
  7. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +51 -39
  8. package/dist/cjs/jats/importer/jats-parser-utils.js +17 -56
  9. package/dist/cjs/jats/importer/jats-reference-parser.js +24 -79
  10. package/dist/cjs/jats/importer/jats-references.js +34 -0
  11. package/dist/cjs/jats/importer/parse-jats-article.js +67 -173
  12. package/dist/cjs/jats/index.js +1 -3
  13. package/dist/cjs/jats/jats-exporter.js +34 -55
  14. package/dist/cjs/lib/section-group-type.js +30 -0
  15. package/dist/cjs/lib/utils.js +1 -25
  16. package/dist/cjs/schema/index.js +20 -17
  17. package/dist/cjs/schema/nodes/abstracts.js +27 -0
  18. package/dist/cjs/schema/nodes/affiliations.js +27 -0
  19. package/dist/cjs/schema/nodes/backmatter.js +27 -0
  20. package/dist/cjs/schema/nodes/body.js +27 -0
  21. package/dist/cjs/schema/nodes/citation.js +10 -15
  22. package/dist/cjs/schema/nodes/{comment_list.js → comments.js} +4 -4
  23. package/dist/cjs/schema/nodes/contributors.js +27 -0
  24. package/dist/cjs/schema/nodes/{meta_section.js → core_section.js} +6 -5
  25. package/dist/cjs/schema/nodes/cross_reference.js +4 -3
  26. package/dist/cjs/schema/nodes/inline_footnote.js +6 -5
  27. package/dist/cjs/schema/nodes/keyword.js +0 -1
  28. package/dist/cjs/schema/nodes/{keywords_group.js → keyword_group.js} +6 -6
  29. package/dist/cjs/schema/nodes/{keywords_section.js → keywords.js} +7 -7
  30. package/dist/cjs/schema/nodes/keywords_element.js +1 -1
  31. package/dist/cjs/schema/nodes/manuscript.js +5 -2
  32. package/dist/cjs/transformer/builders.js +9 -86
  33. package/dist/cjs/transformer/decode.js +147 -176
  34. package/dist/cjs/transformer/encode.js +66 -67
  35. package/dist/cjs/transformer/highlight-markers.js +48 -36
  36. package/dist/cjs/transformer/html.js +7 -23
  37. package/dist/cjs/transformer/labels.js +3 -17
  38. package/dist/cjs/transformer/node-names.js +1 -1
  39. package/dist/cjs/transformer/node-title.js +1 -1
  40. package/dist/cjs/transformer/node-types.js +7 -6
  41. package/dist/cjs/transformer/object-types.js +1 -2
  42. package/dist/cjs/transformer/section-category.js +31 -31
  43. package/dist/es/index.js +1 -1
  44. package/dist/es/jats/importer/index.js +1 -1
  45. package/dist/es/jats/importer/jats-body-dom-parser.js +23 -227
  46. package/dist/es/jats/importer/jats-body-transformations.js +111 -202
  47. package/dist/es/jats/importer/jats-comments.js +97 -96
  48. package/dist/es/jats/importer/jats-front-parser.js +88 -82
  49. package/dist/es/jats/importer/jats-journal-meta-parser.js +51 -39
  50. package/dist/es/jats/importer/jats-parser-utils.js +16 -54
  51. package/dist/es/jats/importer/jats-reference-parser.js +27 -82
  52. package/dist/es/jats/importer/jats-references.js +30 -0
  53. package/dist/es/jats/importer/parse-jats-article.js +70 -174
  54. package/dist/es/jats/index.js +1 -1
  55. package/dist/es/jats/jats-exporter.js +34 -55
  56. package/dist/es/lib/section-group-type.js +27 -0
  57. package/dist/es/lib/utils.js +0 -22
  58. package/dist/es/schema/index.js +21 -18
  59. package/dist/es/schema/nodes/abstracts.js +24 -0
  60. package/dist/es/schema/nodes/affiliations.js +24 -0
  61. package/dist/es/schema/nodes/backmatter.js +24 -0
  62. package/dist/es/schema/nodes/body.js +24 -0
  63. package/dist/es/schema/nodes/citation.js +10 -15
  64. package/dist/es/schema/nodes/{comment_list.js → comments.js} +3 -3
  65. package/dist/es/schema/nodes/contributors.js +24 -0
  66. package/dist/es/schema/nodes/{meta_section.js → core_section.js} +5 -4
  67. package/dist/es/schema/nodes/cross_reference.js +4 -3
  68. package/dist/es/schema/nodes/inline_footnote.js +6 -5
  69. package/dist/es/schema/nodes/keyword.js +0 -1
  70. package/dist/es/schema/nodes/{keywords_group.js → keyword_group.js} +4 -4
  71. package/dist/es/schema/nodes/{keywords_section.js → keywords.js} +5 -5
  72. package/dist/es/schema/nodes/keywords_element.js +1 -1
  73. package/dist/es/schema/nodes/manuscript.js +3 -1
  74. package/dist/es/transformer/builders.js +6 -73
  75. package/dist/es/transformer/decode.js +147 -175
  76. package/dist/es/transformer/encode.js +70 -71
  77. package/dist/es/transformer/highlight-markers.js +44 -32
  78. package/dist/es/transformer/html.js +7 -23
  79. package/dist/es/transformer/labels.js +3 -17
  80. package/dist/es/transformer/node-names.js +1 -1
  81. package/dist/es/transformer/node-title.js +1 -1
  82. package/dist/es/transformer/node-types.js +7 -6
  83. package/dist/es/transformer/object-types.js +0 -1
  84. package/dist/es/transformer/section-category.js +29 -29
  85. package/dist/types/index.d.ts +1 -1
  86. package/dist/types/jats/importer/index.d.ts +1 -1
  87. package/dist/types/jats/importer/jats-body-transformations.d.ts +16 -19
  88. package/dist/types/jats/importer/jats-comments.d.ts +13 -9
  89. package/dist/types/jats/importer/jats-front-parser.d.ts +35 -12
  90. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +4 -4
  91. package/dist/types/jats/importer/jats-parser-utils.d.ts +1 -6
  92. package/dist/types/jats/importer/jats-reference-parser.d.ts +2 -6
  93. package/dist/types/jats/importer/jats-references.d.ts +12 -0
  94. package/dist/types/jats/importer/parse-jats-article.d.ts +5 -17
  95. package/dist/types/jats/index.d.ts +1 -1
  96. package/dist/types/lib/section-group-type.d.ts +23 -0
  97. package/dist/types/lib/utils.d.ts +1 -4
  98. package/dist/types/schema/index.d.ts +4 -5
  99. package/dist/types/schema/nodes/{meta_section.d.ts → abstracts.d.ts} +1 -9
  100. package/dist/types/schema/nodes/affiliations.d.ts +17 -0
  101. package/dist/types/schema/nodes/backmatter.d.ts +17 -0
  102. package/dist/types/schema/nodes/body.d.ts +17 -0
  103. package/dist/types/schema/nodes/citation.d.ts +3 -5
  104. package/dist/types/schema/nodes/comments.d.ts +17 -0
  105. package/dist/types/schema/nodes/contributors.d.ts +17 -0
  106. package/dist/types/schema/nodes/core_section.d.ts +17 -0
  107. package/dist/types/schema/nodes/cross_reference.d.ts +1 -1
  108. package/dist/types/schema/nodes/inline_footnote.d.ts +1 -1
  109. package/dist/types/schema/nodes/keyword.d.ts +0 -1
  110. package/dist/types/schema/nodes/{contributors_element.d.ts → keyword_group.d.ts} +3 -4
  111. package/dist/types/schema/nodes/{comment_list.d.ts → keywords.d.ts} +3 -2
  112. package/dist/types/schema/nodes/manuscript.d.ts +1 -0
  113. package/dist/types/schema/types.d.ts +1 -1
  114. package/dist/types/transformer/builders.d.ts +2 -14
  115. package/dist/types/transformer/decode.d.ts +5 -9
  116. package/dist/types/transformer/encode.d.ts +4 -4
  117. package/dist/types/transformer/highlight-markers.d.ts +7 -2
  118. package/dist/types/transformer/object-types.d.ts +1 -2
  119. package/dist/types/transformer/section-category.d.ts +4 -3
  120. package/package.json +1 -6
  121. package/dist/cjs/lib/core-section-categories.js +0 -29
  122. package/dist/cjs/schema/nodes/affiliations_section.js +0 -36
  123. package/dist/cjs/schema/nodes/contributors_element.js +0 -49
  124. package/dist/cjs/schema/nodes/contributors_section.js +0 -36
  125. package/dist/es/lib/core-section-categories.js +0 -26
  126. package/dist/es/schema/nodes/affiliations_section.js +0 -32
  127. package/dist/es/schema/nodes/contributors_element.js +0 -46
  128. package/dist/es/schema/nodes/contributors_section.js +0 -32
  129. package/dist/types/lib/core-section-categories.d.ts +0 -8
  130. package/dist/types/schema/nodes/affiliations_section.d.ts +0 -11
  131. package/dist/types/schema/nodes/contributors_section.d.ts +0 -12
  132. package/dist/types/schema/nodes/keywords_group.d.ts +0 -26
  133. package/dist/types/schema/nodes/keywords_section.d.ts +0 -26
@@ -15,140 +15,142 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.createReferenceComments = exports.createComments = exports.markProcessingInstructions = exports.parseProcessingInstruction = void 0;
18
+ exports.createReferenceComments = exports.createComments = exports.markComments = exports.parseJATSComment = exports.isJATSComment = void 0;
19
19
  const uuid_1 = require("uuid");
20
20
  const transformer_1 = require("../../transformer");
21
- const DEFAULT_ANNOTATION_COLOR = 'rgb(250, 224, 150)';
22
21
  const DEFAULT_PROFILE_ID = 'MPUserProfile:0000000000000000000000000000000000000001';
23
- const parseProcessingInstruction = (node) => {
24
- var _a;
25
- const value = `<AuthorQuery ${(_a = node.textContent) === null || _a === void 0 ? void 0 : _a.trim()} />`;
26
- const processingInstruction = new DOMParser().parseFromString(value, 'application/xml').firstElementChild;
27
- if (processingInstruction) {
28
- const queryText = processingInstruction.getAttribute('queryText');
29
- const id = processingInstruction.getAttribute('id');
30
- if (queryText && id) {
31
- return { queryText, id };
22
+ const isJATSComment = (node) => {
23
+ return (node.nodeType === node.PROCESSING_INSTRUCTION_NODE &&
24
+ node.nodeName === 'AuthorQuery');
25
+ };
26
+ exports.isJATSComment = isJATSComment;
27
+ const parseJATSComment = (node) => {
28
+ const text = node.textContent;
29
+ if (text) {
30
+ const id = /id="(.+)"/.exec(text);
31
+ const queryText = /queryText="(.+)"/.exec(text);
32
+ if (id && queryText) {
33
+ return {
34
+ id: id[1],
35
+ text: queryText[1],
36
+ };
32
37
  }
33
38
  }
34
39
  };
35
- exports.parseProcessingInstruction = parseProcessingInstruction;
36
- const markProcessingInstructions = (doc) => {
37
- const authorQueriesMap = new Map();
40
+ exports.parseJATSComment = parseJATSComment;
41
+ const markComments = (doc) => {
42
+ const marks = [];
38
43
  const root = doc.getRootNode();
39
44
  const queue = [root];
40
45
  while (queue.length !== 0) {
41
46
  const node = queue.shift();
42
47
  if (node) {
43
- const { nodeType, nodeName } = node;
44
- if (nodeType === node.PROCESSING_INSTRUCTION_NODE &&
45
- nodeName === 'AuthorQuery') {
46
- insertToken(doc, node, authorQueriesMap);
48
+ if ((0, exports.isJATSComment)(node)) {
49
+ const comment = (0, exports.parseJATSComment)(node);
50
+ if (comment) {
51
+ const token = addMark(doc, node);
52
+ if (token) {
53
+ const mark = {
54
+ token,
55
+ comment,
56
+ };
57
+ marks.push(mark);
58
+ }
59
+ }
47
60
  }
48
61
  node.childNodes.forEach((child) => {
49
62
  queue.push(child);
50
63
  });
51
64
  }
52
65
  }
53
- return authorQueriesMap;
66
+ return marks;
54
67
  };
55
- exports.markProcessingInstructions = markProcessingInstructions;
56
- const insertToken = (doc, processingInstructionNode, authorQueriesMap) => {
57
- const instruction = (0, exports.parseProcessingInstruction)(processingInstructionNode);
58
- const { parentElement } = processingInstructionNode;
59
- if (parentElement && instruction) {
60
- const { queryText } = instruction;
68
+ exports.markComments = markComments;
69
+ const addMark = (doc, node) => {
70
+ const parent = node.parentElement;
71
+ if (parent) {
61
72
  const token = (0, uuid_1.v4)();
62
73
  const tokenNode = doc.createTextNode(token);
63
- authorQueriesMap.set(token, queryText);
64
- return parentElement.insertBefore(tokenNode, processingInstructionNode);
65
- }
66
- };
67
- const extractCommentsFromKeywords = (tokens, model, authorQueriesMap) => {
68
- var _a;
69
- const commentAnnotations = [];
70
- const name = model.name;
71
- const filteredTokens = filterAndSortTokens(tokens, name);
72
- let content = name;
73
- for (const token of filteredTokens) {
74
- content = name.replace(token, '');
75
- const query = authorQueriesMap.get(token);
76
- const commentAnnotation = (0, transformer_1.buildComment)((_a = model.containedGroup) !== null && _a !== void 0 ? _a : (0, uuid_1.v4)(), `${query}`, undefined, [(0, transformer_1.buildContribution)(DEFAULT_PROFILE_ID)], DEFAULT_ANNOTATION_COLOR);
77
- model['name'] = content;
78
- commentAnnotations.push(commentAnnotation);
74
+ parent.insertBefore(tokenNode, node);
75
+ return token;
79
76
  }
80
- return commentAnnotations;
81
77
  };
82
- const createComments = (authorQueriesMap, manuscriptModels) => {
83
- const tokens = [...authorQueriesMap.keys()];
84
- const commentAnnotations = [];
85
- for (const model of manuscriptModels) {
78
+ const createComments = (models, marks) => {
79
+ const comments = [];
80
+ for (const model of models) {
86
81
  if ((0, transformer_1.isHighlightableModel)(model)) {
87
- const comments = addCommentsFromMarkedProcessingInstructions(tokens, model, authorQueriesMap);
88
- commentAnnotations.push(...comments);
82
+ comments.push(...processModel(model, marks));
89
83
  }
90
84
  else if ((0, transformer_1.isKeyword)(model)) {
91
- const comments = extractCommentsFromKeywords(tokens, model, authorQueriesMap);
92
- commentAnnotations.push(...comments);
85
+ comments.push(...processKeyword(model, marks));
93
86
  }
94
87
  }
95
- return commentAnnotations;
88
+ return comments;
96
89
  };
97
90
  exports.createComments = createComments;
98
- function filterAndSortTokens(tokens, content) {
99
- return tokens
100
- .filter((token) => content.indexOf(token) >= 0)
101
- .sort((a, b) => content.indexOf(a) - content.indexOf(b));
102
- }
103
- const addCommentsFromMarkedProcessingInstructions = (tokens, model, authorQueriesMap) => {
104
- const commentAnnotations = [];
105
- for (const field of ['contents', 'caption', 'title']) {
106
- const highlightableField = field;
107
- const content = model[highlightableField];
91
+ const getFieldMarks = (content, marks) => {
92
+ return marks
93
+ .filter((m) => content.indexOf(m.token) >= 0)
94
+ .sort((a, b) => content.indexOf(a.token) - content.indexOf(b.token));
95
+ };
96
+ const processModel = (model, marks) => {
97
+ const comments = [];
98
+ for (const field of transformer_1.highlightableFields) {
99
+ const content = model[field];
108
100
  if (!content) {
109
101
  continue;
110
102
  }
111
- const sortedTokens = tokens
112
- .filter((token) => content.indexOf(token) >= 0)
113
- .sort((a, b) => content.indexOf(a) - content.indexOf(b));
114
- let contentWithoutTokens = content;
115
- for (const token of sortedTokens) {
116
- const query = authorQueriesMap.get(token);
117
- if (query) {
118
- const trimmedTextContent = contentWithoutTokens
119
- ? contentWithoutTokens.replace(/^\s+/gm, '')
120
- : undefined;
121
- const startTokenIndex = trimmedTextContent
122
- ? trimmedTextContent.indexOf(token)
123
- : undefined;
124
- contentWithoutTokens = contentWithoutTokens.replace(token, '');
125
- const comment = `${query}`;
126
- const target = model._id && !(0, transformer_1.isCommentAnnotation)(model) ? model._id : (0, uuid_1.v4)();
127
- const contributions = [(0, transformer_1.buildContribution)(DEFAULT_PROFILE_ID)];
128
- const selector = startTokenIndex
129
- ? { from: startTokenIndex, to: startTokenIndex }
130
- : undefined;
131
- const commentAnnotation = (0, transformer_1.buildComment)(target, comment, selector, contributions, DEFAULT_ANNOTATION_COLOR);
132
- commentAnnotations.push(commentAnnotation);
133
- }
103
+ const results = processContent(model, content, getFieldMarks(content, marks));
104
+ model[field] = results.content;
105
+ comments.push(...results.comments);
106
+ }
107
+ return comments;
108
+ };
109
+ const processKeyword = (model, marks) => {
110
+ const comments = [];
111
+ const name = model.name;
112
+ let content = name;
113
+ for (const mark of getFieldMarks(name, marks)) {
114
+ content = name.replace(mark.token, '');
115
+ const target = model.containedGroup;
116
+ if (!target) {
117
+ continue;
134
118
  }
135
- model[highlightableField] = contentWithoutTokens;
119
+ const contributions = [(0, transformer_1.buildContribution)(DEFAULT_PROFILE_ID)];
120
+ const comment = (0, transformer_1.buildComment)(target, mark.comment.text, undefined, contributions);
121
+ model.name = content;
122
+ comments.push(comment);
136
123
  }
137
- return commentAnnotations;
124
+ return comments;
138
125
  };
139
- const createReferenceComments = (referenceQueriesMap, references) => {
126
+ const processContent = (model, content, marks) => {
140
127
  const comments = [];
141
- for (const reference of references) {
142
- const id = reference._id;
143
- if (referenceQueriesMap.has(id)) {
144
- for (const comment of referenceQueriesMap.get(id) || []) {
145
- const target = reference._id && !(0, transformer_1.isCommentAnnotation)(reference)
146
- ? reference._id
147
- : (0, uuid_1.v4)();
148
- const contributions = [(0, transformer_1.buildContribution)(DEFAULT_PROFILE_ID)];
149
- const commentAnnotation = (0, transformer_1.buildComment)(target, comment, undefined, contributions, DEFAULT_ANNOTATION_COLOR);
150
- comments.push(commentAnnotation);
151
- }
128
+ let result = content;
129
+ for (const mark of marks) {
130
+ const token = mark.token;
131
+ const index = result.indexOf(token);
132
+ result = result.replace(token, '');
133
+ const contributions = [(0, transformer_1.buildContribution)(DEFAULT_PROFILE_ID)];
134
+ const selector = {
135
+ from: index,
136
+ to: index,
137
+ };
138
+ const comment = (0, transformer_1.buildComment)(model._id, mark.comment.text, selector, contributions);
139
+ comments.push(comment);
140
+ }
141
+ return {
142
+ content: result,
143
+ comments,
144
+ };
145
+ };
146
+ const createReferenceComments = (references) => {
147
+ const comments = [];
148
+ for (const item of references.getBibliographyItems()) {
149
+ const id = item._id;
150
+ for (const comment of references.getComments(id)) {
151
+ const contributions = [(0, transformer_1.buildContribution)(DEFAULT_PROFILE_ID)];
152
+ const c = (0, transformer_1.buildComment)(id, comment.text, undefined, contributions);
153
+ comments.push(c);
152
154
  }
153
155
  }
154
156
  return comments;
@@ -23,9 +23,28 @@ const debug_1 = __importDefault(require("debug"));
23
23
  const utils_1 = require("../../lib/utils");
24
24
  const transformer_1 = require("../../transformer");
25
25
  const jats_journal_meta_parser_1 = require("./jats-journal-meta-parser");
26
+ const jats_parser_utils_1 = require("./jats-parser-utils");
26
27
  const warn = (0, debug_1.default)('manuscripts-transform');
27
28
  const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
29
+ const defaultTitle = 'Untitled Manuscript';
28
30
  exports.jatsFrontParser = {
31
+ parseTitles(element, createElement) {
32
+ var _a;
33
+ if (!element) {
34
+ return (0, transformer_1.buildTitles)(defaultTitle);
35
+ }
36
+ const title = element.querySelector('article-title');
37
+ const subtitle = element.querySelector('subtitle');
38
+ const runningTitle = element.querySelector('alt-title[alt-title-type="right-running"]');
39
+ const titles = (0, transformer_1.buildTitles)((_a = (0, jats_parser_utils_1.htmlFromJatsNode)(title, createElement)) !== null && _a !== void 0 ? _a : defaultTitle);
40
+ if (subtitle) {
41
+ titles.subtitle = (0, jats_parser_utils_1.htmlFromJatsNode)(subtitle, createElement);
42
+ }
43
+ if (runningTitle) {
44
+ titles.runningTitle = (0, jats_parser_utils_1.htmlFromJatsNode)(runningTitle, createElement);
45
+ }
46
+ return titles;
47
+ },
29
48
  parseCounts(counts) {
30
49
  var _a, _b, _c, _d, _e;
31
50
  if (counts) {
@@ -42,7 +61,7 @@ exports.jatsFrontParser = {
42
61
  for (const element of countElements.values()) {
43
62
  const countType = element.getAttribute('count-type');
44
63
  const count = parseCount(element.getAttribute('count'));
45
- if (countType && typeof count === 'number') {
64
+ if (countType) {
46
65
  const genericCount = { count, countType };
47
66
  genericCounts.push(genericCount);
48
67
  }
@@ -57,17 +76,9 @@ exports.jatsFrontParser = {
57
76
  };
58
77
  }
59
78
  },
60
- parseJournal(journalMeta) {
61
- if (!journalMeta) {
62
- return {
63
- journalIdentifiers: [],
64
- abbreviatedTitles: [],
65
- ISSNs: [],
66
- publisherName: undefined,
67
- title: undefined,
68
- };
69
- }
70
- return (0, jats_journal_meta_parser_1.parseJournalMeta)(journalMeta);
79
+ parseJournal(element) {
80
+ const meta = (0, jats_journal_meta_parser_1.parseJournalMeta)(element);
81
+ return Object.assign(Object.assign({}, meta), (0, transformer_1.buildJournal)());
71
82
  },
72
83
  parseDates(historyNode) {
73
84
  if (!historyNode) {
@@ -117,66 +128,61 @@ exports.jatsFrontParser = {
117
128
  }
118
129
  return history;
119
130
  },
120
- parseSupplements(supplementNodes) {
131
+ parseSupplements(elements) {
121
132
  var _a, _b, _c, _d;
122
- if (!supplementNodes || supplementNodes.length === 0) {
133
+ if (!(elements === null || elements === void 0 ? void 0 : elements.length)) {
123
134
  return [];
124
135
  }
125
136
  const supplements = [];
126
- for (const supplementNode of supplementNodes) {
127
- const supplTitle = (_a = (0, utils_1.getTrimmedTextContent)(supplementNode, 'caption > title')) !== null && _a !== void 0 ? _a : '';
128
- const href = (_b = supplementNode.getAttributeNS(XLINK_NAMESPACE, 'href')) !== null && _b !== void 0 ? _b : '';
129
- const supplementaryMaterial = (0, transformer_1.buildSupplementaryMaterial)(supplTitle, href);
130
- const mimeType = (_c = supplementNode.getAttribute('mimetype')) !== null && _c !== void 0 ? _c : '';
131
- const mimeSubtype = (_d = supplementNode.getAttribute('mime-subtype')) !== null && _d !== void 0 ? _d : '';
137
+ for (const element of elements) {
138
+ const title = (_a = (0, utils_1.getTrimmedTextContent)(element, 'caption > title')) !== null && _a !== void 0 ? _a : '';
139
+ const href = (_b = element.getAttributeNS(XLINK_NAMESPACE, 'href')) !== null && _b !== void 0 ? _b : '';
140
+ const supplement = (0, transformer_1.buildSupplementaryMaterial)(title, href);
141
+ const mimeType = (_c = element.getAttribute('mimetype')) !== null && _c !== void 0 ? _c : '';
142
+ const mimeSubtype = (_d = element.getAttribute('mime-subtype')) !== null && _d !== void 0 ? _d : '';
132
143
  if (mimeType && mimeSubtype) {
133
- supplementaryMaterial.MIME = [mimeType, mimeSubtype].join('/');
144
+ supplement.MIME = [mimeType, mimeSubtype].join('/');
134
145
  }
135
- supplements.push(supplementaryMaterial);
146
+ supplements.push(supplement);
136
147
  }
137
148
  return supplements;
138
149
  },
139
- parseAffiliationNodes(affiliationNodes) {
150
+ parseAffiliations(elements) {
140
151
  const affiliationIDs = new Map();
141
- const affiliations = affiliationNodes.map((affiliationNode, priority) => {
152
+ const affiliations = elements.map((element, priority) => {
142
153
  var _a, _b;
143
154
  const affiliation = (0, transformer_1.buildAffiliation)('', priority);
144
- for (const node of affiliationNode.querySelectorAll('institution')) {
155
+ for (const node of element.querySelectorAll('institution')) {
145
156
  const content = (_a = node.textContent) === null || _a === void 0 ? void 0 : _a.trim();
146
157
  if (!content) {
147
158
  continue;
148
159
  }
149
- const contentType = node.getAttribute('content-type');
150
- switch (contentType) {
151
- case null:
152
- affiliation.institution = content;
153
- break;
154
- case 'dept':
155
- affiliation.department = content;
156
- break;
160
+ const type = node.getAttribute('content-type');
161
+ if (type === 'dept') {
162
+ affiliation.department = content;
163
+ }
164
+ else {
165
+ affiliation.institution = content;
157
166
  }
158
167
  }
159
168
  affiliation.addressLine1 =
160
- (0, utils_1.getTrimmedTextContent)(affiliationNode, 'addr-line:nth-of-type(1)') ||
161
- undefined;
169
+ (0, utils_1.getTrimmedTextContent)(element, 'addr-line:nth-of-type(1)') || undefined;
162
170
  affiliation.addressLine2 =
163
- (0, utils_1.getTrimmedTextContent)(affiliationNode, 'addr-line:nth-of-type(2)') ||
164
- undefined;
171
+ (0, utils_1.getTrimmedTextContent)(element, 'addr-line:nth-of-type(2)') || undefined;
165
172
  affiliation.addressLine3 =
166
- (0, utils_1.getTrimmedTextContent)(affiliationNode, 'addr-line:nth-of-type(3)') ||
167
- undefined;
168
- const emailNode = affiliationNode.querySelector('email');
169
- if (emailNode) {
173
+ (0, utils_1.getTrimmedTextContent)(element, 'addr-line:nth-of-type(3)') || undefined;
174
+ affiliation.postCode =
175
+ (0, utils_1.getTrimmedTextContent)(element, 'postal-code') || undefined;
176
+ affiliation.country =
177
+ (0, utils_1.getTrimmedTextContent)(element, 'country') || undefined;
178
+ const email = element.querySelector('email');
179
+ if (email) {
170
180
  affiliation.email = {
171
- href: emailNode.getAttributeNS(XLINK_NAMESPACE, 'href') || undefined,
172
- text: ((_b = emailNode.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
181
+ href: email.getAttributeNS(XLINK_NAMESPACE, 'href') || undefined,
182
+ text: ((_b = email.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
173
183
  };
174
184
  }
175
- affiliation.postCode =
176
- (0, utils_1.getTrimmedTextContent)(affiliationNode, 'postal-code') || undefined;
177
- affiliation.country =
178
- (0, utils_1.getTrimmedTextContent)(affiliationNode, 'country') || undefined;
179
- const id = affiliationNode.getAttribute('id');
185
+ const id = element.getAttribute('id');
180
186
  if (id) {
181
187
  affiliationIDs.set(id, affiliation._id);
182
188
  }
@@ -187,11 +193,11 @@ exports.jatsFrontParser = {
187
193
  affiliationIDs,
188
194
  };
189
195
  },
190
- parseFootnoteNodes(footnoteNodes) {
196
+ parseAuthorNotes(elements) {
191
197
  const footnoteIDs = new Map();
192
- const footnotes = footnoteNodes.map((footnoteNode) => {
193
- const fn = (0, transformer_1.buildFootnote)('', footnoteNode.innerHTML);
194
- const id = footnoteNode.getAttribute('id');
198
+ const footnotes = elements.map((element) => {
199
+ const fn = (0, transformer_1.buildFootnote)('', element.innerHTML);
200
+ const id = element.getAttribute('id');
195
201
  if (id) {
196
202
  footnoteIDs.set(id, fn._id);
197
203
  }
@@ -202,17 +208,17 @@ exports.jatsFrontParser = {
202
208
  footnoteIDs,
203
209
  };
204
210
  },
205
- parseCorrespNodes(correspNodes) {
211
+ parseCorresp(elements) {
206
212
  const correspondingIDs = new Map();
207
- const correspondingList = correspNodes.map((correspNode) => {
213
+ const correspondingList = elements.map((element) => {
208
214
  var _a, _b, _c;
209
- const label = correspNode.querySelector('label');
215
+ const label = element.querySelector('label');
210
216
  if (label) {
211
217
  label.remove();
212
218
  }
213
- const corresponding = (0, transformer_1.buildCorresp)((_b = (_a = correspNode.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '');
219
+ const corresponding = (0, transformer_1.buildCorresp)((_b = (_a = element.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '');
214
220
  corresponding.label = ((_c = label === null || label === void 0 ? void 0 : label.textContent) === null || _c === void 0 ? void 0 : _c.trim()) || undefined;
215
- const id = correspNode.getAttribute('id');
221
+ const id = element.getAttribute('id');
216
222
  if (id) {
217
223
  correspondingIDs.set(id, corresponding._id);
218
224
  }
@@ -223,60 +229,60 @@ exports.jatsFrontParser = {
223
229
  correspondingIDs,
224
230
  };
225
231
  },
226
- parseAuthorNodes(authorNodes, affiliationIDs, footnoteIDs, correspondingIDs) {
227
- return authorNodes.map((authorNode, priority) => {
232
+ parseContributors(elements, affiliationIDs, footnoteIDs, correspondingIDs) {
233
+ return elements.map((element, priority) => {
228
234
  var _a, _b;
229
235
  const name = (0, transformer_1.buildBibliographicName)({});
230
- const given = (0, utils_1.getTrimmedTextContent)(authorNode, 'name > given-names');
236
+ const given = (0, utils_1.getTrimmedTextContent)(element, 'name > given-names');
231
237
  if (given) {
232
238
  name.given = given;
233
239
  }
234
- const surname = (0, utils_1.getTrimmedTextContent)(authorNode, 'name > surname');
240
+ const surname = (0, utils_1.getTrimmedTextContent)(element, 'name > surname');
235
241
  if (surname) {
236
242
  name.family = surname;
237
243
  }
238
244
  const contributor = (0, transformer_1.buildContributor)(name, 'author', priority);
239
- const corresponding = authorNode.getAttribute('corresp') === 'yes';
245
+ const corresponding = element.getAttribute('corresp') === 'yes';
240
246
  if (corresponding) {
241
247
  contributor.isCorresponding = corresponding;
242
248
  }
243
- const orcid = (0, utils_1.getTrimmedTextContent)(authorNode, 'contrib-id[contrib-id-type="orcid"]');
249
+ const orcid = (0, utils_1.getTrimmedTextContent)(element, 'contrib-id[contrib-id-type="orcid"]');
244
250
  if (orcid) {
245
251
  contributor.ORCIDIdentifier = orcid;
246
252
  }
247
- const xrefNodes = authorNode.querySelectorAll('xref');
248
- for (const xrefNode of xrefNodes) {
249
- if (xrefNode) {
250
- const rid = xrefNode.getAttribute('rid');
251
- const rtype = xrefNode.getAttribute('ref-type');
253
+ const xrefs = element.querySelectorAll('xref');
254
+ for (const xref of xrefs) {
255
+ if (xref) {
256
+ const rid = xref.getAttribute('rid');
257
+ const type = xref.getAttribute('ref-type');
252
258
  if (rid) {
253
- if (rtype === 'fn') {
259
+ if (type === 'fn') {
254
260
  contributor.footnote = [];
255
- const footnoteId = footnoteIDs.get(rid);
256
- if (footnoteId) {
261
+ const footnoteID = footnoteIDs.get(rid);
262
+ if (footnoteID) {
257
263
  const authorFootNoteRef = {
258
- noteID: footnoteId,
259
- noteLabel: ((_a = xrefNode.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '',
264
+ noteID: footnoteID,
265
+ noteLabel: ((_a = xref.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '',
260
266
  };
261
267
  contributor.footnote.push(authorFootNoteRef);
262
268
  }
263
269
  }
264
- else if (rtype === 'corresp') {
270
+ else if (type === 'corresp') {
265
271
  contributor.corresp = [];
266
- const correspId = correspondingIDs.get(rid);
267
- if (correspId) {
272
+ const correspID = correspondingIDs.get(rid);
273
+ if (correspID) {
268
274
  const authorCorrespRef = {
269
- correspID: correspId,
270
- correspLabel: ((_b = xrefNode.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || '',
275
+ correspID: correspID,
276
+ correspLabel: ((_b = xref.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || '',
271
277
  };
272
278
  contributor.corresp.push(authorCorrespRef);
273
279
  }
274
280
  }
275
- else if (rtype === 'aff') {
281
+ else if (type === 'aff') {
276
282
  const rids = rid
277
283
  .split(/\s+/)
278
- .filter((id) => affiliationIDs.has(id))
279
- .map((id) => affiliationIDs.get(id));
284
+ .map((id) => affiliationIDs.get(id))
285
+ .filter(Boolean);
280
286
  if (rids.length) {
281
287
  contributor.affiliations = rids;
282
288
  }
@@ -17,65 +17,77 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.parseJournalMeta = exports.parseJournalISSNs = exports.parseJournalAbbreviatedTitles = exports.parseJournalIdentifiers = void 0;
19
19
  const utils_1 = require("../../lib/utils");
20
- const parseJournalIdentifiers = (journalMeta) => {
21
- var _a, _b;
20
+ const parseJournalIdentifiers = (element) => {
21
+ var _a;
22
+ if (!element) {
23
+ return [];
24
+ }
22
25
  const output = [];
23
- const elements = journalMeta.querySelectorAll('journal-id');
24
- for (const element of elements) {
25
- const journalIDType = element.getAttribute('journal-id-type');
26
- const journalID = (_b = (_a = element.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : element.textContent;
27
- if (journalID !== null && journalIDType != null) {
28
- output.push({ journalIDType, journalID });
29
- }
30
- else if (journalID !== null) {
31
- output.push({ journalID });
26
+ const ids = element.querySelectorAll('journal-id');
27
+ for (const id of ids) {
28
+ const type = id.getAttribute('journal-id-type');
29
+ const value = (_a = id.textContent) === null || _a === void 0 ? void 0 : _a.trim();
30
+ if (!value) {
31
+ continue;
32
32
  }
33
+ output.push({
34
+ journalID: value,
35
+ journalIDType: type !== null && type !== void 0 ? type : undefined,
36
+ });
33
37
  }
34
38
  return output;
35
39
  };
36
40
  exports.parseJournalIdentifiers = parseJournalIdentifiers;
37
- const parseJournalAbbreviatedTitles = (journalMeta) => {
38
- var _a, _b;
41
+ const parseJournalAbbreviatedTitles = (element) => {
42
+ var _a;
43
+ if (!element) {
44
+ return [];
45
+ }
39
46
  const output = [];
40
- const elements = journalMeta.querySelectorAll('journal-title-group > abbrev-journal-title');
41
- for (const element of elements) {
42
- const abbrevType = element.getAttribute('abbrev-type');
43
- const abbreviatedTitle = (_b = (_a = element.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : element.textContent;
44
- if (abbreviatedTitle !== null && abbrevType !== null) {
45
- output.push({ abbreviatedTitle, abbrevType });
46
- }
47
- else if (abbreviatedTitle !== null) {
48
- output.push({ abbreviatedTitle });
47
+ const titles = element.querySelectorAll('journal-title-group > abbrev-journal-title');
48
+ for (const title of titles) {
49
+ const type = title.getAttribute('abbrev-type');
50
+ const value = (_a = title.textContent) === null || _a === void 0 ? void 0 : _a.trim();
51
+ if (!value) {
52
+ continue;
49
53
  }
54
+ output.push({
55
+ abbreviatedTitle: value,
56
+ abbrevType: type !== null && type !== void 0 ? type : undefined,
57
+ });
50
58
  }
51
59
  return output;
52
60
  };
53
61
  exports.parseJournalAbbreviatedTitles = parseJournalAbbreviatedTitles;
54
- const parseJournalISSNs = (journalMeta) => {
55
- var _a, _b;
62
+ const parseJournalISSNs = (element) => {
63
+ var _a;
64
+ if (!element) {
65
+ return [];
66
+ }
56
67
  const output = [];
57
- const elements = journalMeta.querySelectorAll('issn');
58
- for (const element of elements) {
59
- const publicationType = element.getAttribute('pub-type');
60
- const ISSN = (_b = (_a = element.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : element.textContent;
61
- if (publicationType !== null && ISSN !== null) {
62
- output.push({ publicationType, ISSN });
63
- }
64
- else if (ISSN !== null) {
65
- output.push({ ISSN });
68
+ const issns = element.querySelectorAll('issn');
69
+ for (const issn of issns) {
70
+ const type = issn.getAttribute('pub-type');
71
+ const value = (_a = issn.textContent) === null || _a === void 0 ? void 0 : _a.trim();
72
+ if (!value) {
73
+ continue;
66
74
  }
75
+ output.push({
76
+ ISSN: value,
77
+ publicationType: type !== null && type !== void 0 ? type : undefined,
78
+ });
67
79
  }
68
80
  return output;
69
81
  };
70
82
  exports.parseJournalISSNs = parseJournalISSNs;
71
- const parseJournalMeta = (journalMeta) => {
83
+ const parseJournalMeta = (element) => {
72
84
  var _a, _b;
73
85
  return {
74
- abbreviatedTitles: (0, exports.parseJournalAbbreviatedTitles)(journalMeta),
75
- journalIdentifiers: (0, exports.parseJournalIdentifiers)(journalMeta),
76
- ISSNs: (0, exports.parseJournalISSNs)(journalMeta),
77
- publisherName: (_a = (0, utils_1.getTrimmedTextContent)(journalMeta, 'publisher > publisher-name')) !== null && _a !== void 0 ? _a : undefined,
78
- title: (_b = (0, utils_1.getTrimmedTextContent)(journalMeta, 'journal-title-group > journal-title')) !== null && _b !== void 0 ? _b : undefined,
86
+ abbreviatedTitles: (0, exports.parseJournalAbbreviatedTitles)(element),
87
+ journalIdentifiers: (0, exports.parseJournalIdentifiers)(element),
88
+ ISSNs: (0, exports.parseJournalISSNs)(element),
89
+ publisherName: (_a = (0, utils_1.getTrimmedTextContent)(element, 'publisher > publisher-name')) !== null && _a !== void 0 ? _a : undefined,
90
+ title: (_b = (0, utils_1.getTrimmedTextContent)(element, 'journal-title-group > journal-title')) !== null && _b !== void 0 ? _b : undefined,
79
91
  };
80
92
  };
81
93
  exports.parseJournalMeta = parseJournalMeta;