@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,619 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* © 2019 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
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
18
|
+
var t = {};
|
|
19
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
20
|
+
t[p] = s[p];
|
|
21
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
22
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
23
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
24
|
+
t[p[i]] = s[p[i]];
|
|
25
|
+
}
|
|
26
|
+
return t;
|
|
27
|
+
};
|
|
28
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.Decoder = exports.isManuscriptNode = exports.sortSectionsByPriority = exports.getModelsByType = exports.getModelData = void 0;
|
|
33
|
+
const manuscripts_json_schema_1 = require("@manuscripts/manuscripts-json-schema");
|
|
34
|
+
const debug_1 = __importDefault(require("debug"));
|
|
35
|
+
const prosemirror_model_1 = require("prosemirror-model");
|
|
36
|
+
const errors_1 = require("../errors");
|
|
37
|
+
const schema_1 = require("../schema");
|
|
38
|
+
const highlight_markers_1 = require("./highlight-markers");
|
|
39
|
+
const id_1 = require("./id");
|
|
40
|
+
const object_types_1 = require("./object-types");
|
|
41
|
+
const section_category_1 = require("./section-category");
|
|
42
|
+
const timestamp_1 = require("./timestamp");
|
|
43
|
+
const warn = (0, debug_1.default)('manuscripts-transform');
|
|
44
|
+
const parser = prosemirror_model_1.DOMParser.fromSchema(schema_1.schema);
|
|
45
|
+
const getModelData = (model) => {
|
|
46
|
+
const { _rev, _deleted, updatedAt, createdAt, sessionID } = model, data = __rest(model, ["_rev", "_deleted", "updatedAt", "createdAt", "sessionID"]);
|
|
47
|
+
return data;
|
|
48
|
+
};
|
|
49
|
+
exports.getModelData = getModelData;
|
|
50
|
+
const getModelsByType = (modelMap, objectType) => {
|
|
51
|
+
const output = [];
|
|
52
|
+
for (const model of modelMap.values()) {
|
|
53
|
+
if (model.objectType === objectType) {
|
|
54
|
+
output.push(model);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return output;
|
|
58
|
+
};
|
|
59
|
+
exports.getModelsByType = getModelsByType;
|
|
60
|
+
const sortSectionsByPriority = (a, b) => a.priority === b.priority ? 0 : Number(a.priority) - Number(b.priority);
|
|
61
|
+
exports.sortSectionsByPriority = sortSectionsByPriority;
|
|
62
|
+
const getSections = (modelMap) => (0, exports.getModelsByType)(modelMap, manuscripts_json_schema_1.ObjectTypes.Section).sort(exports.sortSectionsByPriority);
|
|
63
|
+
const isManuscriptNode = (model) => model !== null;
|
|
64
|
+
exports.isManuscriptNode = isManuscriptNode;
|
|
65
|
+
const isParagraphElement = (0, object_types_1.hasObjectType)(manuscripts_json_schema_1.ObjectTypes.ParagraphElement);
|
|
66
|
+
const isFootnote = (0, object_types_1.hasObjectType)(manuscripts_json_schema_1.ObjectTypes.Footnote);
|
|
67
|
+
const hasParentSection = (id) => (section) => section.path &&
|
|
68
|
+
section.path.length > 1 &&
|
|
69
|
+
section.path[section.path.length - 2] === id;
|
|
70
|
+
class Decoder {
|
|
71
|
+
createCommentsNode(model) {
|
|
72
|
+
const comments = [];
|
|
73
|
+
for (const comment of this.getComments(model)) {
|
|
74
|
+
comments.push(this.decode(comment));
|
|
75
|
+
}
|
|
76
|
+
return comments;
|
|
77
|
+
}
|
|
78
|
+
getComments(model) {
|
|
79
|
+
return Array.from(this.modelMap.values()).filter((c) => (0, object_types_1.isCommentAnnotation)(c) && c.target === model._id);
|
|
80
|
+
}
|
|
81
|
+
extractListing(model) {
|
|
82
|
+
if (model.listingID) {
|
|
83
|
+
const listingModel = this.getModel(model.listingID);
|
|
84
|
+
let listing;
|
|
85
|
+
if (listingModel) {
|
|
86
|
+
listing = this.decode(listingModel);
|
|
87
|
+
}
|
|
88
|
+
else if (this.allowMissingElements) {
|
|
89
|
+
listing = schema_1.schema.nodes.placeholder.create({
|
|
90
|
+
id: model.listingID,
|
|
91
|
+
label: 'A listing',
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
throw new errors_1.MissingElement(model.listingID);
|
|
96
|
+
}
|
|
97
|
+
return listing;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
constructor(modelMap, allowMissingElements = false) {
|
|
101
|
+
this.creators = {
|
|
102
|
+
[manuscripts_json_schema_1.ObjectTypes.BibliographyElement]: (data) => {
|
|
103
|
+
var _a;
|
|
104
|
+
const model = data;
|
|
105
|
+
const referenceIDs = (_a = model.containedObjectIDs) === null || _a === void 0 ? void 0 : _a.filter((i) => i.startsWith('MPBibliographyItem'));
|
|
106
|
+
const references = [];
|
|
107
|
+
referenceIDs === null || referenceIDs === void 0 ? void 0 : referenceIDs.forEach((id) => {
|
|
108
|
+
const referenceModel = this.getModel(id);
|
|
109
|
+
if (referenceModel) {
|
|
110
|
+
return references.push(this.decode(referenceModel));
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
if (!references.length) {
|
|
114
|
+
references.push(schema_1.schema.nodes.placeholder.createAndFill());
|
|
115
|
+
}
|
|
116
|
+
return schema_1.schema.nodes.bibliography_element.createChecked({
|
|
117
|
+
id: model._id,
|
|
118
|
+
contents: '',
|
|
119
|
+
paragraphStyle: model.paragraphStyle,
|
|
120
|
+
}, references);
|
|
121
|
+
},
|
|
122
|
+
[manuscripts_json_schema_1.ObjectTypes.BibliographyItem]: (data) => {
|
|
123
|
+
const model = data;
|
|
124
|
+
return schema_1.schema.nodes.bibliography_item.create({
|
|
125
|
+
id: model._id,
|
|
126
|
+
type: model.type,
|
|
127
|
+
author: model.author,
|
|
128
|
+
issued: model.issued,
|
|
129
|
+
containerTitle: model['container-title'],
|
|
130
|
+
volume: model.volume,
|
|
131
|
+
issue: model.issue,
|
|
132
|
+
supplement: model.supplement,
|
|
133
|
+
doi: model.DOI,
|
|
134
|
+
page: model.page,
|
|
135
|
+
title: model.title,
|
|
136
|
+
literal: model.literal,
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
[object_types_1.ExtraObjectTypes.PlaceholderElement]: (data) => {
|
|
140
|
+
const model = data;
|
|
141
|
+
return schema_1.schema.nodes.placeholder_element.create({
|
|
142
|
+
id: model._id,
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
[manuscripts_json_schema_1.ObjectTypes.Figure]: (data) => {
|
|
146
|
+
const model = data;
|
|
147
|
+
return schema_1.schema.nodes.figure.create({
|
|
148
|
+
id: model._id,
|
|
149
|
+
contentType: model.contentType,
|
|
150
|
+
src: model.src,
|
|
151
|
+
position: model.position,
|
|
152
|
+
comments: this.createCommentsNode(model),
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
[manuscripts_json_schema_1.ObjectTypes.FigureElement]: (data) => {
|
|
156
|
+
const model = data;
|
|
157
|
+
const paragraphIDs = model.containedObjectIDs.filter((i) => i.startsWith('MPParagraphElement'));
|
|
158
|
+
const figureIDs = model.containedObjectIDs.filter((i) => i.startsWith('MPFigure') || i.startsWith('MPMissingFigure'));
|
|
159
|
+
const paragraphs = [];
|
|
160
|
+
paragraphIDs.forEach((id) => {
|
|
161
|
+
const paragraphModel = this.getModel(id);
|
|
162
|
+
if (paragraphModel) {
|
|
163
|
+
return paragraphs.push(this.decode(paragraphModel));
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
const figures = [];
|
|
167
|
+
figureIDs.forEach((id) => {
|
|
168
|
+
const figureModel = this.getModel(id);
|
|
169
|
+
if (!figureModel) {
|
|
170
|
+
return figures.push(schema_1.schema.nodes.placeholder.create({
|
|
171
|
+
id,
|
|
172
|
+
label: 'A figure',
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
return figures.push(this.decode(figureModel));
|
|
176
|
+
});
|
|
177
|
+
if (!figures.length) {
|
|
178
|
+
figures.push(schema_1.schema.nodes.figure.createAndFill());
|
|
179
|
+
}
|
|
180
|
+
const figcaption = this.getFigcaption(model);
|
|
181
|
+
const content = [...paragraphs, ...figures, figcaption];
|
|
182
|
+
const listing = this.extractListing(model);
|
|
183
|
+
if (listing) {
|
|
184
|
+
content.push(listing);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
const listing = schema_1.schema.nodes.listing.create();
|
|
188
|
+
content.push(listing);
|
|
189
|
+
}
|
|
190
|
+
return schema_1.schema.nodes.figure_element.createChecked({
|
|
191
|
+
id: model._id,
|
|
192
|
+
figureLayout: model.figureLayout,
|
|
193
|
+
label: model.label,
|
|
194
|
+
figureStyle: model.figureStyle,
|
|
195
|
+
alignment: model.alignment,
|
|
196
|
+
sizeFraction: model.sizeFraction,
|
|
197
|
+
suppressCaption: Boolean(model.suppressCaption),
|
|
198
|
+
suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
|
|
199
|
+
attribution: model.attribution,
|
|
200
|
+
alternatives: model.alternatives,
|
|
201
|
+
comments: this.createCommentsNode(model),
|
|
202
|
+
}, content);
|
|
203
|
+
},
|
|
204
|
+
[manuscripts_json_schema_1.ObjectTypes.Equation]: (data) => {
|
|
205
|
+
const model = data;
|
|
206
|
+
return schema_1.schema.nodes.equation.createChecked({
|
|
207
|
+
id: model._id,
|
|
208
|
+
MathMLStringRepresentation: model.MathMLStringRepresentation,
|
|
209
|
+
SVGStringRepresentation: model.SVGStringRepresentation,
|
|
210
|
+
TeXRepresentation: model.TeXRepresentation,
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
[manuscripts_json_schema_1.ObjectTypes.EquationElement]: (data) => {
|
|
214
|
+
const model = data;
|
|
215
|
+
const equationModel = this.getModel(model.containedObjectID);
|
|
216
|
+
let equation;
|
|
217
|
+
if (equationModel) {
|
|
218
|
+
equation = this.decode(equationModel);
|
|
219
|
+
}
|
|
220
|
+
else if (this.allowMissingElements) {
|
|
221
|
+
equation = schema_1.schema.nodes.placeholder.create({
|
|
222
|
+
id: model.containedObjectID,
|
|
223
|
+
label: 'An equation',
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
throw new errors_1.MissingElement(model.containedObjectID);
|
|
228
|
+
}
|
|
229
|
+
const figcaption = this.getFigcaption(model);
|
|
230
|
+
return schema_1.schema.nodes.equation_element.createChecked({
|
|
231
|
+
id: model._id,
|
|
232
|
+
suppressCaption: Boolean(model.suppressCaption),
|
|
233
|
+
suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
|
|
234
|
+
}, [equation, figcaption]);
|
|
235
|
+
},
|
|
236
|
+
[manuscripts_json_schema_1.ObjectTypes.FootnotesElement]: (data) => {
|
|
237
|
+
const model = data;
|
|
238
|
+
const collateByKind = model.collateByKind || 'footnote';
|
|
239
|
+
const footnotesOfKind = [];
|
|
240
|
+
for (const model of this.modelMap.values()) {
|
|
241
|
+
if (isFootnote(model) && model.kind === collateByKind) {
|
|
242
|
+
const footnote = this.parseContents(model.contents || '<div></div>', undefined, this.getComments(model), {
|
|
243
|
+
topNode: schema_1.schema.nodes.footnote.create({
|
|
244
|
+
id: model._id,
|
|
245
|
+
kind: model.kind,
|
|
246
|
+
comments: this.createCommentsNode(model),
|
|
247
|
+
}),
|
|
248
|
+
});
|
|
249
|
+
footnotesOfKind.push(footnote);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return schema_1.schema.nodes.footnotes_element.create({
|
|
253
|
+
id: model._id,
|
|
254
|
+
kind: model.collateByKind,
|
|
255
|
+
paragraphStyle: model.paragraphStyle,
|
|
256
|
+
}, footnotesOfKind);
|
|
257
|
+
},
|
|
258
|
+
[manuscripts_json_schema_1.ObjectTypes.Footnote]: (data) => {
|
|
259
|
+
const model = data;
|
|
260
|
+
return schema_1.schema.nodes.footnote.create({
|
|
261
|
+
id: model._id,
|
|
262
|
+
kind: model.kind,
|
|
263
|
+
comments: this.createCommentsNode(model),
|
|
264
|
+
});
|
|
265
|
+
},
|
|
266
|
+
[manuscripts_json_schema_1.ObjectTypes.KeywordsElement]: (data) => {
|
|
267
|
+
const model = data;
|
|
268
|
+
return schema_1.schema.nodes.keywords_element.create({
|
|
269
|
+
id: model._id,
|
|
270
|
+
contents: model.contents
|
|
271
|
+
? model.contents.replace(/\s+xmlns=".+?"/, '')
|
|
272
|
+
: '',
|
|
273
|
+
paragraphStyle: model.paragraphStyle,
|
|
274
|
+
});
|
|
275
|
+
},
|
|
276
|
+
[manuscripts_json_schema_1.ObjectTypes.ListElement]: (data) => {
|
|
277
|
+
const model = data;
|
|
278
|
+
switch (model.elementType) {
|
|
279
|
+
case 'ol':
|
|
280
|
+
return this.parseContents(model.contents || '<ol></ol>', undefined, this.getComments(model), {
|
|
281
|
+
topNode: schema_1.schema.nodes.ordered_list.create({
|
|
282
|
+
id: model._id,
|
|
283
|
+
paragraphStyle: model.paragraphStyle,
|
|
284
|
+
comments: this.createCommentsNode(model),
|
|
285
|
+
}),
|
|
286
|
+
});
|
|
287
|
+
case 'ul':
|
|
288
|
+
return this.parseContents(model.contents || '<ul></ul>', undefined, this.getComments(model), {
|
|
289
|
+
topNode: schema_1.schema.nodes.bullet_list.create({
|
|
290
|
+
id: model._id,
|
|
291
|
+
paragraphStyle: model.paragraphStyle,
|
|
292
|
+
}),
|
|
293
|
+
});
|
|
294
|
+
default:
|
|
295
|
+
throw new Error('Unknown list element type');
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
[manuscripts_json_schema_1.ObjectTypes.Listing]: (data) => {
|
|
299
|
+
const model = data;
|
|
300
|
+
return schema_1.schema.nodes.listing.createChecked({
|
|
301
|
+
id: model._id,
|
|
302
|
+
contents: model.contents,
|
|
303
|
+
language: model.language,
|
|
304
|
+
languageKey: model.languageKey,
|
|
305
|
+
comments: this.createCommentsNode(model),
|
|
306
|
+
});
|
|
307
|
+
},
|
|
308
|
+
[manuscripts_json_schema_1.ObjectTypes.ListingElement]: (data) => {
|
|
309
|
+
const model = data;
|
|
310
|
+
const listingModel = this.getModel(model.containedObjectID);
|
|
311
|
+
let listing;
|
|
312
|
+
if (listingModel) {
|
|
313
|
+
listing = this.decode(listingModel);
|
|
314
|
+
}
|
|
315
|
+
else if (this.allowMissingElements) {
|
|
316
|
+
listing = schema_1.schema.nodes.placeholder.create({
|
|
317
|
+
id: model.containedObjectID,
|
|
318
|
+
label: 'A listing',
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
throw new errors_1.MissingElement(model.containedObjectID);
|
|
323
|
+
}
|
|
324
|
+
const figcaption = this.getFigcaption(model);
|
|
325
|
+
return schema_1.schema.nodes.listing_element.createChecked({
|
|
326
|
+
id: model._id,
|
|
327
|
+
suppressCaption: model.suppressCaption,
|
|
328
|
+
suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
|
|
329
|
+
comments: this.createCommentsNode(model),
|
|
330
|
+
}, [listing, figcaption]);
|
|
331
|
+
},
|
|
332
|
+
[manuscripts_json_schema_1.ObjectTypes.MissingFigure]: (data) => {
|
|
333
|
+
const model = data;
|
|
334
|
+
return schema_1.schema.nodes.missing_figure.create({
|
|
335
|
+
id: model._id,
|
|
336
|
+
position: model.position,
|
|
337
|
+
});
|
|
338
|
+
},
|
|
339
|
+
[manuscripts_json_schema_1.ObjectTypes.ParagraphElement]: (data) => {
|
|
340
|
+
const model = data;
|
|
341
|
+
return this.parseContents(model.contents || '<p></p>', undefined, this.getComments(model), {
|
|
342
|
+
topNode: schema_1.schema.nodes.paragraph.create({
|
|
343
|
+
id: model._id,
|
|
344
|
+
paragraphStyle: model.paragraphStyle,
|
|
345
|
+
placeholder: model.placeholderInnerHTML,
|
|
346
|
+
comments: this.createCommentsNode(model),
|
|
347
|
+
}),
|
|
348
|
+
});
|
|
349
|
+
},
|
|
350
|
+
[manuscripts_json_schema_1.ObjectTypes.QuoteElement]: (data) => {
|
|
351
|
+
const model = data;
|
|
352
|
+
switch (model.quoteType) {
|
|
353
|
+
case 'block':
|
|
354
|
+
return this.parseContents(model.contents || '<p></p>', undefined, this.getComments(model), {
|
|
355
|
+
topNode: schema_1.schema.nodes.blockquote_element.create({
|
|
356
|
+
id: model._id,
|
|
357
|
+
paragraphStyle: model.paragraphStyle,
|
|
358
|
+
placeholder: model.placeholderInnerHTML,
|
|
359
|
+
}),
|
|
360
|
+
});
|
|
361
|
+
case 'pull':
|
|
362
|
+
return this.parseContents(model.contents || '<p></p>', undefined, this.getComments(model), {
|
|
363
|
+
topNode: schema_1.schema.nodes.pullquote_element.create({
|
|
364
|
+
id: model._id,
|
|
365
|
+
paragraphStyle: model.paragraphStyle,
|
|
366
|
+
placeholder: model.placeholderInnerHTML,
|
|
367
|
+
}),
|
|
368
|
+
});
|
|
369
|
+
default:
|
|
370
|
+
throw new Error('Unknown block type');
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
[manuscripts_json_schema_1.ObjectTypes.Section]: (data) => {
|
|
374
|
+
const model = data;
|
|
375
|
+
const isKeywordsSection = model.category === 'MPSectionCategory:keywords';
|
|
376
|
+
const elements = [];
|
|
377
|
+
if (model.elementIDs) {
|
|
378
|
+
for (const id of model.elementIDs) {
|
|
379
|
+
const element = this.getModel(id);
|
|
380
|
+
if (element) {
|
|
381
|
+
if (isKeywordsSection && isParagraphElement(element)) {
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
elements.push(element);
|
|
385
|
+
}
|
|
386
|
+
else if (this.allowMissingElements) {
|
|
387
|
+
const placeholderElement = {
|
|
388
|
+
_id: id,
|
|
389
|
+
containerID: model._id,
|
|
390
|
+
elementType: 'p',
|
|
391
|
+
objectType: object_types_1.ExtraObjectTypes.PlaceholderElement,
|
|
392
|
+
createdAt: (0, timestamp_1.timestamp)(),
|
|
393
|
+
updatedAt: (0, timestamp_1.timestamp)(),
|
|
394
|
+
};
|
|
395
|
+
elements.push(placeholderElement);
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
throw new errors_1.MissingElement(id);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
const elementNodes = elements
|
|
403
|
+
.map(this.decode)
|
|
404
|
+
.filter(exports.isManuscriptNode);
|
|
405
|
+
const sectionTitleNode = model.title
|
|
406
|
+
? this.parseContents(model.title, 'h1', this.getComments(model), {
|
|
407
|
+
topNode: schema_1.schema.nodes.section_title.create(),
|
|
408
|
+
})
|
|
409
|
+
: schema_1.schema.nodes.section_title.create();
|
|
410
|
+
let sectionLabelNode = undefined;
|
|
411
|
+
if (model.label) {
|
|
412
|
+
sectionLabelNode = this.parseContents(model.label, 'label', this.getComments(model), {
|
|
413
|
+
topNode: schema_1.schema.nodes.section_label.create(),
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
const nestedSections = getSections(this.modelMap)
|
|
417
|
+
.filter(hasParentSection(model._id))
|
|
418
|
+
.map(this.creators[manuscripts_json_schema_1.ObjectTypes.Section]);
|
|
419
|
+
const sectionCategory = model.category || (0, section_category_1.guessSectionCategory)(elements);
|
|
420
|
+
const sectionNodeType = (0, section_category_1.chooseSectionNodeType)(sectionCategory);
|
|
421
|
+
const content = (sectionLabelNode
|
|
422
|
+
? [sectionLabelNode, sectionTitleNode]
|
|
423
|
+
: [sectionTitleNode])
|
|
424
|
+
.concat(elementNodes)
|
|
425
|
+
.concat(nestedSections);
|
|
426
|
+
const sectionNode = sectionNodeType.createAndFill({
|
|
427
|
+
id: model._id,
|
|
428
|
+
category: sectionCategory,
|
|
429
|
+
titleSuppressed: model.titleSuppressed,
|
|
430
|
+
pageBreakStyle: model.pageBreakStyle,
|
|
431
|
+
generatedLabel: model.generatedLabel,
|
|
432
|
+
comments: this.createCommentsNode(model),
|
|
433
|
+
}, content);
|
|
434
|
+
if (!sectionNode) {
|
|
435
|
+
console.error(model);
|
|
436
|
+
throw new Error('Invalid content for section ' + model._id);
|
|
437
|
+
}
|
|
438
|
+
return sectionNode;
|
|
439
|
+
},
|
|
440
|
+
[manuscripts_json_schema_1.ObjectTypes.Table]: (data) => {
|
|
441
|
+
const model = data;
|
|
442
|
+
return this.parseContents(model.contents, undefined, this.getComments(model), {
|
|
443
|
+
topNode: schema_1.schema.nodes.table.create({
|
|
444
|
+
id: model._id,
|
|
445
|
+
comments: this.createCommentsNode(model),
|
|
446
|
+
}),
|
|
447
|
+
});
|
|
448
|
+
},
|
|
449
|
+
[manuscripts_json_schema_1.ObjectTypes.TableElement]: (data) => {
|
|
450
|
+
const model = data;
|
|
451
|
+
const tableModel = this.getModel(model.containedObjectID);
|
|
452
|
+
let table;
|
|
453
|
+
if (tableModel) {
|
|
454
|
+
table = this.decode(tableModel);
|
|
455
|
+
}
|
|
456
|
+
else if (this.allowMissingElements) {
|
|
457
|
+
table = schema_1.schema.nodes.placeholder.create({
|
|
458
|
+
id: model.containedObjectID,
|
|
459
|
+
label: 'A table',
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
throw new errors_1.MissingElement(model.containedObjectID);
|
|
464
|
+
}
|
|
465
|
+
const figcaption = this.getFigcaption(model);
|
|
466
|
+
const content = [table, figcaption];
|
|
467
|
+
if (model.listingID) {
|
|
468
|
+
const listingModel = this.getModel(model.listingID);
|
|
469
|
+
let listing;
|
|
470
|
+
if (listingModel) {
|
|
471
|
+
listing = this.decode(listingModel);
|
|
472
|
+
}
|
|
473
|
+
else if (this.allowMissingElements) {
|
|
474
|
+
listing = schema_1.schema.nodes.placeholder.create({
|
|
475
|
+
id: model.listingID,
|
|
476
|
+
label: 'A listing',
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
throw new errors_1.MissingElement(model.listingID);
|
|
481
|
+
}
|
|
482
|
+
content.push(listing);
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
const listing = schema_1.schema.nodes.listing.create();
|
|
486
|
+
content.push(listing);
|
|
487
|
+
}
|
|
488
|
+
return schema_1.schema.nodes.table_element.createChecked({
|
|
489
|
+
id: model._id,
|
|
490
|
+
table: model.containedObjectID,
|
|
491
|
+
suppressCaption: model.suppressCaption,
|
|
492
|
+
suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
|
|
493
|
+
suppressFooter: model.suppressFooter,
|
|
494
|
+
suppressHeader: model.suppressHeader,
|
|
495
|
+
tableStyle: model.tableStyle,
|
|
496
|
+
paragraphStyle: model.paragraphStyle,
|
|
497
|
+
comments: this.createCommentsNode(model),
|
|
498
|
+
}, content);
|
|
499
|
+
},
|
|
500
|
+
[manuscripts_json_schema_1.ObjectTypes.TOCElement]: (data) => {
|
|
501
|
+
const model = data;
|
|
502
|
+
return schema_1.schema.nodes.toc_element.create({
|
|
503
|
+
id: model._id,
|
|
504
|
+
contents: model.contents
|
|
505
|
+
? model.contents.replace(/\s+xmlns=".+?"/, '')
|
|
506
|
+
: '',
|
|
507
|
+
paragraphStyle: model.paragraphStyle,
|
|
508
|
+
});
|
|
509
|
+
},
|
|
510
|
+
[manuscripts_json_schema_1.ObjectTypes.CommentAnnotation]: (data) => {
|
|
511
|
+
const model = data;
|
|
512
|
+
return schema_1.schema.nodes.comment.create({
|
|
513
|
+
id: model._id,
|
|
514
|
+
contents: model.contents,
|
|
515
|
+
selector: model.selector,
|
|
516
|
+
target: model.target,
|
|
517
|
+
});
|
|
518
|
+
},
|
|
519
|
+
};
|
|
520
|
+
this.decode = (model) => {
|
|
521
|
+
if (!this.creators[model.objectType]) {
|
|
522
|
+
warn(`No converter for ${model.objectType}`);
|
|
523
|
+
return null;
|
|
524
|
+
}
|
|
525
|
+
return this.creators[model.objectType](model);
|
|
526
|
+
};
|
|
527
|
+
this.getModel = (id) => this.modelMap.get(id);
|
|
528
|
+
this.createArticleNode = (manuscriptID) => {
|
|
529
|
+
let rootSections = getSections(this.modelMap).filter((section) => !section.path || section.path.length <= 1);
|
|
530
|
+
rootSections = this.addGeneratedLabels(rootSections);
|
|
531
|
+
const rootSectionNodes = rootSections
|
|
532
|
+
.map(this.decode)
|
|
533
|
+
.filter(exports.isManuscriptNode);
|
|
534
|
+
if (!rootSectionNodes.length) {
|
|
535
|
+
rootSectionNodes.push(schema_1.schema.nodes.section.createAndFill({
|
|
536
|
+
id: (0, id_1.generateNodeID)(schema_1.schema.nodes.section),
|
|
537
|
+
}));
|
|
538
|
+
}
|
|
539
|
+
return schema_1.schema.nodes.manuscript.create({
|
|
540
|
+
id: manuscriptID || this.getManuscriptID(),
|
|
541
|
+
}, rootSectionNodes);
|
|
542
|
+
};
|
|
543
|
+
this.addGeneratedLabels = (sections) => {
|
|
544
|
+
const nextLableCount = { Appendix: 1 };
|
|
545
|
+
return sections.map((section) => {
|
|
546
|
+
if (section.generatedLabel) {
|
|
547
|
+
const secType = section.category
|
|
548
|
+
? (0, section_category_1.chooseSecType)(section.category)
|
|
549
|
+
: undefined;
|
|
550
|
+
if (secType === 'appendices') {
|
|
551
|
+
section.label = `${(0, section_category_1.chooseSectionLableName)(secType)} ${nextLableCount['Appendix']}`;
|
|
552
|
+
nextLableCount['Appendix'] += 1;
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
delete section.label;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
return section;
|
|
559
|
+
});
|
|
560
|
+
};
|
|
561
|
+
this.parseContents = (contents, wrapper, commentAnnotations = [], options) => {
|
|
562
|
+
const contentsWithComments = commentAnnotations.length
|
|
563
|
+
? (0, highlight_markers_1.insertHighlightMarkers)(contents, commentAnnotations)
|
|
564
|
+
: contents;
|
|
565
|
+
const wrappedContents = wrapper
|
|
566
|
+
? `<${wrapper}>${contentsWithComments}</${wrapper}>`
|
|
567
|
+
: contentsWithComments;
|
|
568
|
+
const html = wrappedContents.trim();
|
|
569
|
+
if (!html.length) {
|
|
570
|
+
throw new Error('No HTML to parse');
|
|
571
|
+
}
|
|
572
|
+
const template = document.createElement('template');
|
|
573
|
+
template.innerHTML = html;
|
|
574
|
+
if (!template.content.firstChild) {
|
|
575
|
+
throw new Error('No content could be parsed');
|
|
576
|
+
}
|
|
577
|
+
return parser.parse(template.content.firstChild, options);
|
|
578
|
+
};
|
|
579
|
+
this.getManuscriptID = () => {
|
|
580
|
+
for (const item of this.modelMap.values()) {
|
|
581
|
+
if ((0, object_types_1.isManuscript)(item)) {
|
|
582
|
+
return item._id;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
this.getFigcaption = (model) => {
|
|
587
|
+
const titleNode = schema_1.schema.nodes.caption_title.create();
|
|
588
|
+
const captionTitle = model.title
|
|
589
|
+
? this.parseContents(model.title, 'caption_title', this.getComments(model), {
|
|
590
|
+
topNode: titleNode,
|
|
591
|
+
})
|
|
592
|
+
: titleNode;
|
|
593
|
+
if (model.caption && /<\/?[a-z][\s\S]*>/i.test(model.caption)) {
|
|
594
|
+
const captionDoc = document.createElement('div');
|
|
595
|
+
captionDoc.innerHTML = model.caption;
|
|
596
|
+
const content = [captionTitle];
|
|
597
|
+
const paragraphs = captionDoc.querySelectorAll('p');
|
|
598
|
+
for (const paragraph of paragraphs) {
|
|
599
|
+
const captionNode = schema_1.schema.nodes.caption.create();
|
|
600
|
+
const caption = this.parseContents(paragraph.outerHTML, 'caption', this.getComments(model), {
|
|
601
|
+
topNode: captionNode,
|
|
602
|
+
});
|
|
603
|
+
content.push(caption);
|
|
604
|
+
}
|
|
605
|
+
return schema_1.schema.nodes.figcaption.create({}, content);
|
|
606
|
+
}
|
|
607
|
+
const captionNode = schema_1.schema.nodes.caption.create();
|
|
608
|
+
const caption = model.caption
|
|
609
|
+
? this.parseContents(model.caption, 'caption', this.getComments(model), {
|
|
610
|
+
topNode: captionNode,
|
|
611
|
+
})
|
|
612
|
+
: captionNode;
|
|
613
|
+
return schema_1.schema.nodes.figcaption.create({}, [captionTitle, caption]);
|
|
614
|
+
};
|
|
615
|
+
this.modelMap = modelMap;
|
|
616
|
+
this.allowMissingElements = allowMissingElements;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
exports.Decoder = Decoder;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* © 2019 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.documentObjectTypes = void 0;
|
|
19
|
+
const manuscripts_json_schema_1 = require("@manuscripts/manuscripts-json-schema");
|
|
20
|
+
exports.documentObjectTypes = [
|
|
21
|
+
manuscripts_json_schema_1.ObjectTypes.BibliographyElement,
|
|
22
|
+
manuscripts_json_schema_1.ObjectTypes.EquationElement,
|
|
23
|
+
manuscripts_json_schema_1.ObjectTypes.FigureElement,
|
|
24
|
+
manuscripts_json_schema_1.ObjectTypes.ListElement,
|
|
25
|
+
manuscripts_json_schema_1.ObjectTypes.ListingElement,
|
|
26
|
+
manuscripts_json_schema_1.ObjectTypes.Manuscript,
|
|
27
|
+
manuscripts_json_schema_1.ObjectTypes.ParagraphElement,
|
|
28
|
+
manuscripts_json_schema_1.ObjectTypes.Section,
|
|
29
|
+
manuscripts_json_schema_1.ObjectTypes.TableElement,
|
|
30
|
+
manuscripts_json_schema_1.ObjectTypes.TOCElement,
|
|
31
|
+
];
|