@manuscripts/transform 1.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.
- package/LICENSE +201 -0
- package/README.md +193 -0
- package/dist/cjs/errors.js +17 -0
- package/dist/cjs/index.js +27 -0
- package/dist/cjs/jats/importer/index.js +24 -0
- package/dist/cjs/jats/importer/jats-body-dom-parser.js +650 -0
- package/dist/cjs/jats/importer/jats-body-transformations.js +269 -0
- package/dist/cjs/jats/importer/jats-comments.js +131 -0
- package/dist/cjs/jats/importer/jats-front-parser.js +341 -0
- package/dist/cjs/jats/importer/jats-journal-meta-parser.js +77 -0
- package/dist/cjs/jats/importer/jats-parser-utils.js +145 -0
- package/dist/cjs/jats/importer/jats-reference-parser.js +180 -0
- package/dist/cjs/jats/importer/parse-jats-article.js +237 -0
- package/dist/cjs/jats/index.js +40 -0
- package/dist/cjs/jats/jats-exporter.js +1569 -0
- package/dist/cjs/jats/jats-versions.js +41 -0
- package/dist/cjs/lib/attributes.js +26 -0
- package/dist/cjs/lib/html.js +48 -0
- package/dist/cjs/lib/styled-content.js +28 -0
- package/dist/cjs/lib/table-cell-styles.js +52 -0
- package/dist/cjs/lib/utils.js +66 -0
- package/dist/cjs/mathjax/index.js +41 -0
- package/dist/cjs/mathjax/mathjax-packages.js +20 -0
- package/dist/cjs/mathjax/mathml-to-svg.js +56 -0
- package/dist/cjs/mathjax/tex-to-mathml.js +49 -0
- package/dist/cjs/mathjax/tex-to-svg.js +59 -0
- package/dist/cjs/schema/groups.js +31 -0
- package/dist/cjs/schema/index.js +195 -0
- package/dist/cjs/schema/marks.js +159 -0
- package/dist/cjs/schema/nodes/attribution.js +32 -0
- package/dist/cjs/schema/nodes/bibliography_element.js +44 -0
- package/dist/cjs/schema/nodes/bibliography_item.js +101 -0
- package/dist/cjs/schema/nodes/bibliography_section.js +46 -0
- package/dist/cjs/schema/nodes/blockquote_element.js +62 -0
- package/dist/cjs/schema/nodes/caption.js +52 -0
- package/dist/cjs/schema/nodes/caption_title.js +51 -0
- package/dist/cjs/schema/nodes/citation.js +52 -0
- package/dist/cjs/schema/nodes/comment.js +26 -0
- package/dist/cjs/schema/nodes/cross_reference.js +58 -0
- package/dist/cjs/schema/nodes/doc.js +21 -0
- package/dist/cjs/schema/nodes/equation.js +55 -0
- package/dist/cjs/schema/nodes/equation_element.js +52 -0
- package/dist/cjs/schema/nodes/figcaption.js +31 -0
- package/dist/cjs/schema/nodes/figure.js +52 -0
- package/dist/cjs/schema/nodes/figure_element.js +78 -0
- package/dist/cjs/schema/nodes/footnote.js +67 -0
- package/dist/cjs/schema/nodes/footnotes_element.js +54 -0
- package/dist/cjs/schema/nodes/footnotes_section.js +45 -0
- package/dist/cjs/schema/nodes/graphical_abstract_section.js +46 -0
- package/dist/cjs/schema/nodes/hard_break.js +30 -0
- package/dist/cjs/schema/nodes/highlight_marker.js +53 -0
- package/dist/cjs/schema/nodes/inline_equation.js +58 -0
- package/dist/cjs/schema/nodes/inline_footnote.js +51 -0
- package/dist/cjs/schema/nodes/keywords_element.js +52 -0
- package/dist/cjs/schema/nodes/keywords_section.js +46 -0
- package/dist/cjs/schema/nodes/link.js +61 -0
- package/dist/cjs/schema/nodes/list.js +121 -0
- package/dist/cjs/schema/nodes/listing.js +73 -0
- package/dist/cjs/schema/nodes/listing_element.js +52 -0
- package/dist/cjs/schema/nodes/manuscript.js +46 -0
- package/dist/cjs/schema/nodes/missing_figure.js +50 -0
- package/dist/cjs/schema/nodes/paragraph.js +63 -0
- package/dist/cjs/schema/nodes/placeholder.js +49 -0
- package/dist/cjs/schema/nodes/placeholder_element.js +48 -0
- package/dist/cjs/schema/nodes/pullquote_element.js +65 -0
- package/dist/cjs/schema/nodes/section.js +94 -0
- package/dist/cjs/schema/nodes/section_label.js +30 -0
- package/dist/cjs/schema/nodes/section_title.js +48 -0
- package/dist/cjs/schema/nodes/table.js +70 -0
- package/dist/cjs/schema/nodes/table_col.js +57 -0
- package/dist/cjs/schema/nodes/table_element.js +62 -0
- package/dist/cjs/schema/nodes/table_row.js +123 -0
- package/dist/cjs/schema/nodes/text.js +21 -0
- package/dist/cjs/schema/nodes/toc_element.js +52 -0
- package/dist/cjs/schema/nodes/toc_section.js +46 -0
- package/dist/cjs/schema/types.js +17 -0
- package/dist/cjs/tests.js +30 -0
- package/dist/cjs/transformer/builders.js +305 -0
- package/dist/cjs/transformer/bundles-data.js +36 -0
- package/dist/cjs/transformer/bundles.js +32 -0
- package/dist/cjs/transformer/decode.js +619 -0
- package/dist/cjs/transformer/document-object-types.js +31 -0
- package/dist/cjs/transformer/encode.js +545 -0
- package/dist/cjs/transformer/filename.js +27 -0
- package/dist/cjs/transformer/footnote-category.js +20 -0
- package/dist/cjs/transformer/footnotes-order.js +59 -0
- package/dist/cjs/transformer/highlight-markers.js +126 -0
- package/dist/cjs/transformer/html.js +414 -0
- package/dist/cjs/transformer/id.js +28 -0
- package/dist/cjs/transformer/index.js +54 -0
- package/dist/cjs/transformer/labels.js +85 -0
- package/dist/cjs/transformer/manuscript-dependencies.js +74 -0
- package/dist/cjs/transformer/model-map.js +26 -0
- package/dist/cjs/transformer/models.js +17 -0
- package/dist/cjs/transformer/node-names.js +42 -0
- package/dist/cjs/transformer/node-title.js +87 -0
- package/dist/cjs/transformer/node-types.js +62 -0
- package/dist/cjs/transformer/object-types.js +57 -0
- package/dist/cjs/transformer/project-bundle.js +86 -0
- package/dist/cjs/transformer/section-category.js +222 -0
- package/dist/cjs/transformer/serializer.js +23 -0
- package/dist/cjs/transformer/shared-data.js +31 -0
- package/dist/cjs/transformer/tei-grobid-importer.js +121 -0
- package/dist/cjs/transformer/timestamp.js +20 -0
- package/dist/cjs/transformer/update-identifiers.js +93 -0
- package/dist/cjs/types.js +2 -0
- package/dist/es/errors.js +12 -0
- package/dist/es/index.js +9 -0
- package/dist/es/jats/importer/index.js +16 -0
- package/dist/es/jats/importer/jats-body-dom-parser.js +644 -0
- package/dist/es/jats/importer/jats-body-transformations.js +266 -0
- package/dist/es/jats/importer/jats-comments.js +124 -0
- package/dist/es/jats/importer/jats-front-parser.js +335 -0
- package/dist/es/jats/importer/jats-journal-meta-parser.js +70 -0
- package/dist/es/jats/importer/jats-parser-utils.js +139 -0
- package/dist/es/jats/importer/jats-reference-parser.js +177 -0
- package/dist/es/jats/importer/parse-jats-article.js +229 -0
- package/dist/es/jats/index.js +18 -0
- package/dist/es/jats/jats-exporter.js +1561 -0
- package/dist/es/jats/jats-versions.js +36 -0
- package/dist/es/lib/attributes.js +22 -0
- package/dist/es/lib/html.js +43 -0
- package/dist/es/lib/styled-content.js +23 -0
- package/dist/es/lib/table-cell-styles.js +47 -0
- package/dist/es/lib/utils.js +59 -0
- package/dist/es/mathjax/index.js +12 -0
- package/dist/es/mathjax/mathjax-packages.js +17 -0
- package/dist/es/mathjax/mathml-to-svg.js +52 -0
- package/dist/es/mathjax/tex-to-mathml.js +45 -0
- package/dist/es/mathjax/tex-to-svg.js +55 -0
- package/dist/es/schema/groups.js +27 -0
- package/dist/es/schema/index.js +178 -0
- package/dist/es/schema/marks.js +156 -0
- package/dist/es/schema/nodes/attribution.js +29 -0
- package/dist/es/schema/nodes/bibliography_element.js +41 -0
- package/dist/es/schema/nodes/bibliography_item.js +98 -0
- package/dist/es/schema/nodes/bibliography_section.js +42 -0
- package/dist/es/schema/nodes/blockquote_element.js +58 -0
- package/dist/es/schema/nodes/caption.js +49 -0
- package/dist/es/schema/nodes/caption_title.js +48 -0
- package/dist/es/schema/nodes/citation.js +48 -0
- package/dist/es/schema/nodes/comment.js +23 -0
- package/dist/es/schema/nodes/cross_reference.js +55 -0
- package/dist/es/schema/nodes/doc.js +18 -0
- package/dist/es/schema/nodes/equation.js +52 -0
- package/dist/es/schema/nodes/equation_element.js +49 -0
- package/dist/es/schema/nodes/figcaption.js +28 -0
- package/dist/es/schema/nodes/figure.js +49 -0
- package/dist/es/schema/nodes/figure_element.js +74 -0
- package/dist/es/schema/nodes/footnote.js +63 -0
- package/dist/es/schema/nodes/footnotes_element.js +50 -0
- package/dist/es/schema/nodes/footnotes_section.js +41 -0
- package/dist/es/schema/nodes/graphical_abstract_section.js +42 -0
- package/dist/es/schema/nodes/hard_break.js +27 -0
- package/dist/es/schema/nodes/highlight_marker.js +49 -0
- package/dist/es/schema/nodes/inline_equation.js +55 -0
- package/dist/es/schema/nodes/inline_footnote.js +47 -0
- package/dist/es/schema/nodes/keywords_element.js +49 -0
- package/dist/es/schema/nodes/keywords_section.js +42 -0
- package/dist/es/schema/nodes/link.js +58 -0
- package/dist/es/schema/nodes/list.js +117 -0
- package/dist/es/schema/nodes/listing.js +69 -0
- package/dist/es/schema/nodes/listing_element.js +49 -0
- package/dist/es/schema/nodes/manuscript.js +43 -0
- package/dist/es/schema/nodes/missing_figure.js +47 -0
- package/dist/es/schema/nodes/paragraph.js +59 -0
- package/dist/es/schema/nodes/placeholder.js +46 -0
- package/dist/es/schema/nodes/placeholder_element.js +45 -0
- package/dist/es/schema/nodes/pullquote_element.js +61 -0
- package/dist/es/schema/nodes/section.js +90 -0
- package/dist/es/schema/nodes/section_label.js +26 -0
- package/dist/es/schema/nodes/section_title.js +44 -0
- package/dist/es/schema/nodes/table.js +67 -0
- package/dist/es/schema/nodes/table_col.js +54 -0
- package/dist/es/schema/nodes/table_element.js +59 -0
- package/dist/es/schema/nodes/table_row.js +120 -0
- package/dist/es/schema/nodes/text.js +18 -0
- package/dist/es/schema/nodes/toc_element.js +49 -0
- package/dist/es/schema/nodes/toc_section.js +42 -0
- package/dist/es/schema/types.js +16 -0
- package/dist/es/tests.js +28 -0
- package/dist/es/transformer/builders.js +261 -0
- package/dist/es/transformer/bundles-data.js +8 -0
- package/dist/es/transformer/bundles.js +27 -0
- package/dist/es/transformer/decode.js +608 -0
- package/dist/es/transformer/document-object-types.js +28 -0
- package/dist/es/transformer/encode.js +535 -0
- package/dist/es/transformer/filename.js +23 -0
- package/dist/es/transformer/footnote-category.js +16 -0
- package/dist/es/transformer/footnotes-order.js +53 -0
- package/dist/es/transformer/highlight-markers.js +120 -0
- package/dist/es/transformer/html.js +407 -0
- package/dist/es/transformer/id.js +23 -0
- package/dist/es/transformer/index.js +38 -0
- package/dist/es/transformer/labels.js +81 -0
- package/dist/es/transformer/manuscript-dependencies.js +64 -0
- package/dist/es/transformer/model-map.js +22 -0
- package/dist/es/transformer/models.js +16 -0
- package/dist/es/transformer/node-names.js +39 -0
- package/dist/es/transformer/node-title.js +82 -0
- package/dist/es/transformer/node-types.js +55 -0
- package/dist/es/transformer/object-types.js +52 -0
- package/dist/es/transformer/project-bundle.js +77 -0
- package/dist/es/transformer/section-category.js +210 -0
- package/dist/es/transformer/serializer.js +17 -0
- package/dist/es/transformer/shared-data.js +1 -0
- package/dist/es/transformer/tei-grobid-importer.js +115 -0
- package/dist/es/transformer/timestamp.js +16 -0
- package/dist/es/transformer/update-identifiers.js +87 -0
- package/dist/es/types.js +1 -0
- package/dist/types/errors.d.ts +6 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/jats/importer/index.d.ts +16 -0
- package/dist/types/jats/importer/jats-body-dom-parser.d.ts +24 -0
- package/dist/types/jats/importer/jats-body-transformations.d.ts +31 -0
- package/dist/types/jats/importer/jats-comments.d.ts +26 -0
- package/dist/types/jats/importer/jats-front-parser.d.ts +62 -0
- package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +37 -0
- package/dist/types/jats/importer/jats-parser-utils.d.ts +23 -0
- package/dist/types/jats/importer/jats-reference-parser.d.ts +23 -0
- package/dist/types/jats/importer/parse-jats-article.d.ts +30 -0
- package/dist/types/jats/index.d.ts +18 -0
- package/dist/types/jats/jats-exporter.d.ts +72 -0
- package/dist/types/jats/jats-versions.d.ts +23 -0
- package/dist/types/lib/attributes.d.ts +20 -0
- package/dist/types/lib/html.d.ts +17 -0
- package/dist/types/lib/styled-content.d.ts +22 -0
- package/dist/types/lib/table-cell-styles.d.ts +27 -0
- package/dist/types/lib/utils.d.ts +26 -0
- package/dist/types/mathjax/index.d.ts +3 -0
- package/dist/types/mathjax/mathjax-packages.d.ts +16 -0
- package/dist/types/mathjax/mathml-to-svg.d.ts +17 -0
- package/dist/types/mathjax/tex-to-mathml.d.ts +17 -0
- package/dist/types/mathjax/tex-to-svg.d.ts +17 -0
- package/dist/types/schema/groups.d.ts +22 -0
- package/dist/types/schema/index.d.ts +65 -0
- package/dist/types/schema/marks.d.ts +27 -0
- package/dist/types/schema/nodes/attribution.d.ts +21 -0
- package/dist/types/schema/nodes/bibliography_element.d.ts +26 -0
- package/dist/types/schema/nodes/bibliography_item.d.ts +36 -0
- package/dist/types/schema/nodes/bibliography_section.d.ts +26 -0
- package/dist/types/schema/nodes/blockquote_element.d.ts +28 -0
- package/dist/types/schema/nodes/caption.d.ts +25 -0
- package/dist/types/schema/nodes/caption_title.d.ts +25 -0
- package/dist/types/schema/nodes/citation.d.ts +27 -0
- package/dist/types/schema/nodes/comment.d.ts +31 -0
- package/dist/types/schema/nodes/cross_reference.d.ts +26 -0
- package/dist/types/schema/nodes/doc.d.ts +17 -0
- package/dist/types/schema/nodes/equation.d.ts +28 -0
- package/dist/types/schema/nodes/equation_element.d.ts +29 -0
- package/dist/types/schema/nodes/figcaption.d.ts +21 -0
- package/dist/types/schema/nodes/figure.d.ts +25 -0
- package/dist/types/schema/nodes/figure_element.d.ts +44 -0
- package/dist/types/schema/nodes/footnote.d.ts +32 -0
- package/dist/types/schema/nodes/footnotes_element.d.ts +28 -0
- package/dist/types/schema/nodes/footnotes_section.d.ts +26 -0
- package/dist/types/schema/nodes/graphical_abstract_section.d.ts +26 -0
- package/dist/types/schema/nodes/hard_break.d.ts +21 -0
- package/dist/types/schema/nodes/highlight_marker.d.ts +29 -0
- package/dist/types/schema/nodes/inline_equation.d.ts +28 -0
- package/dist/types/schema/nodes/inline_footnote.d.ts +27 -0
- package/dist/types/schema/nodes/keywords_element.d.ts +27 -0
- package/dist/types/schema/nodes/keywords_section.d.ts +26 -0
- package/dist/types/schema/nodes/link.d.ts +26 -0
- package/dist/types/schema/nodes/list.d.ts +39 -0
- package/dist/types/schema/nodes/listing.d.ts +33 -0
- package/dist/types/schema/nodes/listing_element.d.ts +29 -0
- package/dist/types/schema/nodes/manuscript.d.ts +23 -0
- package/dist/types/schema/nodes/missing_figure.d.ts +23 -0
- package/dist/types/schema/nodes/paragraph.d.ts +30 -0
- package/dist/types/schema/nodes/placeholder.d.ts +26 -0
- package/dist/types/schema/nodes/placeholder_element.d.ts +25 -0
- package/dist/types/schema/nodes/pullquote_element.d.ts +28 -0
- package/dist/types/schema/nodes/section.d.ts +36 -0
- package/dist/types/schema/nodes/section_label.d.ts +22 -0
- package/dist/types/schema/nodes/section_title.d.ts +22 -0
- package/dist/types/schema/nodes/table.d.ts +27 -0
- package/dist/types/schema/nodes/table_col.d.ts +24 -0
- package/dist/types/schema/nodes/table_element.d.ts +35 -0
- package/dist/types/schema/nodes/table_row.d.ts +41 -0
- package/dist/types/schema/nodes/text.d.ts +17 -0
- package/dist/types/schema/nodes/toc_element.d.ts +27 -0
- package/dist/types/schema/nodes/toc_section.d.ts +26 -0
- package/dist/types/schema/types.d.ts +45 -0
- package/dist/types/tests.d.ts +16 -0
- package/dist/types/transformer/builders.d.ts +74 -0
- package/dist/types/transformer/bundles-data.d.ts +3 -0
- package/dist/types/transformer/bundles.d.ts +3 -0
- package/dist/types/transformer/decode.d.ts +38 -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/filename.d.ts +16 -0
- package/dist/types/transformer/footnote-category.d.ts +17 -0
- package/dist/types/transformer/footnotes-order.d.ts +23 -0
- package/dist/types/transformer/highlight-markers.d.ts +26 -0
- package/dist/types/transformer/html.d.ts +36 -0
- package/dist/types/transformer/id.d.ts +20 -0
- package/dist/types/transformer/index.d.ts +38 -0
- package/dist/types/transformer/labels.d.ts +24 -0
- package/dist/types/transformer/manuscript-dependencies.d.ts +12 -0
- package/dist/types/transformer/model-map.d.ts +19 -0
- package/dist/types/transformer/models.d.ts +48 -0
- package/dist/types/transformer/node-names.d.ts +17 -0
- package/dist/types/transformer/node-title.d.ts +19 -0
- package/dist/types/transformer/node-types.d.ts +22 -0
- package/dist/types/transformer/object-types.d.ts +29 -0
- package/dist/types/transformer/project-bundle.d.ts +30 -0
- package/dist/types/transformer/section-category.d.ts +28 -0
- package/dist/types/transformer/serializer.d.ts +19 -0
- package/dist/types/transformer/shared-data.d.ts +2 -0
- package/dist/types/transformer/tei-grobid-importer.d.ts +20 -0
- package/dist/types/transformer/timestamp.d.ts +16 -0
- package/dist/types/transformer/update-identifiers.d.ts +23 -0
- package/dist/types/types.d.ts +2 -0
- package/package.json +89 -0
|
@@ -0,0 +1,1561 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2019 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 { ObjectTypes, } from '@manuscripts/manuscripts-json-schema';
|
|
17
|
+
import debug from 'debug';
|
|
18
|
+
import { DOMParser, DOMSerializer } from 'prosemirror-model';
|
|
19
|
+
import serializeToXML from 'w3c-xmlserializer';
|
|
20
|
+
import { nodeFromHTML, textFromHTML } from '../lib/html';
|
|
21
|
+
import { normalizeStyleName } from '../lib/styled-content';
|
|
22
|
+
import { iterateChildren } from '../lib/utils';
|
|
23
|
+
import { schema, } from '../schema';
|
|
24
|
+
import { generateAttachmentFilename } from '../transformer/filename';
|
|
25
|
+
import { buildTargets } from '../transformer/labels';
|
|
26
|
+
import { isExecutableNodeType, isNodeType } from '../transformer/node-types';
|
|
27
|
+
import { hasObjectType } from '../transformer/object-types';
|
|
28
|
+
import { findLatestManuscriptSubmission, findManuscript, findManuscriptById, } from '../transformer/project-bundle';
|
|
29
|
+
import { chooseSecType } from '../transformer/section-category';
|
|
30
|
+
import { selectVersionIds } from './jats-versions';
|
|
31
|
+
const warn = debug('manuscripts-transform');
|
|
32
|
+
const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
|
|
33
|
+
const normalizeID = (id) => id.replace(/:/g, '_');
|
|
34
|
+
const parser = DOMParser.fromSchema(schema);
|
|
35
|
+
const findChildNodeOfType = (node, nodeType) => {
|
|
36
|
+
for (const child of iterateChildren(node)) {
|
|
37
|
+
if (child.type === nodeType) {
|
|
38
|
+
return child;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const isContributor = hasObjectType(ObjectTypes.Contributor);
|
|
43
|
+
const CREDIT_VOCAB_IDENTIFIER = 'https://dictionary.casrai.org/Contributor_Roles';
|
|
44
|
+
const chooseRoleVocabAttributes = (role) => {
|
|
45
|
+
if (role.uri && role.uri.startsWith(CREDIT_VOCAB_IDENTIFIER)) {
|
|
46
|
+
return {
|
|
47
|
+
vocab: 'credit',
|
|
48
|
+
'vocab-identifier': CREDIT_VOCAB_IDENTIFIER,
|
|
49
|
+
'vocab-term': role.name,
|
|
50
|
+
'vocab-term-identifier': role.uri,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
vocab: 'uncontrolled',
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const insertAbstractNode = (articleMeta, abstractNode) => {
|
|
58
|
+
const siblings = [
|
|
59
|
+
'kwd-group',
|
|
60
|
+
'funding-group',
|
|
61
|
+
'support-group',
|
|
62
|
+
'conference',
|
|
63
|
+
'counts',
|
|
64
|
+
'custom-meta-group',
|
|
65
|
+
];
|
|
66
|
+
for (const sibling of siblings) {
|
|
67
|
+
const siblingNode = articleMeta.querySelector(`:scope > ${sibling}`);
|
|
68
|
+
if (siblingNode) {
|
|
69
|
+
articleMeta.insertBefore(abstractNode, siblingNode);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
articleMeta.appendChild(abstractNode);
|
|
74
|
+
};
|
|
75
|
+
export const createCounter = () => {
|
|
76
|
+
const counts = new Map();
|
|
77
|
+
return {
|
|
78
|
+
increment: (field) => {
|
|
79
|
+
const value = counts.get(field);
|
|
80
|
+
const newValue = value === undefined ? 1 : value + 1;
|
|
81
|
+
counts.set(field, newValue);
|
|
82
|
+
return newValue;
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
const createDefaultIdGenerator = () => {
|
|
87
|
+
const counter = createCounter();
|
|
88
|
+
return async (element) => {
|
|
89
|
+
const value = String(counter.increment(element.nodeName));
|
|
90
|
+
return `${element.nodeName}-${value}`;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
const chooseRefType = (objectType) => {
|
|
94
|
+
switch (objectType) {
|
|
95
|
+
case ObjectTypes.Figure:
|
|
96
|
+
case ObjectTypes.FigureElement:
|
|
97
|
+
return 'fig';
|
|
98
|
+
case ObjectTypes.Footnote:
|
|
99
|
+
return 'fn';
|
|
100
|
+
case ObjectTypes.Table:
|
|
101
|
+
case ObjectTypes.TableElement:
|
|
102
|
+
return 'table';
|
|
103
|
+
case ObjectTypes.Section:
|
|
104
|
+
return 'sec';
|
|
105
|
+
case ObjectTypes.Equation:
|
|
106
|
+
case ObjectTypes.EquationElement:
|
|
107
|
+
return 'disp-formula';
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const sortContributors = (a, b) => Number(a.priority) - Number(b.priority);
|
|
111
|
+
export class JATSExporter {
|
|
112
|
+
constructor() {
|
|
113
|
+
this.serializeToJATS = async (fragment, modelMap, manuscriptID, options = {}) => {
|
|
114
|
+
const { version = '1.2', doi, id, frontMatterOnly = false, links, idGenerator, mediaPathGenerator, } = options;
|
|
115
|
+
this.modelMap = modelMap;
|
|
116
|
+
this.models = Array.from(this.modelMap.values());
|
|
117
|
+
this.createSerializer();
|
|
118
|
+
const versionIds = selectVersionIds(version);
|
|
119
|
+
this.document = document.implementation.createDocument(null, 'article', document.implementation.createDocumentType('article', versionIds.publicId, versionIds.systemId));
|
|
120
|
+
const article = this.document.documentElement;
|
|
121
|
+
article.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', XLINK_NAMESPACE);
|
|
122
|
+
const front = this.buildFront(doi, id, links);
|
|
123
|
+
article.appendChild(front);
|
|
124
|
+
const manuscript = findManuscriptById(this.modelMap, manuscriptID);
|
|
125
|
+
article.setAttribute('article-type', manuscript.articleType || 'other');
|
|
126
|
+
if (!frontMatterOnly) {
|
|
127
|
+
this.labelTargets = buildTargets(fragment, manuscript);
|
|
128
|
+
const body = this.buildBody(fragment);
|
|
129
|
+
article.appendChild(body);
|
|
130
|
+
const back = this.buildBack(body);
|
|
131
|
+
article.appendChild(back);
|
|
132
|
+
this.moveAbstracts(front, body);
|
|
133
|
+
this.moveFloatsGroup(body, article);
|
|
134
|
+
}
|
|
135
|
+
await this.rewriteIDs(idGenerator);
|
|
136
|
+
if (mediaPathGenerator) {
|
|
137
|
+
await this.rewriteMediaPaths(mediaPathGenerator);
|
|
138
|
+
}
|
|
139
|
+
this.rewriteCrossReferenceTypes();
|
|
140
|
+
return serializeToXML(this.document);
|
|
141
|
+
};
|
|
142
|
+
this.nodeFromJATS = (JATSFragment) => {
|
|
143
|
+
JATSFragment = JATSFragment.trim();
|
|
144
|
+
if (!JATSFragment.length) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
const template = this.document.createElement('template');
|
|
148
|
+
template.innerHTML = JATSFragment;
|
|
149
|
+
return template.firstChild;
|
|
150
|
+
};
|
|
151
|
+
this.rewriteCrossReferenceTypes = () => {
|
|
152
|
+
var _a;
|
|
153
|
+
const figRefs = this.document.querySelectorAll('xref[ref-type=fig][rid]');
|
|
154
|
+
if (!figRefs.length) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
for (const xref of figRefs) {
|
|
158
|
+
const rid = xref.getAttribute('rid');
|
|
159
|
+
if (rid) {
|
|
160
|
+
const nodeName = (_a = this.document.getElementById(rid)) === null || _a === void 0 ? void 0 : _a.nodeName;
|
|
161
|
+
if (nodeName) {
|
|
162
|
+
switch (nodeName) {
|
|
163
|
+
case 'table-wrap-group':
|
|
164
|
+
case 'table-wrap':
|
|
165
|
+
case 'table':
|
|
166
|
+
xref.setAttribute('ref-type', 'table');
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
this.rewriteMediaPaths = async (mediaPathGenerator) => {
|
|
174
|
+
for (const fig of this.document.querySelectorAll('fig')) {
|
|
175
|
+
const parentID = fig.getAttribute('id');
|
|
176
|
+
for (const graphic of fig.querySelectorAll('graphic')) {
|
|
177
|
+
const newHref = await mediaPathGenerator(graphic, parentID);
|
|
178
|
+
graphic.setAttributeNS(XLINK_NAMESPACE, 'href', newHref);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
for (const suppMaterial of this.document.querySelectorAll('supplementary-material')) {
|
|
182
|
+
const newHref = await mediaPathGenerator(suppMaterial, suppMaterial.id);
|
|
183
|
+
suppMaterial.setAttributeNS(XLINK_NAMESPACE, 'href', newHref);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
this.rewriteIDs = async (idGenerator = createDefaultIdGenerator()) => {
|
|
187
|
+
const idMap = new Map();
|
|
188
|
+
for (const element of this.document.querySelectorAll('[id]')) {
|
|
189
|
+
const previousID = element.getAttribute('id');
|
|
190
|
+
const newID = await idGenerator(element);
|
|
191
|
+
if (newID) {
|
|
192
|
+
element.setAttribute('id', newID);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
element.removeAttribute('id');
|
|
196
|
+
}
|
|
197
|
+
if (previousID) {
|
|
198
|
+
idMap.set(previousID, newID);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
for (const node of this.document.querySelectorAll('[rid]')) {
|
|
202
|
+
const rids = node.getAttribute('rid');
|
|
203
|
+
if (rids) {
|
|
204
|
+
const newRIDs = rids
|
|
205
|
+
.split(/\s+/)
|
|
206
|
+
.filter(Boolean)
|
|
207
|
+
.map((previousRID) => idMap.get(previousRID))
|
|
208
|
+
.filter(Boolean);
|
|
209
|
+
if (newRIDs.length) {
|
|
210
|
+
node.setAttribute('rid', newRIDs.join(' '));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
this.setTitleContent = (element, title) => {
|
|
216
|
+
const htmlTitleNode = nodeFromHTML(`<h1>${title}</h1>`);
|
|
217
|
+
if (htmlTitleNode) {
|
|
218
|
+
const titleNode = parser.parse(htmlTitleNode, {
|
|
219
|
+
topNode: schema.nodes.section_title.create(),
|
|
220
|
+
});
|
|
221
|
+
const jatsTitleNode = this.serializeNode(titleNode);
|
|
222
|
+
while (jatsTitleNode.firstChild) {
|
|
223
|
+
element.appendChild(jatsTitleNode.firstChild);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
this.buildFront = (doi, id, links) => {
|
|
228
|
+
var _a, _b, _c, _d;
|
|
229
|
+
const manuscript = findManuscript(this.modelMap);
|
|
230
|
+
const submission = findLatestManuscriptSubmission(this.modelMap, manuscript);
|
|
231
|
+
const front = this.document.createElement('front');
|
|
232
|
+
const journalMeta = this.document.createElement('journal-meta');
|
|
233
|
+
front.appendChild(journalMeta);
|
|
234
|
+
const articleMeta = this.document.createElement('article-meta');
|
|
235
|
+
front.appendChild(articleMeta);
|
|
236
|
+
const journal = [...this.modelMap.values()].find((model) => model.objectType === ObjectTypes.Journal);
|
|
237
|
+
if (journal) {
|
|
238
|
+
if (journal.journalIdentifiers) {
|
|
239
|
+
for (const item of journal.journalIdentifiers) {
|
|
240
|
+
const element = this.document.createElement('journal-id');
|
|
241
|
+
if (item.journalIDType) {
|
|
242
|
+
element.setAttribute('journal-id-type', item.journalIDType);
|
|
243
|
+
}
|
|
244
|
+
element.textContent = item.journalID;
|
|
245
|
+
journalMeta.appendChild(element);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (journal.title || journal.abbreviatedTitles) {
|
|
249
|
+
const parentElement = this.document.createElement('journal-title-group');
|
|
250
|
+
journalMeta.appendChild(parentElement);
|
|
251
|
+
if (journal.title) {
|
|
252
|
+
const element = this.document.createElement('journal-title');
|
|
253
|
+
element.textContent = journal.title;
|
|
254
|
+
parentElement.appendChild(element);
|
|
255
|
+
}
|
|
256
|
+
if (journal.abbreviatedTitles) {
|
|
257
|
+
for (const item of journal.abbreviatedTitles) {
|
|
258
|
+
const element = this.document.createElement('abbrev-journal-title');
|
|
259
|
+
if (item.abbrevType) {
|
|
260
|
+
element.setAttribute('abbrev-type', item.abbrevType);
|
|
261
|
+
}
|
|
262
|
+
element.textContent = item.abbreviatedTitle;
|
|
263
|
+
parentElement.appendChild(element);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (journal.ISSNs) {
|
|
268
|
+
for (const item of journal.ISSNs) {
|
|
269
|
+
const element = this.document.createElement('issn');
|
|
270
|
+
if (item.publicationType) {
|
|
271
|
+
element.setAttribute('pub-type', item.publicationType);
|
|
272
|
+
}
|
|
273
|
+
element.textContent = item.ISSN;
|
|
274
|
+
journalMeta.appendChild(element);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (journal.publisherName) {
|
|
278
|
+
const publisher = this.document.createElement('publisher');
|
|
279
|
+
const publisherName = this.document.createElement('publisher-name');
|
|
280
|
+
publisherName.textContent = journal.publisherName;
|
|
281
|
+
publisher.appendChild(publisherName);
|
|
282
|
+
journalMeta.appendChild(publisher);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
if (submission) {
|
|
287
|
+
if (submission.journalCode) {
|
|
288
|
+
const journalID = this.document.createElement('journal-id');
|
|
289
|
+
journalID.setAttribute('journal-id-type', 'publisher-id');
|
|
290
|
+
journalID.textContent = submission.journalCode;
|
|
291
|
+
journalMeta.appendChild(journalID);
|
|
292
|
+
}
|
|
293
|
+
if (submission.journalTitle) {
|
|
294
|
+
const journalTitleGroup = this.document.createElement('journal-title-group');
|
|
295
|
+
journalMeta.appendChild(journalTitleGroup);
|
|
296
|
+
const journalTitle = this.document.createElement('journal-title');
|
|
297
|
+
journalTitle.textContent = submission.journalTitle;
|
|
298
|
+
journalTitleGroup.appendChild(journalTitle);
|
|
299
|
+
}
|
|
300
|
+
if (submission.issn) {
|
|
301
|
+
const issn = this.document.createElement('issn');
|
|
302
|
+
issn.setAttribute('pub-type', 'epub');
|
|
303
|
+
issn.textContent = submission.issn;
|
|
304
|
+
journalMeta.appendChild(issn);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
if (id) {
|
|
309
|
+
const articleID = this.document.createElement('article-id');
|
|
310
|
+
articleID.setAttribute('pub-id-type', 'publisher-id');
|
|
311
|
+
articleID.textContent = id;
|
|
312
|
+
articleMeta.appendChild(articleID);
|
|
313
|
+
}
|
|
314
|
+
if (doi) {
|
|
315
|
+
const articleID = this.document.createElement('article-id');
|
|
316
|
+
articleID.setAttribute('pub-id-type', 'doi');
|
|
317
|
+
articleID.textContent = doi;
|
|
318
|
+
articleMeta.appendChild(articleID);
|
|
319
|
+
}
|
|
320
|
+
const titleGroup = this.document.createElement('title-group');
|
|
321
|
+
articleMeta.appendChild(titleGroup);
|
|
322
|
+
this.buildContributors(articleMeta);
|
|
323
|
+
if (links && links.self) {
|
|
324
|
+
for (const [key, value] of Object.entries(links.self)) {
|
|
325
|
+
const link = this.document.createElement('self-uri');
|
|
326
|
+
link.setAttribute('content-type', key);
|
|
327
|
+
link.setAttributeNS(XLINK_NAMESPACE, 'href', value);
|
|
328
|
+
articleMeta.appendChild(link);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (manuscript.title) {
|
|
332
|
+
const element = this.document.createElement('article-title');
|
|
333
|
+
this.setTitleContent(element, manuscript.title);
|
|
334
|
+
titleGroup.appendChild(element);
|
|
335
|
+
}
|
|
336
|
+
if (manuscript.subtitle) {
|
|
337
|
+
const element = this.document.createElement('subtitle');
|
|
338
|
+
this.setTitleContent(element, manuscript.subtitle);
|
|
339
|
+
titleGroup.appendChild(element);
|
|
340
|
+
}
|
|
341
|
+
if (manuscript.runningTitle) {
|
|
342
|
+
const element = this.document.createElement('alt-title');
|
|
343
|
+
element.setAttribute('alt-title-type', 'right-running');
|
|
344
|
+
this.setTitleContent(element, manuscript.runningTitle);
|
|
345
|
+
titleGroup.appendChild(element);
|
|
346
|
+
}
|
|
347
|
+
const supplements = [...this.modelMap.values()].filter((model) => model.objectType === ObjectTypes.Supplement);
|
|
348
|
+
if (supplements && supplements.length > 0) {
|
|
349
|
+
for (const supplement of supplements) {
|
|
350
|
+
const supplementaryMaterial = this.document.createElement('supplementary-material');
|
|
351
|
+
supplementaryMaterial.setAttribute('id', normalizeID(supplement._id));
|
|
352
|
+
supplementaryMaterial.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = supplement.href) !== null && _a !== void 0 ? _a : '');
|
|
353
|
+
const mimeType = (_b = supplement.MIME) === null || _b === void 0 ? void 0 : _b.split('/')[0];
|
|
354
|
+
const mimeSubType = (_c = supplement.MIME) === null || _c === void 0 ? void 0 : _c.split('/')[1];
|
|
355
|
+
supplementaryMaterial.setAttribute('mimetype', mimeType !== null && mimeType !== void 0 ? mimeType : '');
|
|
356
|
+
supplementaryMaterial.setAttribute('mime-subtype', mimeSubType !== null && mimeSubType !== void 0 ? mimeSubType : '');
|
|
357
|
+
const caption = this.document.createElement('caption');
|
|
358
|
+
const title = this.document.createElement('title');
|
|
359
|
+
title.textContent = (_d = supplement.title) !== null && _d !== void 0 ? _d : '';
|
|
360
|
+
caption.append(title);
|
|
361
|
+
supplementaryMaterial.append(caption);
|
|
362
|
+
articleMeta.append(supplementaryMaterial);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
const history = articleMeta.querySelector('history') ||
|
|
366
|
+
this.document.createElement('history');
|
|
367
|
+
if (manuscript.acceptanceDate) {
|
|
368
|
+
const date = this.buildDateElement(manuscript.acceptanceDate, 'accepted');
|
|
369
|
+
history.appendChild(date);
|
|
370
|
+
}
|
|
371
|
+
if (manuscript.correctionDate) {
|
|
372
|
+
const date = this.buildDateElement(manuscript.correctionDate, 'corrected');
|
|
373
|
+
history.appendChild(date);
|
|
374
|
+
}
|
|
375
|
+
if (manuscript.retractionDate) {
|
|
376
|
+
const date = this.buildDateElement(manuscript.retractionDate, 'retracted');
|
|
377
|
+
history.appendChild(date);
|
|
378
|
+
}
|
|
379
|
+
if (manuscript.receiveDate) {
|
|
380
|
+
const date = this.buildDateElement(manuscript.receiveDate, 'received');
|
|
381
|
+
history.appendChild(date);
|
|
382
|
+
}
|
|
383
|
+
if (manuscript.revisionReceiveDate) {
|
|
384
|
+
const date = this.buildDateElement(manuscript.revisionReceiveDate, 'rev-recd');
|
|
385
|
+
history.appendChild(date);
|
|
386
|
+
}
|
|
387
|
+
if (manuscript.revisionRequestDate) {
|
|
388
|
+
const date = this.buildDateElement(manuscript.revisionRequestDate, 'rev-request');
|
|
389
|
+
history.appendChild(date);
|
|
390
|
+
}
|
|
391
|
+
if (history.childElementCount) {
|
|
392
|
+
articleMeta.appendChild(history);
|
|
393
|
+
}
|
|
394
|
+
if (manuscript.keywordIDs) {
|
|
395
|
+
this.buildKeywords(articleMeta, manuscript.keywordIDs);
|
|
396
|
+
}
|
|
397
|
+
let countingElements = [];
|
|
398
|
+
if (manuscript.genericCounts) {
|
|
399
|
+
const elements = manuscript.genericCounts.map((el) => {
|
|
400
|
+
const countingElement = this.buildCountingElement('count', el.count);
|
|
401
|
+
if (countingElement) {
|
|
402
|
+
countingElement.setAttribute('count-type', el.countType);
|
|
403
|
+
}
|
|
404
|
+
return countingElement;
|
|
405
|
+
});
|
|
406
|
+
countingElements.push(...elements);
|
|
407
|
+
}
|
|
408
|
+
countingElements.push(this.buildCountingElement('fig-count', manuscript.figureCount));
|
|
409
|
+
countingElements.push(this.buildCountingElement('table-count', manuscript.tableCount));
|
|
410
|
+
countingElements.push(this.buildCountingElement('equation-count', manuscript.equationCount));
|
|
411
|
+
countingElements.push(this.buildCountingElement('ref-count', manuscript.referencesCount));
|
|
412
|
+
countingElements.push(this.buildCountingElement('word-count', manuscript.wordCount));
|
|
413
|
+
countingElements = countingElements.filter((el) => el);
|
|
414
|
+
if (countingElements.length > 0) {
|
|
415
|
+
const counts = this.document.createElement('counts');
|
|
416
|
+
counts.append(...countingElements);
|
|
417
|
+
articleMeta.append(counts);
|
|
418
|
+
}
|
|
419
|
+
if (!journalMeta.hasChildNodes()) {
|
|
420
|
+
journalMeta.remove();
|
|
421
|
+
}
|
|
422
|
+
return front;
|
|
423
|
+
};
|
|
424
|
+
this.buildDateElement = (timestamp, type) => {
|
|
425
|
+
const dateElement = this.document.createElement('date');
|
|
426
|
+
dateElement.setAttribute('date-type', type);
|
|
427
|
+
const date = new Date(timestamp * 1000);
|
|
428
|
+
const lookup = {
|
|
429
|
+
year: date.getUTCFullYear().toString(),
|
|
430
|
+
month: date.getUTCMonth().toString(),
|
|
431
|
+
day: date.getUTCDate().toString(),
|
|
432
|
+
};
|
|
433
|
+
for (const [key, value] of Object.entries(lookup).reverse()) {
|
|
434
|
+
const el = this.document.createElement(key);
|
|
435
|
+
el.textContent = value;
|
|
436
|
+
dateElement.appendChild(el);
|
|
437
|
+
}
|
|
438
|
+
return dateElement;
|
|
439
|
+
};
|
|
440
|
+
this.buildCountingElement = (tagName, count) => {
|
|
441
|
+
if (count) {
|
|
442
|
+
const wordCount = this.document.createElement(tagName);
|
|
443
|
+
wordCount.setAttribute('count', String(count));
|
|
444
|
+
return wordCount;
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
this.buildBody = (fragment) => {
|
|
448
|
+
const content = this.serializeFragment(fragment);
|
|
449
|
+
const body = this.document.createElement('body');
|
|
450
|
+
body.appendChild(content);
|
|
451
|
+
this.fixBody(body, fragment);
|
|
452
|
+
return body;
|
|
453
|
+
};
|
|
454
|
+
this.buildBack = (body) => {
|
|
455
|
+
const back = this.document.createElement('back');
|
|
456
|
+
this.moveSectionsToBack(back, body);
|
|
457
|
+
const footnotesElements = this.document.querySelectorAll('sec > fn-group');
|
|
458
|
+
for (const footnotesElement of footnotesElements) {
|
|
459
|
+
const previousParent = footnotesElement.parentElement;
|
|
460
|
+
back.appendChild(footnotesElement);
|
|
461
|
+
if (previousParent) {
|
|
462
|
+
const title = previousParent.querySelector('title');
|
|
463
|
+
if (title) {
|
|
464
|
+
footnotesElement.insertBefore(title, footnotesElement.firstElementChild);
|
|
465
|
+
}
|
|
466
|
+
if (!previousParent.childElementCount) {
|
|
467
|
+
previousParent.remove();
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
let refList = this.document.querySelector('ref-list');
|
|
472
|
+
if (!refList) {
|
|
473
|
+
warn('No bibliography element, creating a ref-list anyway');
|
|
474
|
+
refList = this.document.createElement('ref-list');
|
|
475
|
+
}
|
|
476
|
+
back.appendChild(refList);
|
|
477
|
+
const bibliographyItems = this.models.filter(hasObjectType(ObjectTypes.BibliographyItem));
|
|
478
|
+
for (const bibliographyItem of bibliographyItems) {
|
|
479
|
+
const ref = this.document.createElement('ref');
|
|
480
|
+
ref.setAttribute('id', normalizeID(bibliographyItem._id));
|
|
481
|
+
const updateCitationPubType = (citationEl, pubType) => {
|
|
482
|
+
if (pubType) {
|
|
483
|
+
switch (pubType) {
|
|
484
|
+
case 'article':
|
|
485
|
+
case 'article-journal':
|
|
486
|
+
citationEl.setAttribute('publication-type', 'journal');
|
|
487
|
+
break;
|
|
488
|
+
default:
|
|
489
|
+
citationEl.setAttribute('publication-type', pubType);
|
|
490
|
+
break;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
citationEl.setAttribute('publication-type', 'journal');
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
if (bibliographyItem.literal) {
|
|
498
|
+
const mixedCitation = this.document.createElement('mixed-citation');
|
|
499
|
+
updateCitationPubType(mixedCitation, bibliographyItem.type);
|
|
500
|
+
mixedCitation.textContent = bibliographyItem.literal;
|
|
501
|
+
ref.appendChild(mixedCitation);
|
|
502
|
+
refList.appendChild(ref);
|
|
503
|
+
}
|
|
504
|
+
else {
|
|
505
|
+
const citation = this.document.createElement('element-citation');
|
|
506
|
+
updateCitationPubType(citation, bibliographyItem.type);
|
|
507
|
+
if (bibliographyItem.author) {
|
|
508
|
+
const personGroupNode = this.document.createElement('person-group');
|
|
509
|
+
personGroupNode.setAttribute('person-group-type', 'author');
|
|
510
|
+
citation.appendChild(personGroupNode);
|
|
511
|
+
bibliographyItem.author.forEach((author) => {
|
|
512
|
+
const name = this.document.createElement('string-name');
|
|
513
|
+
if (author.family) {
|
|
514
|
+
const node = this.document.createElement('surname');
|
|
515
|
+
node.textContent = author.family;
|
|
516
|
+
name.appendChild(node);
|
|
517
|
+
}
|
|
518
|
+
if (author.given) {
|
|
519
|
+
const node = this.document.createElement('given-names');
|
|
520
|
+
node.textContent = author.given;
|
|
521
|
+
name.appendChild(node);
|
|
522
|
+
}
|
|
523
|
+
if (name.hasChildNodes()) {
|
|
524
|
+
personGroupNode.appendChild(name);
|
|
525
|
+
}
|
|
526
|
+
if (author.literal) {
|
|
527
|
+
const collab = this.document.createElement('collab');
|
|
528
|
+
collab.textContent = author.literal;
|
|
529
|
+
personGroupNode.appendChild(collab);
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
if (bibliographyItem.issued) {
|
|
534
|
+
const dateParts = bibliographyItem.issued['date-parts'];
|
|
535
|
+
if (dateParts && dateParts.length) {
|
|
536
|
+
const [[year, month, day]] = dateParts;
|
|
537
|
+
if (year) {
|
|
538
|
+
const node = this.document.createElement('year');
|
|
539
|
+
node.textContent = String(year);
|
|
540
|
+
citation.appendChild(node);
|
|
541
|
+
}
|
|
542
|
+
if (month) {
|
|
543
|
+
const node = this.document.createElement('month');
|
|
544
|
+
node.textContent = String(month);
|
|
545
|
+
citation.appendChild(node);
|
|
546
|
+
}
|
|
547
|
+
if (day) {
|
|
548
|
+
const node = this.document.createElement('day');
|
|
549
|
+
node.textContent = String(day);
|
|
550
|
+
citation.appendChild(node);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
if (bibliographyItem.title) {
|
|
555
|
+
const node = this.document.createElement('article-title');
|
|
556
|
+
this.setTitleContent(node, bibliographyItem.title);
|
|
557
|
+
citation.appendChild(node);
|
|
558
|
+
}
|
|
559
|
+
if (bibliographyItem['container-title']) {
|
|
560
|
+
const node = this.document.createElement('source');
|
|
561
|
+
node.textContent = bibliographyItem['container-title'];
|
|
562
|
+
citation.appendChild(node);
|
|
563
|
+
}
|
|
564
|
+
if (bibliographyItem.volume) {
|
|
565
|
+
const node = this.document.createElement('volume');
|
|
566
|
+
node.textContent = String(bibliographyItem.volume);
|
|
567
|
+
citation.appendChild(node);
|
|
568
|
+
}
|
|
569
|
+
if (bibliographyItem.issue) {
|
|
570
|
+
const node = this.document.createElement('issue');
|
|
571
|
+
node.textContent = String(bibliographyItem.issue);
|
|
572
|
+
citation.appendChild(node);
|
|
573
|
+
}
|
|
574
|
+
if (bibliographyItem.supplement) {
|
|
575
|
+
const node = this.document.createElement('supplement');
|
|
576
|
+
node.textContent = bibliographyItem.supplement;
|
|
577
|
+
citation.appendChild(node);
|
|
578
|
+
}
|
|
579
|
+
if (bibliographyItem.page) {
|
|
580
|
+
const pageString = String(bibliographyItem.page);
|
|
581
|
+
if (/^\d+$/.test(pageString)) {
|
|
582
|
+
const node = this.document.createElement('fpage');
|
|
583
|
+
node.textContent = pageString;
|
|
584
|
+
citation.appendChild(node);
|
|
585
|
+
}
|
|
586
|
+
else if (/^\d+-\d+$/.test(pageString)) {
|
|
587
|
+
const [fpage, lpage] = pageString.split('-');
|
|
588
|
+
const fpageNode = this.document.createElement('fpage');
|
|
589
|
+
fpageNode.textContent = fpage;
|
|
590
|
+
citation.appendChild(fpageNode);
|
|
591
|
+
const lpageNode = this.document.createElement('lpage');
|
|
592
|
+
lpageNode.textContent = lpage;
|
|
593
|
+
citation.appendChild(lpageNode);
|
|
594
|
+
}
|
|
595
|
+
else {
|
|
596
|
+
const node = this.document.createElement('page-range');
|
|
597
|
+
node.textContent = pageString;
|
|
598
|
+
citation.appendChild(node);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
if (bibliographyItem.DOI) {
|
|
602
|
+
const node = this.document.createElement('pub-id');
|
|
603
|
+
node.setAttribute('pub-id-type', 'doi');
|
|
604
|
+
node.textContent = String(bibliographyItem.DOI);
|
|
605
|
+
citation.appendChild(node);
|
|
606
|
+
}
|
|
607
|
+
ref.appendChild(citation);
|
|
608
|
+
refList.appendChild(ref);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return back;
|
|
612
|
+
};
|
|
613
|
+
this.createSerializer = () => {
|
|
614
|
+
const getModel = (id) => id ? this.modelMap.get(id) : undefined;
|
|
615
|
+
const nodes = {
|
|
616
|
+
attribution: () => ['attrib', 0],
|
|
617
|
+
bibliography_element: () => '',
|
|
618
|
+
bibliography_item: () => '',
|
|
619
|
+
bibliography_section: (node) => [
|
|
620
|
+
'ref-list',
|
|
621
|
+
{ id: normalizeID(node.attrs.id) },
|
|
622
|
+
0,
|
|
623
|
+
],
|
|
624
|
+
blockquote_element: () => ['disp-quote', { 'content-type': 'quote' }, 0],
|
|
625
|
+
bullet_list: () => ['list', { 'list-type': 'bullet' }, 0],
|
|
626
|
+
caption: () => ['p', 0],
|
|
627
|
+
caption_title: (node) => {
|
|
628
|
+
if (!node.textContent) {
|
|
629
|
+
return '';
|
|
630
|
+
}
|
|
631
|
+
return ['title', 0];
|
|
632
|
+
},
|
|
633
|
+
citation: (node) => {
|
|
634
|
+
if (!node.attrs.rid) {
|
|
635
|
+
warn(`${node.attrs.id} has no rid`);
|
|
636
|
+
return node.attrs.label;
|
|
637
|
+
}
|
|
638
|
+
const citation = getModel(node.attrs.rid);
|
|
639
|
+
if (!citation) {
|
|
640
|
+
warn(`Missing citation ${node.attrs.rid}`);
|
|
641
|
+
return '';
|
|
642
|
+
}
|
|
643
|
+
const rids = citation.embeddedCitationItems.filter((item) => {
|
|
644
|
+
if (!this.modelMap.has(item.bibliographyItem)) {
|
|
645
|
+
warn(`Missing ${item.bibliographyItem} referenced by ${citation._id}`);
|
|
646
|
+
return false;
|
|
647
|
+
}
|
|
648
|
+
return true;
|
|
649
|
+
});
|
|
650
|
+
if (!rids.length) {
|
|
651
|
+
warn(`${citation._id} has no confirmed rids`);
|
|
652
|
+
return '';
|
|
653
|
+
}
|
|
654
|
+
const xref = this.document.createElement('xref');
|
|
655
|
+
xref.setAttribute('ref-type', 'bibr');
|
|
656
|
+
xref.setAttribute('rid', rids.map((item) => normalizeID(item.bibliographyItem)).join(' '));
|
|
657
|
+
if (node.attrs.contents) {
|
|
658
|
+
const text = textFromHTML(node.attrs.contents);
|
|
659
|
+
if (text !== null && text.length) {
|
|
660
|
+
xref.textContent = text;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
return xref;
|
|
664
|
+
},
|
|
665
|
+
cross_reference: (node) => {
|
|
666
|
+
var _a;
|
|
667
|
+
if (!node.attrs.rid) {
|
|
668
|
+
warn(`${node.attrs.id} has no rid`);
|
|
669
|
+
return node.attrs.label;
|
|
670
|
+
}
|
|
671
|
+
const auxiliaryObjectReference = getModel(node.attrs.rid);
|
|
672
|
+
if (!auxiliaryObjectReference) {
|
|
673
|
+
warn(`Missing model ${node.attrs.rid}`);
|
|
674
|
+
return node.attrs.label;
|
|
675
|
+
}
|
|
676
|
+
const xref = this.document.createElement('xref');
|
|
677
|
+
const referencedObject = getModel(auxiliaryObjectReference.referencedObject ||
|
|
678
|
+
((auxiliaryObjectReference === null || auxiliaryObjectReference === void 0 ? void 0 : auxiliaryObjectReference.referencedObjects) &&
|
|
679
|
+
auxiliaryObjectReference.referencedObjects[0]));
|
|
680
|
+
if (referencedObject) {
|
|
681
|
+
const refType = chooseRefType(referencedObject.objectType);
|
|
682
|
+
if (refType) {
|
|
683
|
+
xref.setAttribute('ref-type', refType);
|
|
684
|
+
}
|
|
685
|
+
else {
|
|
686
|
+
warn(`Unset ref-type for objectType ${referencedObject.objectType}`);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
const getReferencedObjectId = (referencedObject) => {
|
|
690
|
+
return normalizeID(referencedObject);
|
|
691
|
+
};
|
|
692
|
+
if (auxiliaryObjectReference.referencedObjects) {
|
|
693
|
+
const rid = (_a = auxiliaryObjectReference.referencedObjects) === null || _a === void 0 ? void 0 : _a.map((referencedObject) => getReferencedObjectId(referencedObject)).join(' ');
|
|
694
|
+
xref.setAttribute('rid', rid);
|
|
695
|
+
}
|
|
696
|
+
if (auxiliaryObjectReference.referencedObject) {
|
|
697
|
+
const rid = getReferencedObjectId(auxiliaryObjectReference.referencedObject);
|
|
698
|
+
xref.setAttribute('rid', rid);
|
|
699
|
+
}
|
|
700
|
+
xref.textContent = node.attrs.label;
|
|
701
|
+
return xref;
|
|
702
|
+
},
|
|
703
|
+
doc: () => '',
|
|
704
|
+
equation: (node) => {
|
|
705
|
+
const formula = this.document.createElement('disp-formula');
|
|
706
|
+
formula.setAttribute('id', normalizeID(node.attrs.id));
|
|
707
|
+
if (node.attrs.TeXRepresentation) {
|
|
708
|
+
const math = this.document.createElement('tex-math');
|
|
709
|
+
math.textContent = node.attrs.TeXRepresentation;
|
|
710
|
+
formula.appendChild(math);
|
|
711
|
+
}
|
|
712
|
+
else if (node.attrs.MathMLStringRepresentation) {
|
|
713
|
+
const math = this.nodeFromJATS(node.attrs.MathMLStringRepresentation);
|
|
714
|
+
if (math) {
|
|
715
|
+
formula.appendChild(math);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
return formula;
|
|
719
|
+
},
|
|
720
|
+
equation_element: (node) => createFigureElement(node, 'fig', node.type.schema.nodes.equation, 'equation'),
|
|
721
|
+
figcaption: (node) => {
|
|
722
|
+
if (!node.textContent) {
|
|
723
|
+
return '';
|
|
724
|
+
}
|
|
725
|
+
return ['caption', 0];
|
|
726
|
+
},
|
|
727
|
+
figure: (node) => {
|
|
728
|
+
const graphic = this.document.createElement('graphic');
|
|
729
|
+
const filename = generateAttachmentFilename(node.attrs.id, node.attrs.contentType);
|
|
730
|
+
graphic.setAttributeNS(XLINK_NAMESPACE, 'xlink:href', `graphic/${filename}`);
|
|
731
|
+
if (node.attrs.contentType) {
|
|
732
|
+
const [mimeType, mimeSubType] = node.attrs.contentType.split('/');
|
|
733
|
+
if (mimeType) {
|
|
734
|
+
graphic.setAttribute('mimetype', mimeType);
|
|
735
|
+
if (mimeSubType) {
|
|
736
|
+
graphic.setAttribute('mime-subtype', mimeSubType);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
return graphic;
|
|
741
|
+
},
|
|
742
|
+
figure_element: (node) => createFigureElement(node, 'fig', node.type.schema.nodes.figure, 'figure'),
|
|
743
|
+
footnote: (node) => {
|
|
744
|
+
const attrs = {};
|
|
745
|
+
if (node.attrs.id) {
|
|
746
|
+
attrs.id = normalizeID(node.attrs.id);
|
|
747
|
+
}
|
|
748
|
+
if (node.attrs.category) {
|
|
749
|
+
attrs['fn-type'] = node.attrs.category;
|
|
750
|
+
}
|
|
751
|
+
return ['fn', attrs, 0];
|
|
752
|
+
},
|
|
753
|
+
footnotes_element: (node) => {
|
|
754
|
+
const kind = node.attrs.kind;
|
|
755
|
+
let tag = 'fn-group';
|
|
756
|
+
if (kind && kind.includes('table')) {
|
|
757
|
+
tag = 'table-wrap-foot';
|
|
758
|
+
}
|
|
759
|
+
return [tag, { id: normalizeID(node.attrs.id) }, 0];
|
|
760
|
+
},
|
|
761
|
+
footnotes_section: (node) => {
|
|
762
|
+
const attrs = {
|
|
763
|
+
id: normalizeID(node.attrs.id),
|
|
764
|
+
'sec-type': 'endnotes',
|
|
765
|
+
};
|
|
766
|
+
return ['sec', attrs, 0];
|
|
767
|
+
},
|
|
768
|
+
hard_break: () => ['break'],
|
|
769
|
+
highlight_marker: () => '',
|
|
770
|
+
inline_equation: (node) => {
|
|
771
|
+
const formula = this.document.createElement('inline-formula');
|
|
772
|
+
formula.setAttribute('id', normalizeID(node.attrs.id));
|
|
773
|
+
if (node.attrs.TeXRepresentation) {
|
|
774
|
+
const math = this.document.createElement('tex-math');
|
|
775
|
+
math.textContent = node.attrs.TeXRepresentation;
|
|
776
|
+
formula.appendChild(math);
|
|
777
|
+
}
|
|
778
|
+
else if (node.attrs.MathMLRepresentation) {
|
|
779
|
+
const math = this.nodeFromJATS(node.attrs.MathMLRepresentation);
|
|
780
|
+
if (math) {
|
|
781
|
+
formula.appendChild(math);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
else if (node.attrs.SVGRepresentation) {
|
|
785
|
+
const math = this.nodeFromJATS(node.attrs.SVGRepresentation);
|
|
786
|
+
if (math) {
|
|
787
|
+
formula.appendChild(math);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
return formula;
|
|
791
|
+
},
|
|
792
|
+
inline_footnote: (node) => {
|
|
793
|
+
const xref = this.document.createElement('xref');
|
|
794
|
+
xref.setAttribute('ref-type', 'fn');
|
|
795
|
+
xref.setAttribute('rid', normalizeID(node.attrs.rid));
|
|
796
|
+
xref.textContent = node.attrs.contents;
|
|
797
|
+
return xref;
|
|
798
|
+
},
|
|
799
|
+
keywords_element: () => '',
|
|
800
|
+
keywords_section: () => '',
|
|
801
|
+
link: (node) => {
|
|
802
|
+
const text = node.textContent;
|
|
803
|
+
if (!text) {
|
|
804
|
+
return '';
|
|
805
|
+
}
|
|
806
|
+
if (!node.attrs.href) {
|
|
807
|
+
return text;
|
|
808
|
+
}
|
|
809
|
+
const linkNode = this.document.createElement('ext-link');
|
|
810
|
+
linkNode.setAttribute('ext-link-type', 'uri');
|
|
811
|
+
linkNode.setAttributeNS(XLINK_NAMESPACE, 'href', node.attrs.href);
|
|
812
|
+
linkNode.textContent = text;
|
|
813
|
+
if (node.attrs.title) {
|
|
814
|
+
linkNode.setAttributeNS(XLINK_NAMESPACE, 'xlink:title', node.attrs.title);
|
|
815
|
+
}
|
|
816
|
+
return linkNode;
|
|
817
|
+
},
|
|
818
|
+
list_item: () => ['list-item', 0],
|
|
819
|
+
listing: (node) => {
|
|
820
|
+
const code = this.document.createElement('code');
|
|
821
|
+
code.setAttribute('id', normalizeID(node.attrs.id));
|
|
822
|
+
code.setAttribute('language', node.attrs.languageKey);
|
|
823
|
+
code.textContent = node.attrs.contents;
|
|
824
|
+
return code;
|
|
825
|
+
},
|
|
826
|
+
listing_element: (node) => createFigureElement(node, 'fig', node.type.schema.nodes.listing, 'listing'),
|
|
827
|
+
manuscript: (node) => ['article', { id: normalizeID(node.attrs.id) }, 0],
|
|
828
|
+
missing_figure: () => {
|
|
829
|
+
const graphic = this.document.createElement('graphic');
|
|
830
|
+
graphic.setAttribute('specific-use', 'MISSING');
|
|
831
|
+
graphic.setAttributeNS(XLINK_NAMESPACE, 'xlink:href', '');
|
|
832
|
+
return graphic;
|
|
833
|
+
},
|
|
834
|
+
ordered_list: () => ['list', { 'list-type': 'order' }, 0],
|
|
835
|
+
paragraph: (node) => {
|
|
836
|
+
if (!node.childCount) {
|
|
837
|
+
return '';
|
|
838
|
+
}
|
|
839
|
+
const attrs = {};
|
|
840
|
+
if (node.attrs.id) {
|
|
841
|
+
attrs.id = normalizeID(node.attrs.id);
|
|
842
|
+
}
|
|
843
|
+
if (node.attrs.contentType) {
|
|
844
|
+
attrs['content-type'] = node.attrs.contentType;
|
|
845
|
+
}
|
|
846
|
+
return ['p', attrs, 0];
|
|
847
|
+
},
|
|
848
|
+
placeholder: () => {
|
|
849
|
+
return this.document.createElement('boxed-text');
|
|
850
|
+
},
|
|
851
|
+
placeholder_element: () => {
|
|
852
|
+
return this.document.createElement('boxed-text');
|
|
853
|
+
},
|
|
854
|
+
pullquote_element: () => [
|
|
855
|
+
'disp-quote',
|
|
856
|
+
{ 'content-type': 'pullquote' },
|
|
857
|
+
0,
|
|
858
|
+
],
|
|
859
|
+
graphical_abstract_section: (node) => {
|
|
860
|
+
const attrs = {
|
|
861
|
+
id: normalizeID(node.attrs.id),
|
|
862
|
+
};
|
|
863
|
+
attrs['sec-type'] = 'abstract-graphical';
|
|
864
|
+
return ['sec', attrs, 0];
|
|
865
|
+
},
|
|
866
|
+
section: (node) => {
|
|
867
|
+
const attrs = {
|
|
868
|
+
id: normalizeID(node.attrs.id),
|
|
869
|
+
};
|
|
870
|
+
if (node.attrs.category) {
|
|
871
|
+
attrs['sec-type'] = chooseSecType(node.attrs.category);
|
|
872
|
+
}
|
|
873
|
+
return ['sec', attrs, 0];
|
|
874
|
+
},
|
|
875
|
+
section_label: () => ['label', 0],
|
|
876
|
+
section_title: () => ['title', 0],
|
|
877
|
+
table: (node) => ['table', { id: normalizeID(node.attrs.id) }, 0],
|
|
878
|
+
table_element: (node) => {
|
|
879
|
+
const element = createFigureElement(node, 'table-wrap', node.type.schema.nodes.table);
|
|
880
|
+
element.setAttribute('position', 'anchor');
|
|
881
|
+
return element;
|
|
882
|
+
},
|
|
883
|
+
table_body: () => ['tbody', 0],
|
|
884
|
+
table_cell: (node) => [
|
|
885
|
+
node.attrs.celltype,
|
|
886
|
+
Object.assign(Object.assign({ valign: node.attrs.valign, align: node.attrs.align, scope: node.attrs.scope, style: node.attrs.style }, (node.attrs.rowspan > 1 && { rowspan: node.attrs.rowspan })), (node.attrs.colspan > 1 && { colspan: node.attrs.colspan })),
|
|
887
|
+
0,
|
|
888
|
+
],
|
|
889
|
+
table_row: () => ['tr', 0],
|
|
890
|
+
table_col: (node) => ['col', { width: node.attrs.width }],
|
|
891
|
+
table_colgroup: () => ['colgroup', 0],
|
|
892
|
+
text: (node) => node.text,
|
|
893
|
+
toc_element: () => '',
|
|
894
|
+
toc_section: () => '',
|
|
895
|
+
comment: () => '',
|
|
896
|
+
};
|
|
897
|
+
const marks = {
|
|
898
|
+
bold: () => ['bold'],
|
|
899
|
+
code: () => ['code', { position: 'anchor' }],
|
|
900
|
+
italic: () => ['italic'],
|
|
901
|
+
smallcaps: () => ['sc'],
|
|
902
|
+
strikethrough: () => ['strike'],
|
|
903
|
+
styled: (mark) => {
|
|
904
|
+
const inlineStyle = getModel(mark.attrs.rid);
|
|
905
|
+
const attrs = {};
|
|
906
|
+
if (inlineStyle && inlineStyle.title) {
|
|
907
|
+
attrs.style = normalizeStyleName(inlineStyle.title);
|
|
908
|
+
}
|
|
909
|
+
return ['styled-content', attrs];
|
|
910
|
+
},
|
|
911
|
+
superscript: () => ['sup'],
|
|
912
|
+
subscript: () => ['sub'],
|
|
913
|
+
underline: () => ['underline'],
|
|
914
|
+
tracked_insert: () => ['ins'],
|
|
915
|
+
tracked_delete: () => ['del'],
|
|
916
|
+
};
|
|
917
|
+
this.serializer = new DOMSerializer(nodes, marks);
|
|
918
|
+
const createFigureElement = (node, nodeName, contentNodeType, figType) => {
|
|
919
|
+
const element = this.document.createElement(nodeName);
|
|
920
|
+
element.setAttribute('id', normalizeID(node.attrs.id));
|
|
921
|
+
if (figType) {
|
|
922
|
+
element.setAttribute('fig-type', figType);
|
|
923
|
+
}
|
|
924
|
+
if (node.attrs.label) {
|
|
925
|
+
const label = this.document.createElement('label');
|
|
926
|
+
label.textContent = node.attrs.label;
|
|
927
|
+
element.appendChild(label);
|
|
928
|
+
}
|
|
929
|
+
else if (this.labelTargets) {
|
|
930
|
+
const target = this.labelTargets.get(node.attrs.id);
|
|
931
|
+
if (target) {
|
|
932
|
+
const label = this.document.createElement('label');
|
|
933
|
+
label.textContent = target.label;
|
|
934
|
+
element.appendChild(label);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
const figcaptionNode = findChildNodeOfType(node, node.type.schema.nodes.figcaption);
|
|
938
|
+
if (figcaptionNode) {
|
|
939
|
+
element.appendChild(this.serializeNode(figcaptionNode));
|
|
940
|
+
}
|
|
941
|
+
const footnotesNode = findChildNodeOfType(node, node.type.schema.nodes.footnotes_element);
|
|
942
|
+
if (footnotesNode) {
|
|
943
|
+
element.appendChild(this.serializeNode(footnotesNode));
|
|
944
|
+
}
|
|
945
|
+
node.forEach((childNode) => {
|
|
946
|
+
if (childNode.type === contentNodeType) {
|
|
947
|
+
if (childNode.attrs.id) {
|
|
948
|
+
element.appendChild(this.serializeNode(childNode));
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
else if (childNode.type === node.type.schema.nodes.paragraph) {
|
|
952
|
+
element.appendChild(this.serializeNode(childNode));
|
|
953
|
+
}
|
|
954
|
+
else if (childNode.type === node.type.schema.nodes.missing_figure) {
|
|
955
|
+
element.appendChild(this.serializeNode(childNode));
|
|
956
|
+
}
|
|
957
|
+
});
|
|
958
|
+
if (node.attrs.attribution) {
|
|
959
|
+
const attribution = this.document.createElement('attrib');
|
|
960
|
+
attribution.textContent = node.attrs.attribution.literal;
|
|
961
|
+
element.appendChild(attribution);
|
|
962
|
+
}
|
|
963
|
+
if (isExecutableNodeType(node.type)) {
|
|
964
|
+
processExecutableNode(node, element);
|
|
965
|
+
}
|
|
966
|
+
return element;
|
|
967
|
+
};
|
|
968
|
+
const processExecutableNode = (node, element) => {
|
|
969
|
+
const listingNode = findChildNodeOfType(node, node.type.schema.nodes.listing);
|
|
970
|
+
if (listingNode) {
|
|
971
|
+
const { contents, languageKey } = listingNode.attrs;
|
|
972
|
+
if (contents && languageKey) {
|
|
973
|
+
const listing = this.document.createElement('fig');
|
|
974
|
+
listing.setAttribute('specific-use', 'source');
|
|
975
|
+
element.appendChild(listing);
|
|
976
|
+
const code = this.document.createElement('code');
|
|
977
|
+
code.setAttribute('executable', 'true');
|
|
978
|
+
code.setAttribute('language', languageKey);
|
|
979
|
+
code.textContent = contents;
|
|
980
|
+
listing.appendChild(code);
|
|
981
|
+
const caption = this.document.createElement('caption');
|
|
982
|
+
listing.appendChild(caption);
|
|
983
|
+
const attachments = [];
|
|
984
|
+
for (const attachment of attachments) {
|
|
985
|
+
const p = this.document.createElement('p');
|
|
986
|
+
caption.appendChild(p);
|
|
987
|
+
const filename = generateAttachmentFilename(`${listingNode.attrs.id}:${attachment.id}`, attachment.type);
|
|
988
|
+
const supp = this.document.createElement('supplementary-material');
|
|
989
|
+
supp.setAttributeNS(XLINK_NAMESPACE, 'xlink:href', `suppl/${filename}`);
|
|
990
|
+
const [mimeType, mimeSubType] = attachment.type.split('/');
|
|
991
|
+
if (mimeType) {
|
|
992
|
+
supp.setAttribute('mimetype', mimeType);
|
|
993
|
+
if (mimeSubType) {
|
|
994
|
+
supp.setAttribute('mime-subtype', mimeSubType);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
p.appendChild(supp);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
};
|
|
1002
|
+
};
|
|
1003
|
+
this.serializeFragment = (fragment) => this.serializer.serializeFragment(fragment, {
|
|
1004
|
+
document: this.document,
|
|
1005
|
+
});
|
|
1006
|
+
this.serializeNode = (node) => this.serializer.serializeNode(node, {
|
|
1007
|
+
document: this.document,
|
|
1008
|
+
});
|
|
1009
|
+
this.validateContributor = (contributor) => {
|
|
1010
|
+
if (!contributor.bibliographicName) {
|
|
1011
|
+
throw new Error(`${contributor._id} has no bibliographicName`);
|
|
1012
|
+
}
|
|
1013
|
+
const { family, given } = contributor.bibliographicName;
|
|
1014
|
+
if (!family && !given) {
|
|
1015
|
+
throw new Error(`${contributor._id} has neither family nor given name`);
|
|
1016
|
+
}
|
|
1017
|
+
};
|
|
1018
|
+
this.buildContributors = (articleMeta) => {
|
|
1019
|
+
const contributors = this.models.filter(isContributor);
|
|
1020
|
+
const authorContributors = contributors
|
|
1021
|
+
.filter((contributor) => contributor.role === 'author')
|
|
1022
|
+
.sort(sortContributors);
|
|
1023
|
+
const affiliationLabels = new Map();
|
|
1024
|
+
const creatAffiliationLabel = (rid) => {
|
|
1025
|
+
let label = affiliationLabels.get(rid);
|
|
1026
|
+
if (!label) {
|
|
1027
|
+
label = affiliationLabels.size + 1;
|
|
1028
|
+
affiliationLabels.set(rid, label);
|
|
1029
|
+
}
|
|
1030
|
+
const sup = this.document.createElement('sup');
|
|
1031
|
+
sup.textContent = String(label);
|
|
1032
|
+
return sup;
|
|
1033
|
+
};
|
|
1034
|
+
const createFootNotesLabels = (content) => {
|
|
1035
|
+
const sup = this.document.createElement('sup');
|
|
1036
|
+
sup.textContent = String(content);
|
|
1037
|
+
return sup;
|
|
1038
|
+
};
|
|
1039
|
+
if (authorContributors.length) {
|
|
1040
|
+
const contribGroup = this.document.createElement('contrib-group');
|
|
1041
|
+
contribGroup.setAttribute('content-type', 'authors');
|
|
1042
|
+
articleMeta.appendChild(contribGroup);
|
|
1043
|
+
authorContributors.forEach((contributor) => {
|
|
1044
|
+
try {
|
|
1045
|
+
this.validateContributor(contributor);
|
|
1046
|
+
}
|
|
1047
|
+
catch (error) {
|
|
1048
|
+
warn(error.message);
|
|
1049
|
+
return;
|
|
1050
|
+
}
|
|
1051
|
+
const contrib = this.document.createElement('contrib');
|
|
1052
|
+
contrib.setAttribute('contrib-type', 'author');
|
|
1053
|
+
contrib.setAttribute('id', normalizeID(contributor._id));
|
|
1054
|
+
if (contributor.isCorresponding) {
|
|
1055
|
+
contrib.setAttribute('corresp', 'yes');
|
|
1056
|
+
}
|
|
1057
|
+
if (contributor.ORCIDIdentifier) {
|
|
1058
|
+
const identifier = this.document.createElement('contrib-id');
|
|
1059
|
+
identifier.setAttribute('contrib-id-type', 'orcid');
|
|
1060
|
+
identifier.textContent = contributor.ORCIDIdentifier;
|
|
1061
|
+
contrib.appendChild(identifier);
|
|
1062
|
+
}
|
|
1063
|
+
const name = this.buildContributorName(contributor);
|
|
1064
|
+
contrib.appendChild(name);
|
|
1065
|
+
if (contributor.email) {
|
|
1066
|
+
const email = this.document.createElement('email');
|
|
1067
|
+
email.textContent = contributor.email;
|
|
1068
|
+
contrib.appendChild(email);
|
|
1069
|
+
}
|
|
1070
|
+
if (contributor.roles) {
|
|
1071
|
+
contributor.roles.forEach((rid) => {
|
|
1072
|
+
const contributorRole = this.modelMap.get(rid);
|
|
1073
|
+
if (contributorRole) {
|
|
1074
|
+
const role = this.document.createElement('role');
|
|
1075
|
+
const attributes = chooseRoleVocabAttributes(contributorRole);
|
|
1076
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
1077
|
+
role.setAttribute(key, value);
|
|
1078
|
+
}
|
|
1079
|
+
role.textContent = contributorRole.name;
|
|
1080
|
+
contrib.appendChild(role);
|
|
1081
|
+
}
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
if (contributor.affiliations) {
|
|
1085
|
+
contributor.affiliations.forEach((rid) => {
|
|
1086
|
+
const xref = this.document.createElement('xref');
|
|
1087
|
+
xref.setAttribute('ref-type', 'aff');
|
|
1088
|
+
xref.setAttribute('rid', normalizeID(rid));
|
|
1089
|
+
xref.appendChild(creatAffiliationLabel(rid));
|
|
1090
|
+
contrib.appendChild(xref);
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
if (contributor.footnote) {
|
|
1094
|
+
contributor.footnote.map((note) => {
|
|
1095
|
+
const xref = this.document.createElement('xref');
|
|
1096
|
+
xref.setAttribute('ref-type', 'fn');
|
|
1097
|
+
xref.setAttribute('rid', normalizeID(note.noteID));
|
|
1098
|
+
xref.appendChild(createFootNotesLabels(note.noteLabel));
|
|
1099
|
+
contrib.appendChild(xref);
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
if (contributor.corresp) {
|
|
1103
|
+
contributor.corresp.map((corresp) => {
|
|
1104
|
+
const xref = this.document.createElement('xref');
|
|
1105
|
+
xref.setAttribute('ref-type', 'corresp');
|
|
1106
|
+
xref.setAttribute('rid', normalizeID(corresp.correspID));
|
|
1107
|
+
xref.appendChild(createFootNotesLabels(corresp.correspLabel));
|
|
1108
|
+
contrib.appendChild(xref);
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
contribGroup.appendChild(contrib);
|
|
1112
|
+
});
|
|
1113
|
+
const otherContributors = contributors
|
|
1114
|
+
.filter((contributor) => contributor.role !== 'author')
|
|
1115
|
+
.sort(sortContributors);
|
|
1116
|
+
if (otherContributors.length) {
|
|
1117
|
+
const contribGroup = this.document.createElement('contrib-group');
|
|
1118
|
+
articleMeta.appendChild(contribGroup);
|
|
1119
|
+
otherContributors.forEach((contributor) => {
|
|
1120
|
+
try {
|
|
1121
|
+
this.validateContributor(contributor);
|
|
1122
|
+
}
|
|
1123
|
+
catch (error) {
|
|
1124
|
+
warn(error.message);
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
const contrib = this.document.createElement('contrib');
|
|
1128
|
+
contrib.setAttribute('id', normalizeID(contributor._id));
|
|
1129
|
+
const name = this.buildContributorName(contributor);
|
|
1130
|
+
contrib.appendChild(name);
|
|
1131
|
+
if (contributor.email) {
|
|
1132
|
+
const email = this.document.createElement('email');
|
|
1133
|
+
email.textContent = contributor.email;
|
|
1134
|
+
contrib.appendChild(email);
|
|
1135
|
+
}
|
|
1136
|
+
if (contributor.roles) {
|
|
1137
|
+
contributor.roles.forEach((rid) => {
|
|
1138
|
+
const contributorRole = this.modelMap.get(rid);
|
|
1139
|
+
if (contributorRole) {
|
|
1140
|
+
const role = this.document.createElement('role');
|
|
1141
|
+
const attributes = chooseRoleVocabAttributes(contributorRole);
|
|
1142
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
1143
|
+
role.setAttribute(key, value);
|
|
1144
|
+
}
|
|
1145
|
+
role.textContent = contributorRole.name;
|
|
1146
|
+
contrib.appendChild(role);
|
|
1147
|
+
}
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
if (contributor.affiliations) {
|
|
1151
|
+
contributor.affiliations.forEach((rid) => {
|
|
1152
|
+
const xref = this.document.createElement('xref');
|
|
1153
|
+
xref.setAttribute('ref-type', 'aff');
|
|
1154
|
+
xref.setAttribute('rid', normalizeID(rid));
|
|
1155
|
+
xref.appendChild(creatAffiliationLabel(rid));
|
|
1156
|
+
contrib.appendChild(xref);
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
if (contributor.footnote) {
|
|
1160
|
+
contributor.footnote.map((note) => {
|
|
1161
|
+
const xref = this.document.createElement('xref');
|
|
1162
|
+
xref.setAttribute('ref-type', 'fn');
|
|
1163
|
+
xref.setAttribute('rid', normalizeID(note.noteID));
|
|
1164
|
+
xref.appendChild(createFootNotesLabels(note.noteLabel));
|
|
1165
|
+
contrib.appendChild(xref);
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1168
|
+
contribGroup.appendChild(contrib);
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
const affiliationRIDs = [];
|
|
1172
|
+
const sortedContributors = [...authorContributors, ...otherContributors];
|
|
1173
|
+
for (const contributor of sortedContributors) {
|
|
1174
|
+
if (contributor.affiliations) {
|
|
1175
|
+
affiliationRIDs.push(...contributor.affiliations);
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
const affiliations = this.models.filter(hasObjectType(ObjectTypes.Affiliation));
|
|
1179
|
+
if (affiliations) {
|
|
1180
|
+
const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation._id));
|
|
1181
|
+
usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a._id) - affiliationRIDs.indexOf(b._id));
|
|
1182
|
+
usedAffiliations.forEach((affiliation) => {
|
|
1183
|
+
var _a, _b;
|
|
1184
|
+
const aff = this.document.createElement('aff');
|
|
1185
|
+
aff.setAttribute('id', normalizeID(affiliation._id));
|
|
1186
|
+
contribGroup.appendChild(aff);
|
|
1187
|
+
if (affiliation.department) {
|
|
1188
|
+
const department = this.document.createElement('institution');
|
|
1189
|
+
department.setAttribute('content-type', 'dept');
|
|
1190
|
+
department.textContent = affiliation.department;
|
|
1191
|
+
aff.appendChild(department);
|
|
1192
|
+
}
|
|
1193
|
+
if (affiliation.institution) {
|
|
1194
|
+
const institution = this.document.createElement('institution');
|
|
1195
|
+
institution.textContent = affiliation.institution;
|
|
1196
|
+
aff.appendChild(institution);
|
|
1197
|
+
}
|
|
1198
|
+
if (affiliation.addressLine1) {
|
|
1199
|
+
const addressLine = this.document.createElement('addr-line');
|
|
1200
|
+
addressLine.textContent = affiliation.addressLine1;
|
|
1201
|
+
aff.appendChild(addressLine);
|
|
1202
|
+
}
|
|
1203
|
+
if (affiliation.addressLine2) {
|
|
1204
|
+
const addressLine = this.document.createElement('addr-line');
|
|
1205
|
+
addressLine.textContent = affiliation.addressLine2;
|
|
1206
|
+
aff.appendChild(addressLine);
|
|
1207
|
+
}
|
|
1208
|
+
if (affiliation.addressLine3) {
|
|
1209
|
+
const addressLine = this.document.createElement('addr-line');
|
|
1210
|
+
addressLine.textContent = affiliation.addressLine3;
|
|
1211
|
+
aff.appendChild(addressLine);
|
|
1212
|
+
}
|
|
1213
|
+
if (affiliation.city) {
|
|
1214
|
+
const city = this.document.createElement('city');
|
|
1215
|
+
city.textContent = affiliation.city;
|
|
1216
|
+
aff.appendChild(city);
|
|
1217
|
+
}
|
|
1218
|
+
if (affiliation.country) {
|
|
1219
|
+
const country = this.document.createElement('country');
|
|
1220
|
+
country.textContent = affiliation.country;
|
|
1221
|
+
aff.appendChild(country);
|
|
1222
|
+
}
|
|
1223
|
+
if (affiliation.email) {
|
|
1224
|
+
const email = this.document.createElement('email');
|
|
1225
|
+
email.setAttributeNS(XLINK_NAMESPACE, 'href', (_a = affiliation.email.href) !== null && _a !== void 0 ? _a : '');
|
|
1226
|
+
email.textContent = (_b = affiliation.email.text) !== null && _b !== void 0 ? _b : '';
|
|
1227
|
+
aff.appendChild(email);
|
|
1228
|
+
}
|
|
1229
|
+
const labelNumber = affiliationLabels.get(affiliation._id);
|
|
1230
|
+
if (labelNumber) {
|
|
1231
|
+
const label = this.document.createElement('label');
|
|
1232
|
+
label.textContent = String(labelNumber);
|
|
1233
|
+
aff.appendChild(label);
|
|
1234
|
+
}
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
const noteIDs = [];
|
|
1238
|
+
for (const contributor of [...authorContributors, ...otherContributors]) {
|
|
1239
|
+
if (contributor.footnote) {
|
|
1240
|
+
const ids = contributor.footnote.map((note) => {
|
|
1241
|
+
return note.noteID;
|
|
1242
|
+
});
|
|
1243
|
+
noteIDs.push(...ids);
|
|
1244
|
+
}
|
|
1245
|
+
if (contributor.corresp) {
|
|
1246
|
+
const ids = contributor.corresp.map((corresp) => {
|
|
1247
|
+
return corresp.correspID;
|
|
1248
|
+
});
|
|
1249
|
+
noteIDs.push(...ids);
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
const footnotes = [];
|
|
1253
|
+
footnotes.push(...this.models.filter(hasObjectType(ObjectTypes.Footnote)));
|
|
1254
|
+
const correspodings = [];
|
|
1255
|
+
correspodings.push(...this.models.filter(hasObjectType(ObjectTypes.Corresponding)));
|
|
1256
|
+
if (footnotes || correspodings) {
|
|
1257
|
+
const authorNotesEl = this.document.createElement('author-notes');
|
|
1258
|
+
const usedFootnotes = footnotes.filter((footnote) => {
|
|
1259
|
+
return noteIDs.includes(footnote._id);
|
|
1260
|
+
});
|
|
1261
|
+
const usedCorrespodings = correspodings.filter((corresp) => {
|
|
1262
|
+
return noteIDs.includes(corresp._id);
|
|
1263
|
+
});
|
|
1264
|
+
usedFootnotes.forEach((footnote) => {
|
|
1265
|
+
const authorFootNote = this.document.createElement('fn');
|
|
1266
|
+
authorFootNote.setAttribute('id', normalizeID(footnote._id));
|
|
1267
|
+
authorFootNote.innerHTML = footnote.contents;
|
|
1268
|
+
authorNotesEl.appendChild(authorFootNote);
|
|
1269
|
+
});
|
|
1270
|
+
usedCorrespodings.forEach((corresponding) => {
|
|
1271
|
+
const correspondingEl = this.document.createElement('corresp');
|
|
1272
|
+
correspondingEl.setAttribute('id', normalizeID(corresponding._id));
|
|
1273
|
+
if (corresponding.label) {
|
|
1274
|
+
const labelEl = this.document.createElement('label');
|
|
1275
|
+
labelEl.textContent = corresponding.label;
|
|
1276
|
+
correspondingEl.appendChild(labelEl);
|
|
1277
|
+
}
|
|
1278
|
+
correspondingEl.append(corresponding.contents);
|
|
1279
|
+
authorNotesEl.appendChild(correspondingEl);
|
|
1280
|
+
});
|
|
1281
|
+
if (authorNotesEl.childNodes.length > 0) {
|
|
1282
|
+
articleMeta.appendChild(authorNotesEl);
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
};
|
|
1287
|
+
this.fixBody = (body, fragment) => {
|
|
1288
|
+
fragment.descendants((node) => {
|
|
1289
|
+
if (node.attrs.id) {
|
|
1290
|
+
if (node.attrs.titleSuppressed) {
|
|
1291
|
+
const title = body.querySelector(`#${normalizeID(node.attrs.id)} > title`);
|
|
1292
|
+
if (title && title.parentNode) {
|
|
1293
|
+
title.parentNode.removeChild(title);
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
if (node.attrs.suppressCaption) {
|
|
1297
|
+
const caption = body.querySelector(`#${normalizeID(node.attrs.id)} > caption`);
|
|
1298
|
+
if (caption) {
|
|
1299
|
+
caption.remove();
|
|
1300
|
+
}
|
|
1301
|
+
const label = body.querySelector(`#${normalizeID(node.attrs.id)} > label`);
|
|
1302
|
+
if (label) {
|
|
1303
|
+
label.remove();
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
if (isNodeType(node, 'table_element')) {
|
|
1307
|
+
const tableElement = body.querySelector(`#${normalizeID(node.attrs.id)}`);
|
|
1308
|
+
if (tableElement) {
|
|
1309
|
+
for (const childNode of tableElement.childNodes) {
|
|
1310
|
+
switch (childNode.nodeName) {
|
|
1311
|
+
case 'caption': {
|
|
1312
|
+
if (node.attrs.suppressCaption) {
|
|
1313
|
+
tableElement.removeChild(childNode);
|
|
1314
|
+
}
|
|
1315
|
+
else {
|
|
1316
|
+
const label = tableElement.querySelector('label');
|
|
1317
|
+
tableElement.insertBefore(childNode, label ? label.nextSibling : tableElement.firstChild);
|
|
1318
|
+
}
|
|
1319
|
+
break;
|
|
1320
|
+
}
|
|
1321
|
+
case 'table': {
|
|
1322
|
+
this.fixTable(childNode, node);
|
|
1323
|
+
break;
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
});
|
|
1331
|
+
};
|
|
1332
|
+
this.changeTag = (node, tag) => {
|
|
1333
|
+
const clone = this.document.createElement(tag);
|
|
1334
|
+
for (const attr of node.attributes) {
|
|
1335
|
+
clone.setAttributeNS(null, attr.name, attr.value);
|
|
1336
|
+
}
|
|
1337
|
+
while (node.firstChild) {
|
|
1338
|
+
clone.appendChild(node.firstChild);
|
|
1339
|
+
}
|
|
1340
|
+
node.replaceWith(clone);
|
|
1341
|
+
return clone;
|
|
1342
|
+
};
|
|
1343
|
+
this.fixTable = (table, node) => {
|
|
1344
|
+
let tbody;
|
|
1345
|
+
Array.from(table.childNodes).forEach((child) => {
|
|
1346
|
+
if (child instanceof Element && child.tagName.toLowerCase() === 'tbody') {
|
|
1347
|
+
tbody = child;
|
|
1348
|
+
}
|
|
1349
|
+
});
|
|
1350
|
+
if (!tbody) {
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
const tbodyRows = Array.from(tbody.childNodes);
|
|
1354
|
+
const thead = this.document.createElement('thead');
|
|
1355
|
+
const tfoot = this.document.createElement('tfoot');
|
|
1356
|
+
tbodyRows.forEach((row, i) => {
|
|
1357
|
+
const isRow = row instanceof Element && row.tagName.toLowerCase() === 'tr';
|
|
1358
|
+
if (isRow) {
|
|
1359
|
+
const headerCell = row.querySelector('th[scope="col"], th[scope="colgroup"]');
|
|
1360
|
+
if (i === 0 || headerCell) {
|
|
1361
|
+
tbody === null || tbody === void 0 ? void 0 : tbody.removeChild(row);
|
|
1362
|
+
if (!node.attrs.suppressHeader) {
|
|
1363
|
+
const tableCells = row.querySelectorAll('td');
|
|
1364
|
+
for (const td of tableCells) {
|
|
1365
|
+
this.changeTag(td, 'th');
|
|
1366
|
+
}
|
|
1367
|
+
thead.appendChild(row);
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
else if (i === tbodyRows.length - 1) {
|
|
1371
|
+
tbody === null || tbody === void 0 ? void 0 : tbody.removeChild(row);
|
|
1372
|
+
if (!node.attrs.suppressFooter) {
|
|
1373
|
+
tfoot.appendChild(row);
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
});
|
|
1378
|
+
if (thead.hasChildNodes()) {
|
|
1379
|
+
table.insertBefore(thead, tbody);
|
|
1380
|
+
}
|
|
1381
|
+
if (tfoot.hasChildNodes()) {
|
|
1382
|
+
table.insertBefore(tfoot, tbody);
|
|
1383
|
+
}
|
|
1384
|
+
};
|
|
1385
|
+
this.moveAbstracts = (front, body) => {
|
|
1386
|
+
const sections = body.querySelectorAll(':scope > sec');
|
|
1387
|
+
const abstractSections = Array.from(sections).filter((section) => {
|
|
1388
|
+
const sectionType = section.getAttribute('sec-type');
|
|
1389
|
+
if (sectionType === 'abstract' ||
|
|
1390
|
+
sectionType === 'abstract-teaser' ||
|
|
1391
|
+
sectionType === 'abstract-graphical') {
|
|
1392
|
+
return true;
|
|
1393
|
+
}
|
|
1394
|
+
const sectionTitle = section.querySelector(':scope > title');
|
|
1395
|
+
if (!sectionTitle) {
|
|
1396
|
+
return false;
|
|
1397
|
+
}
|
|
1398
|
+
return sectionTitle.textContent === 'Abstract';
|
|
1399
|
+
});
|
|
1400
|
+
if (abstractSections.length) {
|
|
1401
|
+
for (const abstractSection of abstractSections) {
|
|
1402
|
+
const abstractNode = this.document.createElement('abstract');
|
|
1403
|
+
for (const node of abstractSection.childNodes) {
|
|
1404
|
+
if (node.nodeName !== 'title') {
|
|
1405
|
+
abstractNode.appendChild(node.cloneNode(true));
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
const sectionType = abstractSection.getAttribute('sec-type');
|
|
1409
|
+
if (sectionType && sectionType !== 'abstract') {
|
|
1410
|
+
const [, abstractType] = sectionType.split('-', 2);
|
|
1411
|
+
abstractNode.setAttribute('abstract-type', abstractType);
|
|
1412
|
+
}
|
|
1413
|
+
abstractSection.remove();
|
|
1414
|
+
const articleMeta = front.querySelector(':scope > article-meta');
|
|
1415
|
+
if (articleMeta) {
|
|
1416
|
+
insertAbstractNode(articleMeta, abstractNode);
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
};
|
|
1421
|
+
this.moveSectionsToBack = (back, body) => {
|
|
1422
|
+
const availabilitySection = body.querySelector('sec[sec-type="availability"]');
|
|
1423
|
+
if (availabilitySection) {
|
|
1424
|
+
back.insertBefore(availabilitySection, back.firstChild);
|
|
1425
|
+
}
|
|
1426
|
+
const section = body.querySelector('sec[sec-type="acknowledgments"]');
|
|
1427
|
+
if (section) {
|
|
1428
|
+
const ack = this.document.createElement('ack');
|
|
1429
|
+
while (section.firstChild) {
|
|
1430
|
+
ack.appendChild(section.firstChild);
|
|
1431
|
+
}
|
|
1432
|
+
if (section.parentNode) {
|
|
1433
|
+
section.parentNode.removeChild(section);
|
|
1434
|
+
}
|
|
1435
|
+
back.insertBefore(ack, back.firstChild);
|
|
1436
|
+
}
|
|
1437
|
+
const appendicesSections = body.querySelectorAll('sec[sec-type="appendices"]');
|
|
1438
|
+
if (appendicesSections) {
|
|
1439
|
+
const appGroup = this.document.createElement('app-group');
|
|
1440
|
+
appendicesSections.forEach((section) => {
|
|
1441
|
+
if (section.parentNode) {
|
|
1442
|
+
section.parentNode.removeChild(section);
|
|
1443
|
+
}
|
|
1444
|
+
const app = this.document.createElement('app');
|
|
1445
|
+
app.appendChild(section);
|
|
1446
|
+
appGroup.appendChild(app);
|
|
1447
|
+
});
|
|
1448
|
+
back.insertBefore(appGroup, back.firstChild);
|
|
1449
|
+
}
|
|
1450
|
+
const footNotes = [];
|
|
1451
|
+
const footnoteCategories = [
|
|
1452
|
+
'con',
|
|
1453
|
+
'conflict',
|
|
1454
|
+
'deceased',
|
|
1455
|
+
'equal',
|
|
1456
|
+
'present-address',
|
|
1457
|
+
'presented-at',
|
|
1458
|
+
'previously-at',
|
|
1459
|
+
'supplementary-material',
|
|
1460
|
+
'supported-by',
|
|
1461
|
+
'financial-disclosure',
|
|
1462
|
+
'ethics-statement',
|
|
1463
|
+
'competing-interests',
|
|
1464
|
+
];
|
|
1465
|
+
const sections = body.querySelectorAll('sec');
|
|
1466
|
+
for (const currentSection of sections) {
|
|
1467
|
+
const currentSectionType = currentSection.getAttribute('sec-type');
|
|
1468
|
+
if (currentSectionType &&
|
|
1469
|
+
footnoteCategories.indexOf(currentSectionType) >= 0) {
|
|
1470
|
+
footNotes.push(this.sectionToFootnote(currentSection, currentSectionType));
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
if (footNotes.length > 0) {
|
|
1474
|
+
const fnGroup = this.document.createElement('fn-group');
|
|
1475
|
+
fnGroup.append(...footNotes);
|
|
1476
|
+
back.append(fnGroup);
|
|
1477
|
+
}
|
|
1478
|
+
};
|
|
1479
|
+
this.sectionToFootnote = (section, fnType) => {
|
|
1480
|
+
const footNote = this.document.createElement('fn');
|
|
1481
|
+
footNote.setAttribute('fn-type', fnType);
|
|
1482
|
+
const title = section.querySelector('title');
|
|
1483
|
+
if (title) {
|
|
1484
|
+
const footNoteTitle = this.document.createElement('p');
|
|
1485
|
+
footNoteTitle.setAttribute('content-type', 'fn-title');
|
|
1486
|
+
footNoteTitle.textContent = title.textContent;
|
|
1487
|
+
section.removeChild(title);
|
|
1488
|
+
footNote.append(footNoteTitle);
|
|
1489
|
+
}
|
|
1490
|
+
footNote.append(...section.children);
|
|
1491
|
+
if (section.parentNode) {
|
|
1492
|
+
section.parentNode.removeChild(section);
|
|
1493
|
+
}
|
|
1494
|
+
return footNote;
|
|
1495
|
+
};
|
|
1496
|
+
this.moveFloatsGroup = (body, article) => {
|
|
1497
|
+
const floatsGroup = this.document.createElement('floats-group');
|
|
1498
|
+
const section = body.querySelector('sec[sec-type="floating-element"]');
|
|
1499
|
+
if (section) {
|
|
1500
|
+
floatsGroup.append(...section.children);
|
|
1501
|
+
if (section === null || section === void 0 ? void 0 : section.parentNode) {
|
|
1502
|
+
section.parentNode.removeChild(section);
|
|
1503
|
+
}
|
|
1504
|
+
article.appendChild(floatsGroup);
|
|
1505
|
+
}
|
|
1506
|
+
};
|
|
1507
|
+
this.buildContributorName = (contributor) => {
|
|
1508
|
+
const name = this.document.createElement('name');
|
|
1509
|
+
if (contributor.bibliographicName.family) {
|
|
1510
|
+
const surname = this.document.createElement('surname');
|
|
1511
|
+
surname.textContent = contributor.bibliographicName.family;
|
|
1512
|
+
name.appendChild(surname);
|
|
1513
|
+
}
|
|
1514
|
+
if (contributor.bibliographicName.given) {
|
|
1515
|
+
const givenNames = this.document.createElement('given-names');
|
|
1516
|
+
givenNames.textContent = contributor.bibliographicName.given;
|
|
1517
|
+
name.appendChild(givenNames);
|
|
1518
|
+
}
|
|
1519
|
+
return name;
|
|
1520
|
+
};
|
|
1521
|
+
}
|
|
1522
|
+
buildKeywords(articleMeta, keywordIDs) {
|
|
1523
|
+
const keywords = keywordIDs
|
|
1524
|
+
.map((id) => this.modelMap.get(id))
|
|
1525
|
+
.filter((model) => model && model.name);
|
|
1526
|
+
const keywordGroups = new Map();
|
|
1527
|
+
keywords.forEach((keyword) => {
|
|
1528
|
+
const containedGroup = keyword.containedGroup || '';
|
|
1529
|
+
const group = keywordGroups.get(containedGroup);
|
|
1530
|
+
if (group) {
|
|
1531
|
+
group.push(keyword);
|
|
1532
|
+
}
|
|
1533
|
+
else {
|
|
1534
|
+
keywordGroups.set(containedGroup, [keyword]);
|
|
1535
|
+
}
|
|
1536
|
+
});
|
|
1537
|
+
for (const [groupID, keywords] of keywordGroups) {
|
|
1538
|
+
const keywordGroup = (this.modelMap.get(groupID) || {});
|
|
1539
|
+
const kwdGroup = this.document.createElement('kwd-group');
|
|
1540
|
+
if (keywordGroup.type) {
|
|
1541
|
+
kwdGroup.setAttribute('kwd-group-type', keywordGroup.type);
|
|
1542
|
+
}
|
|
1543
|
+
if (keywordGroup.label) {
|
|
1544
|
+
const label = this.document.createElement('label');
|
|
1545
|
+
label.textContent = keywordGroup.label;
|
|
1546
|
+
kwdGroup.appendChild(label);
|
|
1547
|
+
}
|
|
1548
|
+
if (keywordGroup.title) {
|
|
1549
|
+
const title = this.document.createElement('title');
|
|
1550
|
+
title.textContent = keywordGroup.title;
|
|
1551
|
+
kwdGroup.appendChild(title);
|
|
1552
|
+
}
|
|
1553
|
+
articleMeta.appendChild(kwdGroup);
|
|
1554
|
+
for (const keyword of keywords) {
|
|
1555
|
+
const kwd = this.document.createElement('kwd');
|
|
1556
|
+
kwd.textContent = keyword.name;
|
|
1557
|
+
kwdGroup.appendChild(kwd);
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
}
|