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