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