@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,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* © 2020 Atypon Systems LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.jatsBodyTransformations = void 0;
|
|
19
|
+
const transformer_1 = require("../../transformer");
|
|
20
|
+
const removeNodeFromParent = (node) => node.parentNode && node.parentNode.removeChild(node);
|
|
21
|
+
const capitalizeFirstLetter = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
22
|
+
exports.jatsBodyTransformations = {
|
|
23
|
+
ensureSection(body, createElement) {
|
|
24
|
+
let section = createElement('sec');
|
|
25
|
+
const title = section.querySelector('title');
|
|
26
|
+
if (!title) {
|
|
27
|
+
const title = createElement('title');
|
|
28
|
+
title.textContent = '';
|
|
29
|
+
section.appendChild(title);
|
|
30
|
+
}
|
|
31
|
+
const { firstElementChild } = body;
|
|
32
|
+
if (firstElementChild && firstElementChild.tagName === 'sec') {
|
|
33
|
+
section = firstElementChild;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
body.insertBefore(section, body.firstChild);
|
|
37
|
+
}
|
|
38
|
+
body.childNodes.forEach((child) => {
|
|
39
|
+
if (child.nodeType === Node.ELEMENT_NODE) {
|
|
40
|
+
const element = child;
|
|
41
|
+
if (element.tagName !== 'sec') {
|
|
42
|
+
section.appendChild(element);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
section = element;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
createAbstract(abstractNode, createElement) {
|
|
51
|
+
const abstractType = abstractNode.getAttribute('abstract-type');
|
|
52
|
+
const section = createElement('sec');
|
|
53
|
+
const sectionType = abstractType ? `abstract-${abstractType}` : 'abstract';
|
|
54
|
+
section.setAttribute('sec-type', sectionType);
|
|
55
|
+
const title = createElement('title');
|
|
56
|
+
title.textContent = abstractType
|
|
57
|
+
? `${capitalizeFirstLetter(abstractType)} Abstract`
|
|
58
|
+
: 'Abstract';
|
|
59
|
+
section.appendChild(title);
|
|
60
|
+
while (abstractNode.firstChild) {
|
|
61
|
+
section.appendChild(abstractNode.firstChild);
|
|
62
|
+
}
|
|
63
|
+
return section;
|
|
64
|
+
},
|
|
65
|
+
createAcknowledgments(ackNode, createElement) {
|
|
66
|
+
const section = createElement('sec');
|
|
67
|
+
section.setAttribute('sec-type', 'acknowledgments');
|
|
68
|
+
const titleNode = ackNode.querySelector('title');
|
|
69
|
+
if (titleNode) {
|
|
70
|
+
section.appendChild(titleNode);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const title = createElement('title');
|
|
74
|
+
title.textContent = 'Acknowledgements';
|
|
75
|
+
section.appendChild(title);
|
|
76
|
+
}
|
|
77
|
+
while (ackNode.firstChild) {
|
|
78
|
+
section.appendChild(ackNode.firstChild);
|
|
79
|
+
}
|
|
80
|
+
return section;
|
|
81
|
+
},
|
|
82
|
+
createBibliography(doc, references, createElement) {
|
|
83
|
+
const bibSec = doc.createElement('sec');
|
|
84
|
+
bibSec.setAttribute('sec-type', 'bibliography');
|
|
85
|
+
const titleNode = doc.querySelector('back > ref-list > title');
|
|
86
|
+
if (titleNode) {
|
|
87
|
+
bibSec.appendChild(titleNode);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const title = createElement('title');
|
|
91
|
+
title.textContent = 'References';
|
|
92
|
+
bibSec.appendChild(title);
|
|
93
|
+
}
|
|
94
|
+
const refList = doc.createElement('ref-list');
|
|
95
|
+
for (const ref of references) {
|
|
96
|
+
const item = doc.createElement('ref');
|
|
97
|
+
item.setAttribute('id', ref._id);
|
|
98
|
+
item.setAttribute('type', ref.type);
|
|
99
|
+
item.setAttribute('author', JSON.stringify(ref.author));
|
|
100
|
+
item.setAttribute('issued', JSON.stringify(ref.issued));
|
|
101
|
+
ref['container-title'] &&
|
|
102
|
+
item.setAttribute('container-title', ref['container-title']);
|
|
103
|
+
ref.DOI && item.setAttribute('doi', ref.DOI);
|
|
104
|
+
ref.volume && item.setAttribute('volume', ref.volume.toString());
|
|
105
|
+
ref.issue && item.setAttribute('issue', ref.issue.toString());
|
|
106
|
+
ref.supplement && item.setAttribute('supplement', ref.supplement);
|
|
107
|
+
ref.page && item.setAttribute('page', ref.page.toString());
|
|
108
|
+
ref.title && item.setAttribute('title', ref.title);
|
|
109
|
+
ref.literal && item.setAttribute('literal', ref.literal);
|
|
110
|
+
refList.appendChild(item);
|
|
111
|
+
}
|
|
112
|
+
bibSec.appendChild(refList);
|
|
113
|
+
return bibSec;
|
|
114
|
+
},
|
|
115
|
+
createFootnotes(footnoteGroups, createElement) {
|
|
116
|
+
const section = createElement('sec');
|
|
117
|
+
section.setAttribute('sec-type', 'endnotes');
|
|
118
|
+
const titleNode = footnoteGroups
|
|
119
|
+
.map((g) => g.querySelector('title'))
|
|
120
|
+
.filter((t) => t !== null)[0];
|
|
121
|
+
if (titleNode) {
|
|
122
|
+
section.appendChild(titleNode);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
const title = createElement('title');
|
|
126
|
+
title.textContent = 'Footnotes';
|
|
127
|
+
section.appendChild(title);
|
|
128
|
+
}
|
|
129
|
+
for (const footnoteGroup of footnoteGroups) {
|
|
130
|
+
section.appendChild(footnoteGroup);
|
|
131
|
+
}
|
|
132
|
+
return section;
|
|
133
|
+
},
|
|
134
|
+
createAppendixSection(app, createElement) {
|
|
135
|
+
const section = createElement('sec');
|
|
136
|
+
section.setAttribute('sec-type', 'appendices');
|
|
137
|
+
section.append(...app.children);
|
|
138
|
+
return section;
|
|
139
|
+
},
|
|
140
|
+
createFloatsGroupSection(floatsGroup, createElement) {
|
|
141
|
+
const section = createElement('sec');
|
|
142
|
+
section.setAttribute('sec-type', 'floating-element');
|
|
143
|
+
const title = createElement('title');
|
|
144
|
+
title.textContent = 'Floating Group';
|
|
145
|
+
section.appendChild(title);
|
|
146
|
+
section.append(...floatsGroup.children);
|
|
147
|
+
return section;
|
|
148
|
+
},
|
|
149
|
+
moveSectionsToBody(doc, body, references, createElement) {
|
|
150
|
+
const abstractNodes = doc.querySelectorAll('front > article-meta > abstract');
|
|
151
|
+
for (const abstractNode of abstractNodes) {
|
|
152
|
+
const abstract = this.createAbstract(abstractNode, createElement);
|
|
153
|
+
removeNodeFromParent(abstractNode);
|
|
154
|
+
body.insertBefore(abstract, body.firstChild);
|
|
155
|
+
}
|
|
156
|
+
for (const section of doc.querySelectorAll('back > sec')) {
|
|
157
|
+
removeNodeFromParent(section);
|
|
158
|
+
body.appendChild(section);
|
|
159
|
+
}
|
|
160
|
+
const ackNode = doc.querySelector('back > ack');
|
|
161
|
+
if (ackNode) {
|
|
162
|
+
const acknowledgements = this.createAcknowledgments(ackNode, createElement);
|
|
163
|
+
removeNodeFromParent(ackNode);
|
|
164
|
+
body.appendChild(acknowledgements);
|
|
165
|
+
}
|
|
166
|
+
const appGroup = doc.querySelectorAll('back > app-group > app');
|
|
167
|
+
for (const app of appGroup) {
|
|
168
|
+
const appendix = this.createAppendixSection(app, createElement);
|
|
169
|
+
removeNodeFromParent(app);
|
|
170
|
+
body.appendChild(appendix);
|
|
171
|
+
}
|
|
172
|
+
if (references) {
|
|
173
|
+
body.appendChild(this.createBibliography(doc, references, createElement));
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
mapFootnotesToSections(doc, body, createElement) {
|
|
177
|
+
const footnoteGroups = [...doc.querySelectorAll('fn[fn-type]')];
|
|
178
|
+
for (const footnote of footnoteGroups) {
|
|
179
|
+
const type = footnote.getAttribute('fn-type') || '';
|
|
180
|
+
const category = (0, transformer_1.chooseSectionCategoryByType)(type);
|
|
181
|
+
if (category) {
|
|
182
|
+
const section = createElement('sec');
|
|
183
|
+
const title = footnote.querySelector('p[content-type="fn-title"]');
|
|
184
|
+
if (title) {
|
|
185
|
+
const sectionTitleElement = createElement('title');
|
|
186
|
+
sectionTitleElement.textContent = title.textContent;
|
|
187
|
+
removeNodeFromParent(title);
|
|
188
|
+
section.append(sectionTitleElement);
|
|
189
|
+
}
|
|
190
|
+
section.append(...footnote.children);
|
|
191
|
+
removeNodeFromParent(footnote);
|
|
192
|
+
section.setAttribute('sec-type', (0, transformer_1.chooseSecType)(category));
|
|
193
|
+
body.append(section);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const footnotes = [...doc.querySelectorAll('fn')];
|
|
197
|
+
const footnotesSection = doc.querySelector('sec[sec-type="endnotes"]');
|
|
198
|
+
const footnotesSectionGroup = footnotesSection === null || footnotesSection === void 0 ? void 0 : footnotesSection.querySelector('fn-group');
|
|
199
|
+
const containingGroup = footnotesSectionGroup || createElement('fn-group');
|
|
200
|
+
for (const footnote of footnotes) {
|
|
201
|
+
const type = footnote.getAttribute('fn-type');
|
|
202
|
+
if (!type) {
|
|
203
|
+
containingGroup.appendChild(footnote);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (!footnotesSection && containingGroup.innerHTML) {
|
|
207
|
+
const section = this.createFootnotes([containingGroup], createElement);
|
|
208
|
+
body.append(section);
|
|
209
|
+
}
|
|
210
|
+
let regularFootnoteGroups = [
|
|
211
|
+
...doc.querySelectorAll('back > fn-group:not([fn-type])'),
|
|
212
|
+
];
|
|
213
|
+
regularFootnoteGroups = regularFootnoteGroups.filter((group) => {
|
|
214
|
+
return group.childElementCount === 0
|
|
215
|
+
? false
|
|
216
|
+
: !group.querySelector('fn[fn-type]');
|
|
217
|
+
});
|
|
218
|
+
if (regularFootnoteGroups.length > 0) {
|
|
219
|
+
regularFootnoteGroups.map((g) => removeNodeFromParent(g));
|
|
220
|
+
const footnotes = this.createFootnotes(regularFootnoteGroups, createElement);
|
|
221
|
+
body.appendChild(footnotes);
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
moveCaptionsToEnd(body) {
|
|
225
|
+
const captions = body.querySelectorAll('caption');
|
|
226
|
+
for (const caption of captions) {
|
|
227
|
+
if (caption.parentNode) {
|
|
228
|
+
caption.parentNode.appendChild(caption);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
moveTableFooterToEnd(body) {
|
|
233
|
+
const tableFooters = body.querySelectorAll('table-wrap-foot');
|
|
234
|
+
for (const tableFooter of tableFooters) {
|
|
235
|
+
if (tableFooter.parentNode) {
|
|
236
|
+
tableFooter.parentNode.appendChild(tableFooter);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
moveFloatsGroupToBody(doc, body, createElement) {
|
|
241
|
+
const floatsGroup = doc.querySelector('floats-group');
|
|
242
|
+
if (floatsGroup) {
|
|
243
|
+
const floatsGroupSection = this.createFloatsGroupSection(floatsGroup, createElement);
|
|
244
|
+
removeNodeFromParent(floatsGroup);
|
|
245
|
+
body.appendChild(floatsGroupSection);
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
moveBlockNodesFromParagraph(doc, body, createElement) {
|
|
249
|
+
const blockNodes = ['disp-formula'];
|
|
250
|
+
const paragraphs = [...body.querySelectorAll('sec > p')].filter((node) => blockNodes.find((node_name) => node.querySelector(`:scope > ${node_name}`)));
|
|
251
|
+
paragraphs.map((paragraph) => {
|
|
252
|
+
let newParagraph = createElement('p');
|
|
253
|
+
const parent = doc.createDocumentFragment();
|
|
254
|
+
while (paragraph === null || paragraph === void 0 ? void 0 : paragraph.firstChild) {
|
|
255
|
+
if (blockNodes.includes(paragraph === null || paragraph === void 0 ? void 0 : paragraph.firstChild.nodeName)) {
|
|
256
|
+
if (newParagraph.innerHTML.trim().length > 0) {
|
|
257
|
+
parent.append(newParagraph);
|
|
258
|
+
newParagraph = createElement('p');
|
|
259
|
+
}
|
|
260
|
+
parent.append(paragraph === null || paragraph === void 0 ? void 0 : paragraph.firstChild);
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
newParagraph.append(paragraph === null || paragraph === void 0 ? void 0 : paragraph.firstChild);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
paragraph === null || paragraph === void 0 ? void 0 : paragraph.replaceWith(parent);
|
|
267
|
+
});
|
|
268
|
+
},
|
|
269
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* © 2020 Atypon Systems LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.createReferenceComments = exports.createComments = exports.markProcessingInstructions = exports.parseProcessingInstruction = void 0;
|
|
19
|
+
const uuid_1 = require("uuid");
|
|
20
|
+
const transformer_1 = require("../../transformer");
|
|
21
|
+
const DEFAULT_ANNOTATION_COLOR = 'rgb(250, 224, 150)';
|
|
22
|
+
const DEFAULT_PROFILE_ID = 'MPUserProfile:0000000000000000000000000000000000000001';
|
|
23
|
+
const parseProcessingInstruction = (node) => {
|
|
24
|
+
const value = `<AuthorQuery ${node.textContent} />`;
|
|
25
|
+
const processingInstruction = new DOMParser().parseFromString(value, 'application/xml').firstElementChild;
|
|
26
|
+
if (processingInstruction) {
|
|
27
|
+
const queryText = processingInstruction.getAttribute('queryText');
|
|
28
|
+
const id = processingInstruction.getAttribute('id');
|
|
29
|
+
if (queryText && id) {
|
|
30
|
+
return { queryText, id };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
exports.parseProcessingInstruction = parseProcessingInstruction;
|
|
35
|
+
const markProcessingInstructions = (doc) => {
|
|
36
|
+
const authorQueriesMap = new Map();
|
|
37
|
+
const root = doc.getRootNode();
|
|
38
|
+
const queue = [root];
|
|
39
|
+
while (queue.length !== 0) {
|
|
40
|
+
const node = queue.shift();
|
|
41
|
+
if (node) {
|
|
42
|
+
const { nodeType, nodeName } = node;
|
|
43
|
+
if (nodeType === node.PROCESSING_INSTRUCTION_NODE &&
|
|
44
|
+
nodeName === 'AuthorQuery') {
|
|
45
|
+
insertToken(doc, node, authorQueriesMap);
|
|
46
|
+
}
|
|
47
|
+
node.childNodes.forEach((child) => {
|
|
48
|
+
queue.push(child);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return authorQueriesMap;
|
|
53
|
+
};
|
|
54
|
+
exports.markProcessingInstructions = markProcessingInstructions;
|
|
55
|
+
const insertToken = (doc, processingInstructionNode, authorQueriesMap) => {
|
|
56
|
+
const instruction = (0, exports.parseProcessingInstruction)(processingInstructionNode);
|
|
57
|
+
const { parentElement } = processingInstructionNode;
|
|
58
|
+
if (parentElement && instruction) {
|
|
59
|
+
const { queryText } = instruction;
|
|
60
|
+
const token = (0, uuid_1.v4)();
|
|
61
|
+
const tokenNode = doc.createTextNode(token);
|
|
62
|
+
authorQueriesMap.set(token, queryText);
|
|
63
|
+
return parentElement.insertBefore(tokenNode, processingInstructionNode);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const createComments = (authorQueriesMap, manuscriptModels) => {
|
|
67
|
+
const tokens = [...authorQueriesMap.keys()];
|
|
68
|
+
const commentAnnotations = [];
|
|
69
|
+
for (const model of manuscriptModels) {
|
|
70
|
+
if ((0, transformer_1.isHighlightableModel)(model)) {
|
|
71
|
+
const comments = addCommentsFromMarkedProcessingInstructions(tokens, model, authorQueriesMap);
|
|
72
|
+
commentAnnotations.push(...comments);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return commentAnnotations;
|
|
76
|
+
};
|
|
77
|
+
exports.createComments = createComments;
|
|
78
|
+
const addCommentsFromMarkedProcessingInstructions = (tokens, model, authorQueriesMap) => {
|
|
79
|
+
const commentAnnotations = [];
|
|
80
|
+
for (const field of ['contents', 'caption', 'title']) {
|
|
81
|
+
const highlightableField = field;
|
|
82
|
+
const content = model[highlightableField];
|
|
83
|
+
if (!content) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const sortedTokens = tokens
|
|
87
|
+
.filter((token) => content.indexOf(token) >= 0)
|
|
88
|
+
.sort((a, b) => content.indexOf(a) - content.indexOf(b));
|
|
89
|
+
let contentWithoutTokens = content;
|
|
90
|
+
for (const token of sortedTokens) {
|
|
91
|
+
const query = authorQueriesMap.get(token);
|
|
92
|
+
if (query) {
|
|
93
|
+
const trimmedTextContent = contentWithoutTokens
|
|
94
|
+
? contentWithoutTokens.replace(/^\s+/gm, '')
|
|
95
|
+
: undefined;
|
|
96
|
+
const startTokenIndex = trimmedTextContent
|
|
97
|
+
? trimmedTextContent.indexOf(token)
|
|
98
|
+
: undefined;
|
|
99
|
+
contentWithoutTokens = contentWithoutTokens.replace(token, '');
|
|
100
|
+
const comment = `${query}`;
|
|
101
|
+
const target = model._id && !(0, transformer_1.isCommentAnnotation)(model) ? model._id : (0, uuid_1.v4)();
|
|
102
|
+
const contributions = [(0, transformer_1.buildContribution)(DEFAULT_PROFILE_ID)];
|
|
103
|
+
const selector = startTokenIndex
|
|
104
|
+
? { from: startTokenIndex, to: startTokenIndex }
|
|
105
|
+
: undefined;
|
|
106
|
+
const commentAnnotation = (0, transformer_1.buildComment)(target, comment, selector, contributions, DEFAULT_ANNOTATION_COLOR);
|
|
107
|
+
commentAnnotations.push(commentAnnotation);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
model[highlightableField] = contentWithoutTokens;
|
|
111
|
+
}
|
|
112
|
+
return commentAnnotations;
|
|
113
|
+
};
|
|
114
|
+
const createReferenceComments = (referenceQueriesMap, references) => {
|
|
115
|
+
const comments = [];
|
|
116
|
+
for (const reference of references) {
|
|
117
|
+
const id = reference._id;
|
|
118
|
+
if (referenceQueriesMap.has(id)) {
|
|
119
|
+
for (const comment of referenceQueriesMap.get(id) || []) {
|
|
120
|
+
const target = reference._id && !(0, transformer_1.isCommentAnnotation)(reference)
|
|
121
|
+
? reference._id
|
|
122
|
+
: (0, uuid_1.v4)();
|
|
123
|
+
const contributions = [(0, transformer_1.buildContribution)(DEFAULT_PROFILE_ID)];
|
|
124
|
+
const commentAnnotation = (0, transformer_1.buildComment)(target, comment, undefined, contributions, DEFAULT_ANNOTATION_COLOR);
|
|
125
|
+
comments.push(commentAnnotation);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return comments;
|
|
130
|
+
};
|
|
131
|
+
exports.createReferenceComments = createReferenceComments;
|