@manuscripts/transform 2.3.34-LEAN-3911.2 → 2.3.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/__tests__/data/project-dump.json +825 -0
- package/dist/cjs/jats/importer/index.js +3 -3
- package/dist/cjs/jats/importer/{jats-dom-parser.js → jats-body-dom-parser.js} +9 -229
- package/dist/cjs/jats/importer/jats-body-transformations.js +0 -70
- package/dist/cjs/jats/importer/jats-comments.js +104 -27
- package/dist/cjs/jats/importer/jats-front-parser.js +321 -0
- package/dist/cjs/jats/importer/jats-journal-meta-parser.js +1 -8
- package/dist/cjs/jats/importer/jats-parser-utils.js +5 -39
- package/dist/cjs/jats/importer/jats-reference-parser.js +27 -16
- package/dist/cjs/jats/importer/jats-references.js +18 -18
- package/dist/cjs/jats/importer/parse-jats-article.js +78 -42
- package/dist/cjs/jats/index.js +3 -4
- package/dist/cjs/jats/jats-exporter.js +354 -251
- package/dist/cjs/lib/utils.js +1 -9
- package/dist/cjs/schema/nodes/inline_footnote.js +1 -0
- package/dist/cjs/transformer/__tests__/__helpers__/doc.js +37 -0
- package/dist/cjs/transformer/builders.js +219 -0
- package/dist/cjs/transformer/decode.js +874 -0
- package/dist/cjs/transformer/document-object-types.js +31 -0
- package/dist/cjs/transformer/encode.js +664 -0
- package/dist/cjs/transformer/footnote-category.js +20 -0
- package/dist/cjs/transformer/footnotes-order.js +60 -0
- package/dist/cjs/transformer/highlight-markers.js +138 -0
- package/dist/cjs/transformer/html.js +400 -0
- package/dist/cjs/transformer/id.js +6 -6
- package/dist/cjs/transformer/index.js +18 -0
- package/dist/cjs/{jats → transformer}/labels.js +3 -3
- package/dist/cjs/transformer/manuscript-dependencies.js +21 -0
- package/dist/cjs/transformer/model-map.js +26 -0
- package/dist/cjs/transformer/models.js +17 -0
- package/dist/cjs/transformer/object-types.js +57 -0
- package/dist/cjs/transformer/project-bundle.js +94 -0
- package/dist/cjs/transformer/serializer.js +23 -0
- package/dist/cjs/transformer/update-identifiers.js +93 -0
- package/dist/cjs/version.js +1 -1
- package/dist/es/__tests__/data/project-dump.json +825 -0
- package/dist/es/jats/importer/index.js +1 -2
- package/dist/es/jats/importer/{jats-dom-parser.js → jats-body-dom-parser.js} +10 -230
- package/dist/es/jats/importer/jats-body-transformations.js +0 -70
- package/dist/es/jats/importer/jats-comments.js +101 -26
- package/dist/es/jats/importer/jats-front-parser.js +315 -0
- package/dist/es/jats/importer/jats-journal-meta-parser.js +0 -6
- package/dist/es/jats/importer/jats-parser-utils.js +6 -40
- package/dist/es/jats/importer/jats-reference-parser.js +27 -16
- package/dist/es/jats/importer/jats-references.js +18 -18
- package/dist/es/jats/importer/parse-jats-article.js +77 -43
- package/dist/es/jats/index.js +1 -3
- package/dist/es/jats/jats-exporter.js +356 -253
- package/dist/es/lib/utils.js +0 -7
- package/dist/es/schema/nodes/inline_footnote.js +1 -0
- package/dist/es/transformer/__tests__/__helpers__/doc.js +29 -0
- package/dist/es/transformer/builders.js +186 -0
- package/dist/es/transformer/decode.js +864 -0
- package/dist/es/transformer/document-object-types.js +28 -0
- package/dist/es/transformer/encode.js +654 -0
- package/dist/{types/jats/importer/create-article-node.d.ts → es/transformer/footnote-category.js} +2 -3
- package/dist/es/transformer/footnotes-order.js +55 -0
- package/dist/es/transformer/highlight-markers.js +132 -0
- package/dist/es/transformer/html.js +393 -0
- package/dist/es/transformer/id.js +4 -5
- package/dist/es/transformer/index.js +16 -0
- package/dist/es/{jats → transformer}/labels.js +3 -3
- package/dist/es/transformer/manuscript-dependencies.js +17 -0
- package/dist/es/transformer/model-map.js +22 -0
- package/dist/es/transformer/models.js +16 -0
- package/dist/es/transformer/object-types.js +52 -0
- package/dist/es/transformer/project-bundle.js +85 -0
- package/dist/es/transformer/serializer.js +17 -0
- package/dist/es/transformer/update-identifiers.js +87 -0
- package/dist/es/version.js +1 -1
- package/dist/types/jats/importer/index.d.ts +1 -2
- package/dist/types/jats/importer/{jats-dom-parser.d.ts → jats-body-dom-parser.d.ts} +1 -1
- package/dist/types/jats/importer/jats-body-transformations.d.ts +0 -5
- package/dist/types/jats/importer/jats-comments.d.ts +10 -4
- package/dist/types/jats/importer/jats-front-parser.d.ts +84 -0
- package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +0 -10
- package/dist/types/jats/importer/jats-references.d.ts +8 -19
- package/dist/types/jats/importer/parse-jats-article.d.ts +5 -12
- package/dist/types/jats/index.d.ts +1 -3
- package/dist/types/jats/jats-exporter.d.ts +29 -10
- package/dist/types/lib/utils.d.ts +0 -3
- package/dist/types/schema/nodes/bibliography_item.d.ts +6 -16
- package/dist/types/schema/nodes/contributor.d.ts +0 -10
- package/dist/types/schema/nodes/keyword_group.d.ts +0 -1
- package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +18 -0
- package/dist/types/transformer/builders.d.ts +61 -0
- package/dist/types/transformer/decode.d.ts +51 -0
- package/dist/types/transformer/document-object-types.d.ts +17 -0
- package/dist/types/transformer/encode.d.ts +29 -0
- package/dist/types/transformer/footnote-category.d.ts +17 -0
- package/dist/types/transformer/footnotes-order.d.ts +22 -0
- package/dist/types/transformer/highlight-markers.d.ts +31 -0
- package/dist/types/transformer/html.d.ts +36 -0
- package/dist/types/transformer/id.d.ts +3 -4
- package/dist/types/transformer/index.d.ts +16 -0
- package/dist/types/{jats → transformer}/labels.d.ts +1 -2
- package/dist/types/transformer/manuscript-dependencies.d.ts +4 -0
- package/dist/types/transformer/model-map.d.ts +19 -0
- package/dist/types/transformer/models.d.ts +48 -0
- package/dist/types/transformer/object-types.d.ts +30 -0
- package/dist/types/transformer/project-bundle.d.ts +30 -0
- package/dist/types/transformer/serializer.d.ts +19 -0
- package/dist/types/transformer/update-identifiers.d.ts +23 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -2
- package/dist/cjs/jats/importer/create-article-node.js +0 -31
- package/dist/cjs/jats/importer/jats-front-transformations.js +0 -262
- package/dist/es/jats/importer/create-article-node.js +0 -27
- package/dist/es/jats/importer/jats-front-transformations.js +0 -259
- package/dist/types/jats/importer/jats-front-transformations.d.ts +0 -38
- /package/dist/cjs/{jats → transformer}/filename.js +0 -0
- /package/dist/cjs/{jats → transformer}/timestamp.js +0 -0
- /package/dist/es/{jats → transformer}/filename.js +0 -0
- /package/dist/es/{jats → transformer}/timestamp.js +0 -0
- /package/dist/types/{jats → transformer}/filename.d.ts +0 -0
- /package/dist/types/{jats → transformer}/timestamp.d.ts +0 -0
|
@@ -14,14 +14,44 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { InvalidInput } from '../../errors';
|
|
17
|
+
import { buildBibliographyElement, buildSection, encode, } from '../../transformer';
|
|
18
|
+
import { buildManuscript } from '../../transformer/builders';
|
|
19
|
+
import { generateID } from '../../transformer/id';
|
|
20
|
+
import { findManuscript } from '../../transformer/project-bundle';
|
|
21
|
+
import { jatsBodyDOMParser } from './jats-body-dom-parser';
|
|
17
22
|
import { jatsBodyTransformations } from './jats-body-transformations';
|
|
18
|
-
import { markComments } from './jats-comments';
|
|
19
|
-
import {
|
|
20
|
-
import { jatsFrontTransformations } from './jats-front-transformations';
|
|
21
|
-
import { parseJournal } from './jats-journal-meta-parser';
|
|
23
|
+
import { createComments, createReferenceComments, markComments, } from './jats-comments';
|
|
24
|
+
import { jatsFrontParser } from './jats-front-parser';
|
|
22
25
|
import { updateDocumentIDs } from './jats-parser-utils';
|
|
23
26
|
import { jatsReferenceParser } from './jats-reference-parser';
|
|
24
|
-
const
|
|
27
|
+
export const parseJATSFront = (doc, front) => {
|
|
28
|
+
const createElement = createElementFn(doc);
|
|
29
|
+
const journal = jatsFrontParser.parseJournal(front.querySelector('journal-meta'));
|
|
30
|
+
const titles = jatsFrontParser.parseTitles(front.querySelector('article-meta > title-group'), createElement);
|
|
31
|
+
const DOI = jatsFrontParser.parseDOI(front);
|
|
32
|
+
const { affiliations, affiliationIDs } = jatsFrontParser.parseAffiliations([
|
|
33
|
+
...front.querySelectorAll('article-meta > contrib-group > aff'),
|
|
34
|
+
]);
|
|
35
|
+
const { footnotes, footnoteIDs, authorNotes, authorNotesParagraphs, correspondingIDs, correspondingList, } = jatsFrontParser.parseAuthorNotes(front.querySelector('article-meta > author-notes'));
|
|
36
|
+
const authors = jatsFrontParser.parseContributors([
|
|
37
|
+
...front.querySelectorAll('article-meta > contrib-group > contrib[contrib-type="author"]'),
|
|
38
|
+
], affiliationIDs, footnoteIDs, correspondingIDs);
|
|
39
|
+
const history = jatsFrontParser.parseDates(front.querySelector('article-meta > history'));
|
|
40
|
+
const counts = jatsFrontParser.parseCounts(front.querySelector('article-meta counts'));
|
|
41
|
+
const manuscript = Object.assign(Object.assign(Object.assign(Object.assign({}, buildManuscript()), counts), history), { DOI });
|
|
42
|
+
return generateIDs([
|
|
43
|
+
manuscript,
|
|
44
|
+
titles,
|
|
45
|
+
journal,
|
|
46
|
+
...authorNotesParagraphs,
|
|
47
|
+
...authorNotes,
|
|
48
|
+
...footnotes,
|
|
49
|
+
...authors,
|
|
50
|
+
...affiliations,
|
|
51
|
+
...correspondingList,
|
|
52
|
+
]);
|
|
53
|
+
};
|
|
54
|
+
export const parseJATSBody = (doc, body, references) => {
|
|
25
55
|
const createElement = createElementFn(doc);
|
|
26
56
|
jatsBodyTransformations.ensureSection(body, createElement);
|
|
27
57
|
jatsBodyTransformations.moveCaptionsToEnd(body);
|
|
@@ -32,58 +62,62 @@ const parseJATSBody = (doc, body, references) => {
|
|
|
32
62
|
jatsBodyTransformations.createSuppleMaterials(doc, body, createElement);
|
|
33
63
|
jatsBodyTransformations.createKeywords(doc, body, createElement);
|
|
34
64
|
jatsBodyTransformations.orderTableFootnote(doc, body);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var _a;
|
|
39
|
-
const createElement = createElementFn(doc);
|
|
40
|
-
jatsFrontTransformations.setArticleAttrs(doc, template);
|
|
41
|
-
const authorNotes = jatsFrontTransformations.createAuthorNotes(doc, createElement);
|
|
42
|
-
if (authorNotes) {
|
|
43
|
-
doc.documentElement.prepend(authorNotes);
|
|
44
|
-
}
|
|
45
|
-
const affiliations = jatsFrontTransformations.createAffiliations(front, createElement);
|
|
46
|
-
if (affiliations) {
|
|
47
|
-
doc.documentElement.prepend(affiliations);
|
|
48
|
-
}
|
|
49
|
-
const contributors = jatsFrontTransformations.createContributors(front, createElement);
|
|
50
|
-
if (contributors) {
|
|
51
|
-
doc.documentElement.prepend(contributors);
|
|
52
|
-
}
|
|
53
|
-
const title = jatsFrontTransformations.createTitle(front, createElement);
|
|
54
|
-
if (title) {
|
|
55
|
-
doc.documentElement.prepend(title);
|
|
65
|
+
const node = jatsBodyDOMParser.parse(body).firstChild;
|
|
66
|
+
if (!node) {
|
|
67
|
+
throw new Error('No content was parsed from the JATS article body');
|
|
56
68
|
}
|
|
57
|
-
|
|
69
|
+
const replacements = new Map(references === null || references === void 0 ? void 0 : references.IDs);
|
|
70
|
+
updateDocumentIDs(node, replacements);
|
|
71
|
+
return encode(node).values();
|
|
72
|
+
};
|
|
73
|
+
const createBibliographyModels = (references) => {
|
|
74
|
+
const models = [];
|
|
75
|
+
const bibliographyItems = references.getBibliographyItems();
|
|
76
|
+
const bibliographyElement = buildBibliographyElement(bibliographyItems);
|
|
77
|
+
const bibliographySection = Object.assign(Object.assign({}, buildSection(99)), { category: 'MPSectionCategory:bibliography', elementIDs: [bibliographyElement._id], title: 'References' });
|
|
78
|
+
const comments = createReferenceComments(references);
|
|
79
|
+
models.push(bibliographySection);
|
|
80
|
+
models.push(bibliographyElement);
|
|
81
|
+
models.push(...bibliographyItems);
|
|
82
|
+
models.push(...comments);
|
|
83
|
+
return models;
|
|
58
84
|
};
|
|
59
85
|
const createElementFn = (doc) => (tagName) => doc.createElement(tagName);
|
|
60
|
-
|
|
86
|
+
const generateIDs = (models) => models.map((m) => m._id ? m : Object.assign(Object.assign({}, m), { _id: generateID(m.objectType) }));
|
|
87
|
+
export const parseJATSArticle = (doc) => {
|
|
61
88
|
const article = doc.querySelector('article');
|
|
62
89
|
const front = doc.querySelector('front');
|
|
63
90
|
const body = doc.querySelector('body');
|
|
64
91
|
const back = doc.querySelector('back');
|
|
65
|
-
if (!
|
|
66
|
-
throw new InvalidInput('
|
|
92
|
+
if (!front) {
|
|
93
|
+
throw new InvalidInput('Invalid JATS format! Missing front element');
|
|
94
|
+
}
|
|
95
|
+
if (!article) {
|
|
96
|
+
throw new InvalidInput('Invalid JATS format! Missing article element');
|
|
67
97
|
}
|
|
68
|
-
markComments(doc);
|
|
69
|
-
const journal = parseJournal(front.querySelector('journal-meta'));
|
|
98
|
+
const marks = markComments(doc);
|
|
70
99
|
const createElement = createElementFn(doc);
|
|
100
|
+
const models = [];
|
|
71
101
|
let references;
|
|
72
102
|
if (back) {
|
|
73
103
|
references = jatsReferenceParser.parseReferences([...back.querySelectorAll('ref-list > ref')], createElement);
|
|
74
104
|
}
|
|
75
|
-
|
|
76
|
-
parseJATSFront(doc, front, template);
|
|
105
|
+
models.push(...parseJATSFront(doc, front));
|
|
77
106
|
if (body) {
|
|
78
|
-
parseJATSBody(doc, body, references);
|
|
107
|
+
models.push(...parseJATSBody(doc, body, references));
|
|
79
108
|
}
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
109
|
+
const modelMap = new Map(models.map((model) => [model._id, model]));
|
|
110
|
+
const manuscript = findManuscript(modelMap);
|
|
111
|
+
if (manuscript) {
|
|
112
|
+
const type = article.getAttribute('article-type');
|
|
113
|
+
manuscript.articleType = type || 'other';
|
|
83
114
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
115
|
+
if (references && references.items.size) {
|
|
116
|
+
models.push(...createBibliographyModels(references));
|
|
117
|
+
}
|
|
118
|
+
if (marks.length) {
|
|
119
|
+
const comments = createComments(models, marks);
|
|
120
|
+
models.push(...comments);
|
|
121
|
+
}
|
|
122
|
+
return models;
|
|
89
123
|
};
|
package/dist/es/jats/index.js
CHANGED
|
@@ -13,8 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export {
|
|
16
|
+
export { parseJATSFront, parseJATSBody, parseJATSArticle } from './importer';
|
|
17
17
|
export * from './jats-exporter';
|
|
18
18
|
export * from './jats-versions';
|
|
19
|
-
export * from './timestamp';
|
|
20
|
-
export * from './labels';
|