@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,545 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.encode = exports.modelFromNode = exports.inlineText = exports.inlineContents = void 0;
|
|
22
|
+
const prosemirror_model_1 = require("prosemirror-model");
|
|
23
|
+
const w3c_xmlserializer_1 = __importDefault(require("w3c-xmlserializer"));
|
|
24
|
+
const utils_1 = require("../lib/utils");
|
|
25
|
+
const schema_1 = require("../schema");
|
|
26
|
+
const builders_1 = require("./builders");
|
|
27
|
+
const highlight_markers_1 = require("./highlight-markers");
|
|
28
|
+
const node_types_1 = require("./node-types");
|
|
29
|
+
const section_category_1 = require("./section-category");
|
|
30
|
+
const serializer = prosemirror_model_1.DOMSerializer.fromSchema(schema_1.schema);
|
|
31
|
+
const contents = (node) => {
|
|
32
|
+
const output = serializer.serializeNode(node);
|
|
33
|
+
return (0, w3c_xmlserializer_1.default)(output);
|
|
34
|
+
};
|
|
35
|
+
const footnoteContents = (node) => {
|
|
36
|
+
const output = serializer.serializeNode(node);
|
|
37
|
+
output.querySelectorAll('p').forEach((element) => {
|
|
38
|
+
element.removeAttribute('class');
|
|
39
|
+
element.removeAttribute('data-object-type');
|
|
40
|
+
});
|
|
41
|
+
return (0, w3c_xmlserializer_1.default)(output);
|
|
42
|
+
};
|
|
43
|
+
const inlineContents = (node) => serializer.serializeNode(node).innerHTML;
|
|
44
|
+
exports.inlineContents = inlineContents;
|
|
45
|
+
const inlineText = (node) => {
|
|
46
|
+
const text = serializer.serializeNode(node).textContent;
|
|
47
|
+
return text === null ? '' : text;
|
|
48
|
+
};
|
|
49
|
+
exports.inlineText = inlineText;
|
|
50
|
+
const listContents = (node) => {
|
|
51
|
+
const output = serializer.serializeNode(node);
|
|
52
|
+
for (const p of output.querySelectorAll('li > p')) {
|
|
53
|
+
const parent = p.parentNode;
|
|
54
|
+
while (p.firstChild) {
|
|
55
|
+
parent.insertBefore(p.firstChild, p);
|
|
56
|
+
}
|
|
57
|
+
parent.removeChild(p);
|
|
58
|
+
}
|
|
59
|
+
return (0, w3c_xmlserializer_1.default)(output);
|
|
60
|
+
};
|
|
61
|
+
const svgDefs = (svg) => {
|
|
62
|
+
const template = document.createElement('template');
|
|
63
|
+
template.innerHTML = svg.trim();
|
|
64
|
+
const defs = template.content.querySelector('defs');
|
|
65
|
+
return defs ? (0, w3c_xmlserializer_1.default)(defs) : undefined;
|
|
66
|
+
};
|
|
67
|
+
const tableRowDisplayStyle = (tagName, parent) => {
|
|
68
|
+
switch (tagName) {
|
|
69
|
+
case 'thead':
|
|
70
|
+
return parent.attrs.suppressHeader ? 'none' : 'table-header-group';
|
|
71
|
+
case 'tfoot':
|
|
72
|
+
return parent.attrs.suppressFooter ? 'none' : 'table-footer-group';
|
|
73
|
+
default:
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const buildTableSection = (tagName, inputRows, parent) => {
|
|
78
|
+
const section = document.createElement(tagName);
|
|
79
|
+
for (const sectionRow of inputRows) {
|
|
80
|
+
const row = section.appendChild(document.createElement('tr'));
|
|
81
|
+
for (const child of sectionRow.children) {
|
|
82
|
+
const cellType = tagName === 'thead' ? 'th' : 'td';
|
|
83
|
+
const cell = row.appendChild(document.createElement(cellType));
|
|
84
|
+
while (child.firstChild) {
|
|
85
|
+
cell.appendChild(child.firstChild);
|
|
86
|
+
}
|
|
87
|
+
for (const attribute of child.attributes) {
|
|
88
|
+
cell.setAttribute(attribute.name, attribute.value);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const displayStyle = tableRowDisplayStyle(tagName, parent);
|
|
93
|
+
if (displayStyle) {
|
|
94
|
+
section.style.display = displayStyle;
|
|
95
|
+
}
|
|
96
|
+
return section;
|
|
97
|
+
};
|
|
98
|
+
function buildTableColGroup(cols) {
|
|
99
|
+
if (cols.length === 0) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
const colgroup = document.createElement('colgroup');
|
|
103
|
+
for (const inputCol of cols) {
|
|
104
|
+
const col = document.createElement('col');
|
|
105
|
+
for (const attribute of inputCol.attributes) {
|
|
106
|
+
col.setAttribute(attribute.name, attribute.value);
|
|
107
|
+
}
|
|
108
|
+
colgroup.appendChild(inputCol);
|
|
109
|
+
}
|
|
110
|
+
return colgroup;
|
|
111
|
+
}
|
|
112
|
+
const tableContents = (node, parent) => {
|
|
113
|
+
const input = serializer.serializeNode(node);
|
|
114
|
+
const output = document.createElement('table');
|
|
115
|
+
const colgroup = buildTableColGroup(Array.from(input.querySelectorAll('col')));
|
|
116
|
+
if (colgroup) {
|
|
117
|
+
output.appendChild(colgroup);
|
|
118
|
+
}
|
|
119
|
+
output.setAttribute('id', parent.attrs.id);
|
|
120
|
+
output.classList.add('MPElement');
|
|
121
|
+
if (parent.attrs.tableStyle) {
|
|
122
|
+
output.classList.add(parent.attrs.tableStyle.replace(/:/g, '_'));
|
|
123
|
+
}
|
|
124
|
+
if (parent.attrs.paragraphStyle) {
|
|
125
|
+
output.classList.add(parent.attrs.paragraphStyle.replace(/:/g, '_'));
|
|
126
|
+
}
|
|
127
|
+
output.setAttribute('data-contained-object-id', node.attrs.id);
|
|
128
|
+
const rows = Array.from(input.querySelectorAll('tr'));
|
|
129
|
+
let headerCount = 0;
|
|
130
|
+
for (const row of rows) {
|
|
131
|
+
const th = row.querySelector('th[scope="col"], th[scope="colgroup"]');
|
|
132
|
+
th && headerCount++;
|
|
133
|
+
}
|
|
134
|
+
const thead = rows.splice(0, headerCount || 1);
|
|
135
|
+
const tfoot = rows.splice(-1, 1);
|
|
136
|
+
output.appendChild(buildTableSection('thead', thead, parent));
|
|
137
|
+
output.appendChild(buildTableSection('tbody', rows, parent));
|
|
138
|
+
output.appendChild(buildTableSection('tfoot', tfoot, parent));
|
|
139
|
+
return (0, w3c_xmlserializer_1.default)(output);
|
|
140
|
+
};
|
|
141
|
+
const elementContents = (node) => {
|
|
142
|
+
const input = serializer.serializeNode(node);
|
|
143
|
+
input.classList.add('MPElement');
|
|
144
|
+
if (node.attrs.paragraphStyle) {
|
|
145
|
+
input.classList.add(node.attrs.paragraphStyle.replace(/:/g, '_'));
|
|
146
|
+
}
|
|
147
|
+
if (node.attrs.id) {
|
|
148
|
+
input.setAttribute('id', node.attrs.id);
|
|
149
|
+
}
|
|
150
|
+
return (0, w3c_xmlserializer_1.default)(input);
|
|
151
|
+
};
|
|
152
|
+
const childElements = (node) => {
|
|
153
|
+
const nodes = [];
|
|
154
|
+
node.forEach((childNode) => {
|
|
155
|
+
if (!(0, schema_1.isSectionNode)(childNode)) {
|
|
156
|
+
nodes.push(childNode);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
return nodes;
|
|
160
|
+
};
|
|
161
|
+
const attributeOfNodeType = (node, type, attribute) => {
|
|
162
|
+
for (const child of (0, utils_1.iterateChildren)(node)) {
|
|
163
|
+
if (child.type.name === type) {
|
|
164
|
+
return child.attrs[attribute];
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return '';
|
|
168
|
+
};
|
|
169
|
+
const inlineContentsOfNodeType = (node, nodeType) => {
|
|
170
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
171
|
+
const child = node.child(i);
|
|
172
|
+
if (child.type === nodeType) {
|
|
173
|
+
return (0, exports.inlineContents)(child);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return '';
|
|
177
|
+
};
|
|
178
|
+
const inlineContentOfChildNodeType = (node, parentNodeType, childNodeType, empty = true) => {
|
|
179
|
+
const parentNode = childElements(node).find((node) => node.type === parentNodeType && node);
|
|
180
|
+
const content = parentNode && inlineContentsOfNodeType(parentNode, childNodeType);
|
|
181
|
+
return content && content.length > 1 ? content : empty ? content : undefined;
|
|
182
|
+
};
|
|
183
|
+
const wrappedContentOfChildrenNodeType = (node, parentNodeType, childNodeType) => {
|
|
184
|
+
const parentNode = childElements(node).find((node) => node.type === parentNodeType && node);
|
|
185
|
+
const content = parentNode &&
|
|
186
|
+
childElements(parentNode)
|
|
187
|
+
.filter((node) => node.type === childNodeType && node)
|
|
188
|
+
.map((node) => serializer.serializeNode(node).outerHTML)
|
|
189
|
+
.join('');
|
|
190
|
+
return content;
|
|
191
|
+
};
|
|
192
|
+
const containedFigureIDs = (node) => {
|
|
193
|
+
const figureNodeType = node.type.schema.nodes.figure;
|
|
194
|
+
const missingFigureNodeType = node.type.schema.nodes.missing_figure;
|
|
195
|
+
return containedObjectIDs(node, [figureNodeType, missingFigureNodeType]);
|
|
196
|
+
};
|
|
197
|
+
const containedParagraphIDs = (node) => {
|
|
198
|
+
const paragraphNodeType = node.type.schema.nodes.paragraph;
|
|
199
|
+
return containedObjectIDs(node, [paragraphNodeType]);
|
|
200
|
+
};
|
|
201
|
+
const containedBibliographyItemIDs = (node) => {
|
|
202
|
+
const bibliographyItemNodeType = node.type.schema.nodes.bibliography_item;
|
|
203
|
+
return containedObjectIDs(node, [bibliographyItemNodeType]);
|
|
204
|
+
};
|
|
205
|
+
const containedObjectIDs = (node, nodeTypes) => {
|
|
206
|
+
const ids = [];
|
|
207
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
208
|
+
const childNode = node.child(i);
|
|
209
|
+
if (nodeTypes.includes(childNode.type)) {
|
|
210
|
+
ids.push(childNode.attrs.id);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return ids;
|
|
214
|
+
};
|
|
215
|
+
const attribution = (node) => {
|
|
216
|
+
if (node.attrs.attribution) {
|
|
217
|
+
return Object.assign(Object.assign({}, node.attrs.attribution), (0, builders_1.buildAttribution)());
|
|
218
|
+
}
|
|
219
|
+
return undefined;
|
|
220
|
+
};
|
|
221
|
+
const fromJson = (json) => {
|
|
222
|
+
let obj;
|
|
223
|
+
try {
|
|
224
|
+
obj = JSON.parse(json);
|
|
225
|
+
}
|
|
226
|
+
catch (e) {
|
|
227
|
+
}
|
|
228
|
+
return obj;
|
|
229
|
+
};
|
|
230
|
+
function figureElementEncoder(node) {
|
|
231
|
+
var _a;
|
|
232
|
+
return {
|
|
233
|
+
containedObjectIDs: (_a = containedParagraphIDs(node)) === null || _a === void 0 ? void 0 : _a.concat(containedFigureIDs(node)),
|
|
234
|
+
caption: wrappedContentOfChildrenNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
|
|
235
|
+
title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
|
|
236
|
+
label: node.attrs.label,
|
|
237
|
+
elementType: 'figure',
|
|
238
|
+
attribution: attribution(node),
|
|
239
|
+
alternatives: node.attrs.alternatives,
|
|
240
|
+
listingID: attributeOfNodeType(node, 'listing', 'id') || undefined,
|
|
241
|
+
alignment: node.attrs.alignment || undefined,
|
|
242
|
+
sizeFraction: node.attrs.sizeFraction || undefined,
|
|
243
|
+
suppressCaption: Boolean(node.attrs.suppressCaption) || undefined,
|
|
244
|
+
suppressTitle: node.attrs.suppressTitle === undefined ||
|
|
245
|
+
node.attrs.suppressTitle === true
|
|
246
|
+
? undefined
|
|
247
|
+
: false,
|
|
248
|
+
figureStyle: node.attrs.figureStyle || undefined,
|
|
249
|
+
figureLayout: node.attrs.figureLayout || undefined,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
const encoders = {
|
|
253
|
+
bibliography_element: (node) => ({
|
|
254
|
+
elementType: 'div',
|
|
255
|
+
contents: '',
|
|
256
|
+
containedObjectIDs: containedBibliographyItemIDs(node),
|
|
257
|
+
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
258
|
+
}),
|
|
259
|
+
bibliography_item: (node) => {
|
|
260
|
+
const { type, containerTitle, doi, volume, issue, supplement, page, title, literal, } = node.attrs;
|
|
261
|
+
const author = fromJson(node.attrs.author);
|
|
262
|
+
const issued = fromJson(node.attrs.issued);
|
|
263
|
+
const ref = {
|
|
264
|
+
type,
|
|
265
|
+
};
|
|
266
|
+
if (author) {
|
|
267
|
+
ref.author = author;
|
|
268
|
+
}
|
|
269
|
+
if (issued) {
|
|
270
|
+
ref.issued = issued;
|
|
271
|
+
}
|
|
272
|
+
if (containerTitle) {
|
|
273
|
+
ref['container-title'] = containerTitle;
|
|
274
|
+
}
|
|
275
|
+
if (doi) {
|
|
276
|
+
ref.DOI = doi;
|
|
277
|
+
}
|
|
278
|
+
if (volume) {
|
|
279
|
+
ref.volume = volume;
|
|
280
|
+
}
|
|
281
|
+
if (issue) {
|
|
282
|
+
ref.issue = issue;
|
|
283
|
+
}
|
|
284
|
+
if (supplement) {
|
|
285
|
+
ref.supplement = supplement;
|
|
286
|
+
}
|
|
287
|
+
if (page) {
|
|
288
|
+
ref.page = page;
|
|
289
|
+
}
|
|
290
|
+
if (title) {
|
|
291
|
+
ref.title = title;
|
|
292
|
+
}
|
|
293
|
+
if (literal) {
|
|
294
|
+
ref.literal = literal;
|
|
295
|
+
}
|
|
296
|
+
return ref;
|
|
297
|
+
},
|
|
298
|
+
bibliography_section: (node, parent, path, priority) => ({
|
|
299
|
+
category: (0, section_category_1.buildSectionCategory)(node),
|
|
300
|
+
priority: priority.value++,
|
|
301
|
+
title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
|
|
302
|
+
path: path.concat([node.attrs.id]),
|
|
303
|
+
elementIDs: childElements(node)
|
|
304
|
+
.map((childNode) => childNode.attrs.id)
|
|
305
|
+
.filter((id) => id),
|
|
306
|
+
}),
|
|
307
|
+
blockquote_element: (node) => ({
|
|
308
|
+
contents: contents(node),
|
|
309
|
+
elementType: 'div',
|
|
310
|
+
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
311
|
+
placeholderInnerHTML: node.attrs.placeholder || '',
|
|
312
|
+
quoteType: 'block',
|
|
313
|
+
}),
|
|
314
|
+
bullet_list: (node) => ({
|
|
315
|
+
elementType: 'ul',
|
|
316
|
+
contents: listContents(node),
|
|
317
|
+
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
318
|
+
}),
|
|
319
|
+
listing: (node) => ({
|
|
320
|
+
contents: (0, exports.inlineText)(node),
|
|
321
|
+
language: node.attrs.language || undefined,
|
|
322
|
+
languageKey: node.attrs.languageKey || 'null',
|
|
323
|
+
}),
|
|
324
|
+
listing_element: (node) => ({
|
|
325
|
+
containedObjectID: attributeOfNodeType(node, 'listing', 'id'),
|
|
326
|
+
caption: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
|
|
327
|
+
title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
|
|
328
|
+
elementType: 'figure',
|
|
329
|
+
suppressCaption: node.attrs.suppressCaption === true ? undefined : false,
|
|
330
|
+
suppressTitle: node.attrs.suppressTitle === undefined ||
|
|
331
|
+
node.attrs.suppressTitle === true
|
|
332
|
+
? undefined
|
|
333
|
+
: false,
|
|
334
|
+
}),
|
|
335
|
+
equation: (node) => ({
|
|
336
|
+
MathMLStringRepresentation: node.attrs.MathMLStringRepresentation || undefined,
|
|
337
|
+
TeXRepresentation: node.attrs.TeXRepresentation,
|
|
338
|
+
SVGStringRepresentation: node.attrs.SVGStringRepresentation,
|
|
339
|
+
}),
|
|
340
|
+
equation_element: (node) => ({
|
|
341
|
+
containedObjectID: attributeOfNodeType(node, 'equation', 'id'),
|
|
342
|
+
caption: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
|
|
343
|
+
title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
|
|
344
|
+
elementType: 'p',
|
|
345
|
+
suppressCaption: Boolean(node.attrs.suppressCaption) || undefined,
|
|
346
|
+
suppressTitle: node.attrs.suppressTitle === undefined ||
|
|
347
|
+
node.attrs.suppressTitle === true
|
|
348
|
+
? undefined
|
|
349
|
+
: false,
|
|
350
|
+
}),
|
|
351
|
+
figure: (node) => ({
|
|
352
|
+
contentType: node.attrs.contentType || undefined,
|
|
353
|
+
src: node.attrs.src || undefined,
|
|
354
|
+
position: node.attrs.position || undefined,
|
|
355
|
+
}),
|
|
356
|
+
figure_element: (node) => figureElementEncoder(node),
|
|
357
|
+
comment: (node) => ({
|
|
358
|
+
selector: node.attrs.selector,
|
|
359
|
+
target: node.attrs.target,
|
|
360
|
+
contents: node.attrs.contents,
|
|
361
|
+
}),
|
|
362
|
+
footnote: (node, parent) => ({
|
|
363
|
+
containingObject: parent.attrs.id,
|
|
364
|
+
contents: footnoteContents(node),
|
|
365
|
+
kind: node.attrs.kind || 'footnote',
|
|
366
|
+
}),
|
|
367
|
+
footnotes_element: (node) => ({
|
|
368
|
+
contents: '<div></div>',
|
|
369
|
+
elementType: 'div',
|
|
370
|
+
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
371
|
+
}),
|
|
372
|
+
footnotes_section: (node, parent, path, priority) => ({
|
|
373
|
+
category: (0, section_category_1.buildSectionCategory)(node),
|
|
374
|
+
priority: priority.value++,
|
|
375
|
+
title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
|
|
376
|
+
path: path.concat([node.attrs.id]),
|
|
377
|
+
elementIDs: childElements(node)
|
|
378
|
+
.map((childNode) => childNode.attrs.id)
|
|
379
|
+
.filter((id) => id),
|
|
380
|
+
}),
|
|
381
|
+
graphical_abstract_section: (node, parent, path, priority) => ({
|
|
382
|
+
category: (0, section_category_1.buildSectionCategory)(node),
|
|
383
|
+
priority: priority.value++,
|
|
384
|
+
title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
|
|
385
|
+
path: path.concat([node.attrs.id]),
|
|
386
|
+
elementIDs: childElements(node)
|
|
387
|
+
.map((childNode) => childNode.attrs.id)
|
|
388
|
+
.filter((id) => id),
|
|
389
|
+
}),
|
|
390
|
+
inline_equation: (node, parent) => ({
|
|
391
|
+
containingObject: parent.attrs.id,
|
|
392
|
+
TeXRepresentation: node.attrs.TeXRepresentation,
|
|
393
|
+
SVGRepresentation: node.attrs.SVGRepresentation,
|
|
394
|
+
SVGGlyphs: svgDefs(node.attrs.SVGRepresentation),
|
|
395
|
+
}),
|
|
396
|
+
keywords_element: (node) => ({
|
|
397
|
+
contents: elementContents(node),
|
|
398
|
+
elementType: 'div',
|
|
399
|
+
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
400
|
+
}),
|
|
401
|
+
keywords_section: (node, parent, path, priority) => ({
|
|
402
|
+
category: (0, section_category_1.buildSectionCategory)(node),
|
|
403
|
+
priority: priority.value++,
|
|
404
|
+
title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
|
|
405
|
+
path: path.concat([node.attrs.id]),
|
|
406
|
+
elementIDs: childElements(node)
|
|
407
|
+
.map((childNode) => childNode.attrs.id)
|
|
408
|
+
.filter((id) => id),
|
|
409
|
+
}),
|
|
410
|
+
missing_figure: (node) => ({
|
|
411
|
+
position: node.attrs.position || undefined,
|
|
412
|
+
}),
|
|
413
|
+
ordered_list: (node) => ({
|
|
414
|
+
elementType: 'ol',
|
|
415
|
+
contents: listContents(node),
|
|
416
|
+
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
417
|
+
}),
|
|
418
|
+
paragraph: (node) => ({
|
|
419
|
+
elementType: 'p',
|
|
420
|
+
contents: contents(node),
|
|
421
|
+
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
422
|
+
placeholderInnerHTML: node.attrs.placeholder || '',
|
|
423
|
+
}),
|
|
424
|
+
placeholder_element: () => ({
|
|
425
|
+
elementType: 'p',
|
|
426
|
+
}),
|
|
427
|
+
pullquote_element: (node) => ({
|
|
428
|
+
contents: contents(node),
|
|
429
|
+
elementType: 'div',
|
|
430
|
+
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
431
|
+
placeholderInnerHTML: node.attrs.placeholder || '',
|
|
432
|
+
quoteType: 'pull',
|
|
433
|
+
}),
|
|
434
|
+
section: (node, parent, path, priority) => ({
|
|
435
|
+
category: (0, section_category_1.buildSectionCategory)(node),
|
|
436
|
+
priority: priority.value++,
|
|
437
|
+
title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
|
|
438
|
+
label: inlineContentsOfNodeType(node, node.type.schema.nodes.section_label) ||
|
|
439
|
+
undefined,
|
|
440
|
+
path: path.concat([node.attrs.id]),
|
|
441
|
+
elementIDs: childElements(node)
|
|
442
|
+
.map((childNode) => childNode.attrs.id)
|
|
443
|
+
.filter((id) => id),
|
|
444
|
+
titleSuppressed: node.attrs.titleSuppressed || undefined,
|
|
445
|
+
generatedLabel: node.attrs.generatedLabel || undefined,
|
|
446
|
+
pageBreakStyle: node.attrs.pageBreakStyle || undefined,
|
|
447
|
+
}),
|
|
448
|
+
table: (node, parent) => ({
|
|
449
|
+
contents: tableContents(node, parent),
|
|
450
|
+
listingAttachment: node.attrs.listingAttachment || undefined,
|
|
451
|
+
}),
|
|
452
|
+
table_element: (node) => ({
|
|
453
|
+
containedObjectID: attributeOfNodeType(node, 'table', 'id'),
|
|
454
|
+
caption: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
|
|
455
|
+
title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
|
|
456
|
+
elementType: 'table',
|
|
457
|
+
listingID: attributeOfNodeType(node, 'listing', 'id') || undefined,
|
|
458
|
+
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
459
|
+
suppressCaption: Boolean(node.attrs.suppressCaption) || undefined,
|
|
460
|
+
suppressTitle: node.attrs.suppressTitle === undefined ||
|
|
461
|
+
node.attrs.suppressTitle === true
|
|
462
|
+
? undefined
|
|
463
|
+
: false,
|
|
464
|
+
suppressFooter: Boolean(node.attrs.suppressFooter) || undefined,
|
|
465
|
+
suppressHeader: Boolean(node.attrs.suppressHeader) || undefined,
|
|
466
|
+
tableStyle: node.attrs.tableStyle || undefined,
|
|
467
|
+
}),
|
|
468
|
+
toc_element: (node) => ({
|
|
469
|
+
contents: elementContents(node),
|
|
470
|
+
elementType: 'div',
|
|
471
|
+
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
472
|
+
}),
|
|
473
|
+
toc_section: (node, parent, path, priority) => ({
|
|
474
|
+
category: (0, section_category_1.buildSectionCategory)(node),
|
|
475
|
+
priority: priority.value++,
|
|
476
|
+
title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
|
|
477
|
+
path: path.concat([node.attrs.id]),
|
|
478
|
+
elementIDs: childElements(node)
|
|
479
|
+
.map((childNode) => childNode.attrs.id)
|
|
480
|
+
.filter((id) => id),
|
|
481
|
+
}),
|
|
482
|
+
};
|
|
483
|
+
const modelData = (node, parent, path, priority) => {
|
|
484
|
+
const encoder = encoders[node.type.name];
|
|
485
|
+
if (!encoder) {
|
|
486
|
+
throw new Error(`Unhandled model: ${node.type.name}`);
|
|
487
|
+
}
|
|
488
|
+
return encoder(node, parent, path, priority);
|
|
489
|
+
};
|
|
490
|
+
const modelFromNode = (node, parent, path, priority) => {
|
|
491
|
+
const commentAnnotationsMap = new Map();
|
|
492
|
+
const objectType = node_types_1.nodeTypesMap.get(node.type);
|
|
493
|
+
if (!objectType) {
|
|
494
|
+
throw new Error(`No objectType is defined for ${node.type.name}`);
|
|
495
|
+
}
|
|
496
|
+
const { id } = node.attrs;
|
|
497
|
+
if (!id) {
|
|
498
|
+
throw new Error(`No id is defined for this ${node.type.name}`);
|
|
499
|
+
}
|
|
500
|
+
const data = Object.assign(Object.assign({}, modelData(node, parent, path, priority)), { _id: id, objectType: objectType });
|
|
501
|
+
const model = data;
|
|
502
|
+
if ((0, highlight_markers_1.isHighlightableModel)(model)) {
|
|
503
|
+
(0, highlight_markers_1.extractHighlightMarkers)(model, commentAnnotationsMap);
|
|
504
|
+
if (node.attrs.comments) {
|
|
505
|
+
const commentNodes = node.attrs.comments;
|
|
506
|
+
commentNodes
|
|
507
|
+
.filter((commentNode) => !commentNode.attrs.selector)
|
|
508
|
+
.forEach((c) => {
|
|
509
|
+
const commentAnnotation = (0, builders_1.buildComment)(model._id, c.attrs.contents, c.attrs.selector);
|
|
510
|
+
commentAnnotation._id = c.attrs.id;
|
|
511
|
+
commentAnnotationsMap.set(commentAnnotation._id, commentAnnotation);
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return { model, commentAnnotationsMap };
|
|
516
|
+
};
|
|
517
|
+
exports.modelFromNode = modelFromNode;
|
|
518
|
+
const encode = (node) => {
|
|
519
|
+
const models = new Map();
|
|
520
|
+
const priority = {
|
|
521
|
+
value: 1,
|
|
522
|
+
};
|
|
523
|
+
const placeholders = ['placeholder', 'placeholder_element'];
|
|
524
|
+
const addModel = (path, parent) => (child) => {
|
|
525
|
+
if (!child.attrs.id) {
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
if ((0, schema_1.isHighlightMarkerNode)(child)) {
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
if (placeholders.includes(child.type.name)) {
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
const { model, commentAnnotationsMap } = (0, exports.modelFromNode)(child, parent, path, priority);
|
|
535
|
+
if (models.has(model._id)) {
|
|
536
|
+
throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
|
|
537
|
+
}
|
|
538
|
+
models.set(model._id, model);
|
|
539
|
+
commentAnnotationsMap.forEach((val, key) => models.set(key, val));
|
|
540
|
+
child.forEach(addModel(path.concat(child.attrs.id), child));
|
|
541
|
+
};
|
|
542
|
+
node.forEach(addModel([], node));
|
|
543
|
+
return models;
|
|
544
|
+
};
|
|
545
|
+
exports.encode = encode;
|
|
@@ -0,0 +1,27 @@
|
|
|
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.generateAttachmentFilename = void 0;
|
|
19
|
+
const generateAttachmentFilename = (id, contentType) => {
|
|
20
|
+
const basename = id.replace(':', '_');
|
|
21
|
+
if (!contentType) {
|
|
22
|
+
return basename;
|
|
23
|
+
}
|
|
24
|
+
const [, mimeSubType] = contentType.split('/');
|
|
25
|
+
return `${basename}.${mimeSubType}`;
|
|
26
|
+
};
|
|
27
|
+
exports.generateAttachmentFilename = generateAttachmentFilename;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* © 2021 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.buildFootnoteCategory = void 0;
|
|
19
|
+
const buildFootnoteCategory = (category) => (category && `MPFootnoteCategory:${category}`) || undefined;
|
|
20
|
+
exports.buildFootnoteCategory = buildFootnoteCategory;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* © 2022 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.createEmptyFootnotesOrder = exports.handleFootnotesOrder = exports.createOrderedFootnotesIDs = void 0;
|
|
19
|
+
const builders_1 = require("./builders");
|
|
20
|
+
const createOrderedFootnotesIDs = (doc) => {
|
|
21
|
+
const footnotesRefs = [...doc.querySelectorAll('xref[ref-type="fn"][rid]')];
|
|
22
|
+
const footnotes = [...doc.querySelectorAll('fn:not([fn-type])')];
|
|
23
|
+
const authorNotesIDs = [...doc.querySelectorAll('author-notes > fn')].map((an) => an.getAttribute('id'));
|
|
24
|
+
const orderedFootnotesIDs = [];
|
|
25
|
+
footnotesRefs.forEach((ref) => {
|
|
26
|
+
const refID = ref.getAttribute('rid');
|
|
27
|
+
if (refID) {
|
|
28
|
+
orderedFootnotesIDs.push(refID);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
footnotes.forEach((footnote) => {
|
|
32
|
+
const id = footnote.getAttribute('id');
|
|
33
|
+
if (id &&
|
|
34
|
+
!authorNotesIDs.includes(id) &&
|
|
35
|
+
!orderedFootnotesIDs.includes(id)) {
|
|
36
|
+
orderedFootnotesIDs.push(id);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return orderedFootnotesIDs;
|
|
40
|
+
};
|
|
41
|
+
exports.createOrderedFootnotesIDs = createOrderedFootnotesIDs;
|
|
42
|
+
const handleFootnotesOrder = (orderedFootnotesIDs, replacements, footnotesOrder) => {
|
|
43
|
+
const footnotesList = [];
|
|
44
|
+
let index = 0;
|
|
45
|
+
orderedFootnotesIDs.forEach((refID) => {
|
|
46
|
+
const fnID = replacements.get(refID);
|
|
47
|
+
if (fnID) {
|
|
48
|
+
footnotesList.push({
|
|
49
|
+
index,
|
|
50
|
+
id: fnID,
|
|
51
|
+
});
|
|
52
|
+
index++;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
footnotesOrder.footnotesList = footnotesList;
|
|
56
|
+
};
|
|
57
|
+
exports.handleFootnotesOrder = handleFootnotesOrder;
|
|
58
|
+
const createEmptyFootnotesOrder = () => (0, builders_1.buildFootnotesOrder)([]);
|
|
59
|
+
exports.createEmptyFootnotesOrder = createEmptyFootnotesOrder;
|