@manuscripts/transform 2.10.0-LEAN-3577 → 3.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/dist/cjs/index.js +9 -7
- package/dist/cjs/jats/{jats-exporter.js → exporter/jats-exporter.js} +286 -416
- package/dist/cjs/jats/{jats-versions.js → exporter/jats-versions.js} +1 -3
- package/dist/cjs/{transformer → jats/exporter}/labels.js +7 -19
- package/dist/cjs/{transformer/filename.js → jats/importer/create-article-node.js} +12 -9
- package/dist/cjs/jats/importer/jats-body-transformations.js +22 -1
- package/dist/cjs/jats/importer/jats-comments.js +48 -110
- package/dist/cjs/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +364 -11
- package/dist/cjs/jats/importer/jats-journal-meta-parser.js +11 -1
- package/dist/cjs/jats/importer/jats-parser-utils.js +52 -4
- package/dist/cjs/jats/importer/jats-transformations.js +389 -0
- package/dist/cjs/jats/importer/parse-jats-article.js +43 -100
- package/dist/cjs/jats/index.js +7 -7
- package/dist/cjs/{transformer/models.js → lib/deafults.js} +3 -1
- package/dist/cjs/lib/utils.js +3 -1
- package/dist/cjs/schema/index.js +10 -0
- package/dist/cjs/schema/migration/migrate.js +3 -9
- package/dist/cjs/schema/migration/migration-script.js +1 -1
- package/dist/cjs/schema/migration/migration-scripts/1.2.5.js +2 -2
- package/dist/cjs/schema/migration/migration-scripts/2.3.22.js +28 -0
- package/dist/cjs/schema/migration/migration-scripts/index.js +3 -2
- package/dist/cjs/schema/nodes/author_notes.js +9 -2
- package/dist/cjs/schema/nodes/award.js +38 -0
- package/dist/cjs/{transformer/serializer.js → schema/nodes/awards.js} +20 -7
- package/dist/cjs/schema/nodes/backmatter.js +3 -2
- package/dist/cjs/schema/nodes/box_element.js +55 -0
- package/dist/cjs/schema/nodes/contributors.js +1 -1
- package/dist/cjs/schema/nodes/corresp.js +13 -2
- package/dist/cjs/schema/nodes/equation_element.js +0 -1
- package/dist/cjs/schema/nodes/figure_element.js +0 -1
- package/dist/cjs/schema/nodes/footnote.js +0 -1
- package/dist/cjs/schema/nodes/footnotes_section.js +1 -1
- package/dist/cjs/schema/nodes/highlight_marker.js +0 -4
- package/dist/cjs/schema/nodes/inline_equation.js +0 -1
- package/dist/cjs/schema/nodes/inline_footnote.js +1 -0
- package/dist/cjs/schema/nodes/keyword.js +0 -1
- package/dist/cjs/schema/nodes/listing.js +0 -1
- package/dist/cjs/schema/nodes/listing_element.js +0 -1
- package/dist/cjs/schema/nodes/manuscript.js +4 -1
- package/dist/cjs/schema/nodes/paragraph.js +0 -1
- package/dist/cjs/schema/nodes/section.js +0 -1
- package/dist/cjs/schema/nodes/table_element.js +1 -2
- package/dist/cjs/schema/nodes/title.js +1 -0
- package/dist/cjs/transformer/id.js +1 -5
- package/dist/cjs/transformer/index.js +0 -18
- package/dist/cjs/transformer/node-names.js +1 -0
- package/dist/cjs/transformer/node-types.js +1 -0
- package/dist/cjs/transformer/section-category.js +8 -0
- package/dist/cjs/version.js +1 -1
- package/dist/es/index.js +6 -5
- package/dist/es/jats/{jats-exporter.js → exporter/jats-exporter.js} +281 -411
- package/dist/es/jats/{jats-versions.js → exporter/jats-versions.js} +0 -1
- package/dist/es/{transformer → jats/exporter}/labels.js +7 -19
- package/dist/{cjs/transformer/model-map.js → es/jats/importer/create-article-node.js} +10 -10
- package/dist/es/jats/importer/jats-body-transformations.js +22 -1
- package/dist/es/jats/importer/jats-comments.js +49 -107
- package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +364 -11
- package/dist/es/jats/importer/jats-journal-meta-parser.js +9 -0
- package/dist/es/jats/importer/jats-parser-utils.js +54 -6
- package/dist/es/jats/importer/jats-transformations.js +370 -0
- package/dist/es/jats/importer/parse-jats-article.js +43 -98
- package/dist/es/jats/index.js +5 -3
- package/dist/{types/transformer/timestamp.d.ts → es/lib/deafults.js} +2 -2
- package/dist/es/lib/utils.js +1 -0
- package/dist/es/schema/index.js +10 -0
- package/dist/es/schema/migration/migrate.js +3 -9
- package/dist/es/schema/migration/migration-script.js +1 -1
- package/dist/es/schema/migration/migration-scripts/1.2.5.js +2 -2
- package/dist/es/schema/migration/migration-scripts/2.3.22.js +26 -0
- package/dist/es/schema/migration/migration-scripts/index.js +3 -2
- package/dist/es/schema/nodes/author_notes.js +9 -2
- package/dist/es/{transformer/__tests__/__helpers__/doc.js → schema/nodes/award.js} +19 -14
- package/dist/es/{transformer/model-map.js → schema/nodes/awards.js} +17 -7
- package/dist/es/schema/nodes/backmatter.js +3 -2
- package/dist/es/schema/nodes/box_element.js +52 -0
- package/dist/es/schema/nodes/contributors.js +1 -1
- package/dist/es/schema/nodes/corresp.js +11 -1
- package/dist/es/schema/nodes/equation_element.js +0 -1
- package/dist/es/schema/nodes/figure_element.js +0 -1
- package/dist/es/schema/nodes/footnote.js +0 -1
- package/dist/es/schema/nodes/footnotes_section.js +1 -1
- package/dist/es/schema/nodes/highlight_marker.js +0 -4
- package/dist/es/schema/nodes/inline_equation.js +0 -1
- package/dist/es/schema/nodes/inline_footnote.js +1 -0
- package/dist/es/schema/nodes/keyword.js +0 -1
- package/dist/es/schema/nodes/listing.js +0 -1
- package/dist/es/schema/nodes/listing_element.js +0 -1
- package/dist/es/schema/nodes/manuscript.js +4 -1
- package/dist/es/schema/nodes/paragraph.js +0 -1
- package/dist/es/schema/nodes/section.js +0 -1
- package/dist/es/schema/nodes/table_element.js +1 -2
- package/dist/es/schema/nodes/title.js +1 -0
- package/dist/es/transformer/id.js +0 -3
- package/dist/es/transformer/index.js +0 -16
- package/dist/es/transformer/node-names.js +1 -0
- package/dist/es/transformer/node-types.js +1 -0
- package/dist/es/transformer/section-category.js +8 -0
- package/dist/es/version.js +1 -1
- package/dist/types/index.d.ts +6 -5
- package/dist/types/jats/{jats-exporter.d.ts → exporter/jats-exporter.d.ts} +15 -29
- package/dist/types/jats/{jats-versions.d.ts → exporter/jats-versions.d.ts} +0 -1
- package/dist/types/{transformer → jats/exporter}/labels.d.ts +2 -3
- package/dist/{es/transformer/footnote-category.js → types/jats/importer/create-article-node.d.ts} +3 -2
- package/dist/types/jats/importer/jats-body-transformations.d.ts +1 -0
- package/dist/types/jats/importer/jats-comments.d.ts +2 -15
- package/dist/types/jats/importer/{jats-body-dom-parser.d.ts → jats-dom-parser.d.ts} +1 -1
- package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +9 -0
- package/dist/types/jats/importer/jats-parser-utils.d.ts +2 -2
- package/dist/types/jats/importer/jats-transformations.d.ts +32 -0
- package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
- package/dist/types/jats/index.d.ts +5 -3
- package/dist/types/jats/types.d.ts +1 -0
- package/dist/{es/transformer/models.js → types/lib/deafults.d.ts} +2 -2
- package/dist/types/lib/utils.d.ts +1 -0
- package/dist/types/schema/index.d.ts +4 -0
- package/dist/types/schema/migration/migration-script.d.ts +1 -1
- package/dist/types/schema/migration/migration-scripts/1.2.5.d.ts +1 -1
- package/dist/types/schema/migration/migration-scripts/2.3.22.d.ts +8 -0
- package/dist/types/schema/migration/migration-scripts/index.d.ts +3 -2
- package/dist/types/{transformer/footnotes-order.d.ts → schema/nodes/award.d.ts} +14 -7
- package/dist/{cjs/transformer/footnote-category.js → types/schema/nodes/awards.d.ts} +12 -6
- package/dist/types/schema/nodes/bibliography_item.d.ts +3 -3
- package/dist/{es/transformer/filename.js → types/schema/nodes/box_element.d.ts} +11 -8
- package/dist/types/schema/nodes/contributor.d.ts +10 -0
- package/dist/types/schema/nodes/contributors.d.ts +8 -0
- package/dist/types/schema/nodes/corresp.d.ts +1 -0
- package/dist/types/schema/nodes/equation_element.d.ts +0 -2
- package/dist/types/schema/nodes/figure_element.d.ts +0 -2
- package/dist/types/schema/nodes/footnote.d.ts +0 -2
- package/dist/types/schema/nodes/highlight_marker.d.ts +0 -2
- package/dist/types/schema/nodes/inline_equation.d.ts +0 -2
- package/dist/types/schema/nodes/keyword.d.ts +0 -2
- package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
- package/dist/types/schema/nodes/listing.d.ts +0 -2
- package/dist/types/schema/nodes/listing_element.d.ts +0 -2
- package/dist/types/schema/nodes/manuscript.d.ts +8 -4
- package/dist/types/schema/nodes/paragraph.d.ts +0 -2
- package/dist/types/schema/nodes/section.d.ts +0 -2
- package/dist/types/schema/nodes/table_element.d.ts +0 -2
- package/dist/types/schema/nodes/title.d.ts +1 -3
- package/dist/types/schema/types.d.ts +1 -1
- package/dist/types/transformer/id.d.ts +0 -3
- package/dist/types/transformer/index.d.ts +0 -16
- package/dist/types/transformer/section-category.d.ts +2 -2
- package/dist/types/version.d.ts +1 -1
- package/package.json +7 -8
- package/dist/cjs/__tests__/data/project-dump.json +0 -824
- package/dist/cjs/jats/importer/index.js +0 -22
- package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
- package/dist/cjs/jats/importer/jats-reference-parser.js +0 -130
- package/dist/cjs/jats/importer/jats-references.js +0 -34
- package/dist/cjs/transformer/__tests__/__helpers__/doc.js +0 -37
- package/dist/cjs/transformer/builders.js +0 -219
- package/dist/cjs/transformer/decode.js +0 -878
- package/dist/cjs/transformer/document-object-types.js +0 -31
- package/dist/cjs/transformer/encode.js +0 -654
- package/dist/cjs/transformer/footnotes-order.js +0 -60
- package/dist/cjs/transformer/highlight-markers.js +0 -138
- package/dist/cjs/transformer/html.js +0 -401
- package/dist/cjs/transformer/manuscript-dependencies.js +0 -21
- package/dist/cjs/transformer/object-types.js +0 -57
- package/dist/cjs/transformer/project-bundle.js +0 -94
- package/dist/cjs/transformer/timestamp.js +0 -20
- package/dist/cjs/transformer/update-identifiers.js +0 -93
- package/dist/es/__tests__/data/project-dump.json +0 -824
- package/dist/es/jats/importer/index.js +0 -16
- package/dist/es/jats/importer/jats-front-parser.js +0 -315
- package/dist/es/jats/importer/jats-reference-parser.js +0 -127
- package/dist/es/jats/importer/jats-references.js +0 -30
- package/dist/es/transformer/builders.js +0 -186
- package/dist/es/transformer/decode.js +0 -868
- package/dist/es/transformer/document-object-types.js +0 -28
- package/dist/es/transformer/encode.js +0 -644
- package/dist/es/transformer/footnotes-order.js +0 -55
- package/dist/es/transformer/highlight-markers.js +0 -132
- package/dist/es/transformer/html.js +0 -394
- package/dist/es/transformer/manuscript-dependencies.js +0 -17
- package/dist/es/transformer/object-types.js +0 -52
- package/dist/es/transformer/project-bundle.js +0 -85
- package/dist/es/transformer/serializer.js +0 -17
- package/dist/es/transformer/timestamp.js +0 -16
- package/dist/es/transformer/update-identifiers.js +0 -87
- package/dist/types/jats/importer/index.d.ts +0 -16
- package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
- package/dist/types/jats/importer/jats-reference-parser.d.ts +0 -19
- package/dist/types/jats/importer/jats-references.d.ts +0 -12
- package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +0 -18
- package/dist/types/transformer/builders.d.ts +0 -61
- package/dist/types/transformer/decode.d.ts +0 -50
- package/dist/types/transformer/document-object-types.d.ts +0 -17
- package/dist/types/transformer/encode.d.ts +0 -29
- package/dist/types/transformer/filename.d.ts +0 -16
- package/dist/types/transformer/footnote-category.d.ts +0 -17
- package/dist/types/transformer/highlight-markers.d.ts +0 -31
- package/dist/types/transformer/html.d.ts +0 -36
- package/dist/types/transformer/manuscript-dependencies.d.ts +0 -4
- package/dist/types/transformer/model-map.d.ts +0 -19
- package/dist/types/transformer/models.d.ts +0 -48
- package/dist/types/transformer/object-types.d.ts +0 -30
- package/dist/types/transformer/project-bundle.d.ts +0 -30
- package/dist/types/transformer/serializer.d.ts +0 -19
- package/dist/types/transformer/update-identifiers.d.ts +0 -23
- package/dist/types/types.d.ts +0 -2
- /package/dist/cjs/{types.js → jats/types.js} +0 -0
- /package/dist/es/{types.js → jats/types.js} +0 -0
|
@@ -1,31 +0,0 @@
|
|
|
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 json_schema_1 = require("@manuscripts/json-schema");
|
|
20
|
-
exports.documentObjectTypes = [
|
|
21
|
-
json_schema_1.ObjectTypes.BibliographyElement,
|
|
22
|
-
json_schema_1.ObjectTypes.EquationElement,
|
|
23
|
-
json_schema_1.ObjectTypes.FigureElement,
|
|
24
|
-
json_schema_1.ObjectTypes.ListElement,
|
|
25
|
-
json_schema_1.ObjectTypes.ListingElement,
|
|
26
|
-
json_schema_1.ObjectTypes.Manuscript,
|
|
27
|
-
json_schema_1.ObjectTypes.ParagraphElement,
|
|
28
|
-
json_schema_1.ObjectTypes.Section,
|
|
29
|
-
json_schema_1.ObjectTypes.TableElement,
|
|
30
|
-
json_schema_1.ObjectTypes.TOCElement,
|
|
31
|
-
];
|
|
@@ -1,654 +0,0 @@
|
|
|
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 keywordContents = (node) => {
|
|
44
|
-
const text = serializer.serializeNode(node).textContent;
|
|
45
|
-
return text === null ? '' : text;
|
|
46
|
-
};
|
|
47
|
-
const inlineContents = (node) => serializer.serializeNode(node).innerHTML;
|
|
48
|
-
exports.inlineContents = inlineContents;
|
|
49
|
-
const inlineText = (node) => {
|
|
50
|
-
const text = serializer.serializeNode(node).textContent;
|
|
51
|
-
return text === null ? '' : text;
|
|
52
|
-
};
|
|
53
|
-
exports.inlineText = inlineText;
|
|
54
|
-
const listContents = (node) => {
|
|
55
|
-
const output = serializer.serializeNode(node);
|
|
56
|
-
for (const p of output.querySelectorAll('li > p')) {
|
|
57
|
-
const parent = p.parentNode;
|
|
58
|
-
while (p.firstChild) {
|
|
59
|
-
parent.insertBefore(p.firstChild, p);
|
|
60
|
-
}
|
|
61
|
-
parent.removeChild(p);
|
|
62
|
-
}
|
|
63
|
-
return (0, w3c_xmlserializer_1.default)(output);
|
|
64
|
-
};
|
|
65
|
-
const tableRowDisplayStyle = (tagName, parent) => {
|
|
66
|
-
switch (tagName) {
|
|
67
|
-
case 'thead':
|
|
68
|
-
return parent.attrs.suppressHeader ? 'none' : 'table-header-group';
|
|
69
|
-
case 'tfoot':
|
|
70
|
-
return parent.attrs.suppressFooter ? 'none' : 'table-footer-group';
|
|
71
|
-
default:
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const buildTableSection = (tagName, inputRows, parent) => {
|
|
76
|
-
const section = document.createElement(tagName);
|
|
77
|
-
for (const sectionRow of inputRows) {
|
|
78
|
-
const row = section.appendChild(document.createElement('tr'));
|
|
79
|
-
for (const child of sectionRow.children) {
|
|
80
|
-
const cellType = tagName === 'thead' ? 'th' : 'td';
|
|
81
|
-
const cell = row.appendChild(document.createElement(cellType));
|
|
82
|
-
while (child.firstChild) {
|
|
83
|
-
cell.appendChild(child.firstChild);
|
|
84
|
-
}
|
|
85
|
-
for (const attribute of child.attributes) {
|
|
86
|
-
cell.setAttribute(attribute.name, attribute.value);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
const displayStyle = tableRowDisplayStyle(tagName, parent);
|
|
91
|
-
if (displayStyle) {
|
|
92
|
-
section.style.display = displayStyle;
|
|
93
|
-
}
|
|
94
|
-
return section;
|
|
95
|
-
};
|
|
96
|
-
function buildTableColGroup(cols) {
|
|
97
|
-
if (cols.length === 0) {
|
|
98
|
-
return undefined;
|
|
99
|
-
}
|
|
100
|
-
const colgroup = document.createElement('colgroup');
|
|
101
|
-
for (const inputCol of cols) {
|
|
102
|
-
const col = document.createElement('col');
|
|
103
|
-
for (const attribute of inputCol.attributes) {
|
|
104
|
-
col.setAttribute(attribute.name, attribute.value);
|
|
105
|
-
}
|
|
106
|
-
colgroup.appendChild(inputCol);
|
|
107
|
-
}
|
|
108
|
-
return colgroup;
|
|
109
|
-
}
|
|
110
|
-
const tableContents = (node, parent) => {
|
|
111
|
-
const input = serializer.serializeNode(node);
|
|
112
|
-
const parentInput = serializer.serializeNode(parent);
|
|
113
|
-
const output = document.createElement('table');
|
|
114
|
-
const colgroup = buildTableColGroup(Array.from(parentInput.querySelectorAll('col')));
|
|
115
|
-
if (colgroup) {
|
|
116
|
-
output.appendChild(colgroup);
|
|
117
|
-
}
|
|
118
|
-
output.setAttribute('id', parent.attrs.id);
|
|
119
|
-
output.classList.add('MPElement');
|
|
120
|
-
if (parent.attrs.tableStyle) {
|
|
121
|
-
output.classList.add(parent.attrs.tableStyle.replace(/:/g, '_'));
|
|
122
|
-
}
|
|
123
|
-
if (parent.attrs.paragraphStyle) {
|
|
124
|
-
output.classList.add(parent.attrs.paragraphStyle.replace(/:/g, '_'));
|
|
125
|
-
}
|
|
126
|
-
output.setAttribute('data-contained-object-id', node.attrs.id);
|
|
127
|
-
const rows = Array.from(input.querySelectorAll('tr'));
|
|
128
|
-
let headerCount = 0;
|
|
129
|
-
for (const row of rows) {
|
|
130
|
-
const th = row.querySelector('th[scope="col"], th[scope="colgroup"]');
|
|
131
|
-
th && headerCount++;
|
|
132
|
-
}
|
|
133
|
-
const thead = rows.splice(0, headerCount || 1);
|
|
134
|
-
const tfoot = rows.splice(-1, 1);
|
|
135
|
-
output.appendChild(buildTableSection('thead', thead, parent));
|
|
136
|
-
output.appendChild(buildTableSection('tbody', rows, parent));
|
|
137
|
-
output.appendChild(buildTableSection('tfoot', tfoot, parent));
|
|
138
|
-
return (0, w3c_xmlserializer_1.default)(output);
|
|
139
|
-
};
|
|
140
|
-
const elementContents = (node) => {
|
|
141
|
-
const input = serializer.serializeNode(node);
|
|
142
|
-
input.classList.add('MPElement');
|
|
143
|
-
if (node.attrs.paragraphStyle) {
|
|
144
|
-
input.classList.add(node.attrs.paragraphStyle.replace(/:/g, '_'));
|
|
145
|
-
}
|
|
146
|
-
if (node.attrs.id) {
|
|
147
|
-
input.setAttribute('id', node.attrs.id);
|
|
148
|
-
}
|
|
149
|
-
return (0, w3c_xmlserializer_1.default)(input);
|
|
150
|
-
};
|
|
151
|
-
const childElements = (node) => {
|
|
152
|
-
const nodes = [];
|
|
153
|
-
node.forEach((childNode) => {
|
|
154
|
-
if (!(0, schema_1.isSectionNode)(childNode)) {
|
|
155
|
-
nodes.push(childNode);
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
return nodes;
|
|
159
|
-
};
|
|
160
|
-
const sectionChildElementIds = (node) => {
|
|
161
|
-
const nodes = [];
|
|
162
|
-
node.forEach((childNode) => {
|
|
163
|
-
if (!(0, schema_1.hasGroup)(childNode.type, 'sections')) {
|
|
164
|
-
nodes.push(childNode);
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
return nodes.map((childNode) => childNode.attrs.id).filter((id) => id);
|
|
168
|
-
};
|
|
169
|
-
const attributeOfNodeType = (node, type, attribute) => {
|
|
170
|
-
for (const child of (0, utils_1.iterateChildren)(node)) {
|
|
171
|
-
if (child.type.name === type) {
|
|
172
|
-
return child.attrs[attribute];
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return '';
|
|
176
|
-
};
|
|
177
|
-
const inlineContentsOfNodeType = (node, nodeType) => {
|
|
178
|
-
for (let i = 0; i < node.childCount; i++) {
|
|
179
|
-
const child = node.child(i);
|
|
180
|
-
if (child.type === nodeType) {
|
|
181
|
-
return (0, exports.inlineContents)(child);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return '';
|
|
185
|
-
};
|
|
186
|
-
const inlineContentOfChildNodeType = (node, parentNodeType, childNodeType, empty = true) => {
|
|
187
|
-
const parentNode = childElements(node).find((node) => node.type === parentNodeType && node);
|
|
188
|
-
const content = parentNode && inlineContentsOfNodeType(parentNode, childNodeType);
|
|
189
|
-
return content && content.length > 1 ? content : empty ? content : undefined;
|
|
190
|
-
};
|
|
191
|
-
const wrappedContentOfChildrenNodeType = (node, parentNodeType, childNodeType) => {
|
|
192
|
-
const parentNode = childElements(node).find((node) => node.type === parentNodeType && node);
|
|
193
|
-
const content = parentNode &&
|
|
194
|
-
childElements(parentNode)
|
|
195
|
-
.filter((node) => node.type === childNodeType && node)
|
|
196
|
-
.map((node) => serializer.serializeNode(node).outerHTML)
|
|
197
|
-
.join('');
|
|
198
|
-
return content;
|
|
199
|
-
};
|
|
200
|
-
const containedFigureIDs = (node) => {
|
|
201
|
-
const figureNodeType = node.type.schema.nodes.figure;
|
|
202
|
-
const missingFigureNodeType = node.type.schema.nodes.missing_figure;
|
|
203
|
-
return containedObjectIDs(node, [figureNodeType, missingFigureNodeType]);
|
|
204
|
-
};
|
|
205
|
-
const containedParagraphIDs = (node) => {
|
|
206
|
-
const paragraphNodeType = node.type.schema.nodes.paragraph;
|
|
207
|
-
return containedObjectIDs(node, [paragraphNodeType]);
|
|
208
|
-
};
|
|
209
|
-
const containedBibliographyItemIDs = (node) => {
|
|
210
|
-
const bibliographyItemNodeType = node.type.schema.nodes.bibliography_item;
|
|
211
|
-
return containedObjectIDs(node, [bibliographyItemNodeType]);
|
|
212
|
-
};
|
|
213
|
-
const tableElementFooterContainedIDs = (node) => {
|
|
214
|
-
const containedGeneralTableFootnoteIDs = containedObjectIDs(node, [
|
|
215
|
-
schema_1.schema.nodes.footnotes_element,
|
|
216
|
-
]);
|
|
217
|
-
for (let i = 0; i < node.childCount; i++) {
|
|
218
|
-
const childNode = node.child(i);
|
|
219
|
-
if (childNode.type === schema_1.schema.nodes.general_table_footnote) {
|
|
220
|
-
containedGeneralTableFootnoteIDs.push(...containedObjectIDs(childNode));
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return containedGeneralTableFootnoteIDs;
|
|
224
|
-
};
|
|
225
|
-
const containedObjectIDs = (node, nodeTypes) => {
|
|
226
|
-
const ids = [];
|
|
227
|
-
for (let i = 0; i < node.childCount; i++) {
|
|
228
|
-
const childNode = node.child(i);
|
|
229
|
-
if (!nodeTypes || nodeTypes.includes(childNode.type)) {
|
|
230
|
-
ids.push(childNode.attrs.id);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return ids;
|
|
234
|
-
};
|
|
235
|
-
const attribution = (node) => {
|
|
236
|
-
if (node.attrs.attribution) {
|
|
237
|
-
return Object.assign(Object.assign({}, node.attrs.attribution), (0, builders_1.buildAttribution)());
|
|
238
|
-
}
|
|
239
|
-
return undefined;
|
|
240
|
-
};
|
|
241
|
-
const fromJson = (json) => {
|
|
242
|
-
let obj;
|
|
243
|
-
try {
|
|
244
|
-
obj = JSON.parse(json);
|
|
245
|
-
}
|
|
246
|
-
catch (e) {
|
|
247
|
-
}
|
|
248
|
-
return obj;
|
|
249
|
-
};
|
|
250
|
-
function figureElementEncoder(node) {
|
|
251
|
-
var _a;
|
|
252
|
-
return {
|
|
253
|
-
containedObjectIDs: (_a = containedParagraphIDs(node)) === null || _a === void 0 ? void 0 : _a.concat(containedFigureIDs(node)),
|
|
254
|
-
caption: wrappedContentOfChildrenNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
|
|
255
|
-
title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
|
|
256
|
-
label: node.attrs.label,
|
|
257
|
-
elementType: 'figure',
|
|
258
|
-
attribution: attribution(node),
|
|
259
|
-
alternatives: node.attrs.alternatives,
|
|
260
|
-
listingID: attributeOfNodeType(node, 'listing', 'id') || undefined,
|
|
261
|
-
alignment: node.attrs.alignment || undefined,
|
|
262
|
-
sizeFraction: node.attrs.sizeFraction || undefined,
|
|
263
|
-
suppressCaption: Boolean(node.attrs.suppressCaption) || undefined,
|
|
264
|
-
suppressTitle: node.attrs.suppressTitle === undefined ||
|
|
265
|
-
node.attrs.suppressTitle === true
|
|
266
|
-
? undefined
|
|
267
|
-
: false,
|
|
268
|
-
figureStyle: node.attrs.figureStyle || undefined,
|
|
269
|
-
figureLayout: node.attrs.figureLayout || undefined,
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
const encoders = {
|
|
273
|
-
title: (node) => ({
|
|
274
|
-
title: (0, exports.inlineContents)(node),
|
|
275
|
-
subtitle: node.attrs.subtitle,
|
|
276
|
-
runningTitle: node.attrs.runningTitle,
|
|
277
|
-
_id: node.attrs._id,
|
|
278
|
-
}),
|
|
279
|
-
bibliography_element: (node) => ({
|
|
280
|
-
elementType: 'div',
|
|
281
|
-
contents: '',
|
|
282
|
-
containedObjectIDs: containedBibliographyItemIDs(node),
|
|
283
|
-
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
284
|
-
}),
|
|
285
|
-
bibliography_item: (node) => {
|
|
286
|
-
const { type, containerTitle, doi, volume, issue, supplement, page, title, literal, } = node.attrs;
|
|
287
|
-
const getObjectAtrr = (obj) => typeof obj === 'string' ? fromJson(obj) : obj;
|
|
288
|
-
const author = getObjectAtrr(node.attrs.author);
|
|
289
|
-
const issued = getObjectAtrr(node.attrs.issued);
|
|
290
|
-
const ref = {
|
|
291
|
-
type,
|
|
292
|
-
};
|
|
293
|
-
if (author) {
|
|
294
|
-
ref.author = author;
|
|
295
|
-
}
|
|
296
|
-
if (issued) {
|
|
297
|
-
ref.issued = issued;
|
|
298
|
-
}
|
|
299
|
-
if (containerTitle) {
|
|
300
|
-
ref['container-title'] = containerTitle;
|
|
301
|
-
}
|
|
302
|
-
if (doi) {
|
|
303
|
-
ref.DOI = doi;
|
|
304
|
-
}
|
|
305
|
-
if (volume) {
|
|
306
|
-
ref.volume = volume;
|
|
307
|
-
}
|
|
308
|
-
if (issue) {
|
|
309
|
-
ref.issue = issue;
|
|
310
|
-
}
|
|
311
|
-
if (supplement) {
|
|
312
|
-
ref.supplement = supplement;
|
|
313
|
-
}
|
|
314
|
-
if (page) {
|
|
315
|
-
ref.page = page;
|
|
316
|
-
}
|
|
317
|
-
if (title) {
|
|
318
|
-
ref.title = title;
|
|
319
|
-
}
|
|
320
|
-
if (literal) {
|
|
321
|
-
ref.literal = literal;
|
|
322
|
-
}
|
|
323
|
-
return ref;
|
|
324
|
-
},
|
|
325
|
-
bibliography_section: (node, parent, path, priority) => ({
|
|
326
|
-
category: (0, section_category_1.buildSectionCategory)(node),
|
|
327
|
-
priority: priority.value++,
|
|
328
|
-
title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
|
|
329
|
-
path: path.concat([node.attrs.id]),
|
|
330
|
-
elementIDs: childElements(node)
|
|
331
|
-
.map((childNode) => childNode.attrs.id)
|
|
332
|
-
.filter((id) => id),
|
|
333
|
-
}),
|
|
334
|
-
blockquote_element: (node) => ({
|
|
335
|
-
contents: contents(node),
|
|
336
|
-
elementType: 'div',
|
|
337
|
-
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
338
|
-
placeholderInnerHTML: node.attrs.placeholder || '',
|
|
339
|
-
quoteType: 'block',
|
|
340
|
-
}),
|
|
341
|
-
list: (node) => ({
|
|
342
|
-
elementType: (0, schema_1.getListType)(node.attrs.listStyleType).type,
|
|
343
|
-
contents: listContents(node),
|
|
344
|
-
listStyleType: node.attrs.listStyleType,
|
|
345
|
-
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
346
|
-
}),
|
|
347
|
-
listing: (node) => ({
|
|
348
|
-
contents: (0, exports.inlineText)(node),
|
|
349
|
-
language: node.attrs.language || undefined,
|
|
350
|
-
languageKey: node.attrs.languageKey || 'null',
|
|
351
|
-
}),
|
|
352
|
-
listing_element: (node) => ({
|
|
353
|
-
containedObjectID: attributeOfNodeType(node, 'listing', 'id'),
|
|
354
|
-
caption: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
|
|
355
|
-
title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
|
|
356
|
-
elementType: 'figure',
|
|
357
|
-
suppressCaption: node.attrs.suppressCaption === true ? undefined : false,
|
|
358
|
-
suppressTitle: node.attrs.suppressTitle === undefined ||
|
|
359
|
-
node.attrs.suppressTitle === true
|
|
360
|
-
? undefined
|
|
361
|
-
: false,
|
|
362
|
-
}),
|
|
363
|
-
equation: (node) => ({
|
|
364
|
-
contents: node.attrs.contents,
|
|
365
|
-
format: node.attrs.format,
|
|
366
|
-
}),
|
|
367
|
-
equation_element: (node) => ({
|
|
368
|
-
containedObjectID: attributeOfNodeType(node, 'equation', 'id'),
|
|
369
|
-
elementType: 'div',
|
|
370
|
-
label: node.attrs.label,
|
|
371
|
-
}),
|
|
372
|
-
figure: (node) => ({
|
|
373
|
-
contentType: node.attrs.contentType || undefined,
|
|
374
|
-
src: node.attrs.src || undefined,
|
|
375
|
-
position: node.attrs.position || undefined,
|
|
376
|
-
}),
|
|
377
|
-
figure_element: (node) => figureElementEncoder(node),
|
|
378
|
-
comment: (node) => ({
|
|
379
|
-
selector: node.attrs.selector,
|
|
380
|
-
target: node.attrs.target,
|
|
381
|
-
contents: node.attrs.contents,
|
|
382
|
-
resolved: node.attrs.resolved,
|
|
383
|
-
contributions: node.attrs.contributions,
|
|
384
|
-
originalText: node.attrs.originalText,
|
|
385
|
-
}),
|
|
386
|
-
footnote: (node, parent) => ({
|
|
387
|
-
containingObject: parent.attrs.id,
|
|
388
|
-
contents: footnoteContents(node),
|
|
389
|
-
kind: node.attrs.kind || 'footnote',
|
|
390
|
-
}),
|
|
391
|
-
footnotes_element: (node) => ({
|
|
392
|
-
contents: '<div></div>',
|
|
393
|
-
elementType: 'div',
|
|
394
|
-
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
395
|
-
}),
|
|
396
|
-
table_element_footer: (node) => ({
|
|
397
|
-
containedObjectIDs: tableElementFooterContainedIDs(node),
|
|
398
|
-
}),
|
|
399
|
-
author_notes: (node) => ({
|
|
400
|
-
containedObjectIDs: containedObjectIDs(node),
|
|
401
|
-
}),
|
|
402
|
-
footnotes_section: (node, parent, path, priority) => ({
|
|
403
|
-
category: (0, section_category_1.buildSectionCategory)(node),
|
|
404
|
-
priority: priority.value++,
|
|
405
|
-
title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
|
|
406
|
-
path: path.concat([node.attrs.id]),
|
|
407
|
-
elementIDs: childElements(node)
|
|
408
|
-
.map((childNode) => childNode.attrs.id)
|
|
409
|
-
.filter((id) => id),
|
|
410
|
-
}),
|
|
411
|
-
graphical_abstract_section: (node, parent, path, priority) => ({
|
|
412
|
-
category: (0, section_category_1.buildSectionCategory)(node),
|
|
413
|
-
priority: priority.value++,
|
|
414
|
-
title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
|
|
415
|
-
path: path.concat([node.attrs.id]),
|
|
416
|
-
elementIDs: childElements(node)
|
|
417
|
-
.map((childNode) => childNode.attrs.id)
|
|
418
|
-
.filter((id) => id),
|
|
419
|
-
}),
|
|
420
|
-
keyword: (node, parent) => ({
|
|
421
|
-
containedGroup: parent.attrs.id,
|
|
422
|
-
name: keywordContents(node),
|
|
423
|
-
}),
|
|
424
|
-
keywords_element: (node) => ({
|
|
425
|
-
contents: '<div></div>',
|
|
426
|
-
elementType: 'div',
|
|
427
|
-
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
428
|
-
}),
|
|
429
|
-
keyword_group: (node) => ({
|
|
430
|
-
type: node.attrs.type,
|
|
431
|
-
}),
|
|
432
|
-
missing_figure: (node) => ({
|
|
433
|
-
position: node.attrs.position || undefined,
|
|
434
|
-
}),
|
|
435
|
-
paragraph: (node) => ({
|
|
436
|
-
elementType: 'p',
|
|
437
|
-
contents: contents(node),
|
|
438
|
-
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
439
|
-
placeholderInnerHTML: node.attrs.placeholder || '',
|
|
440
|
-
}),
|
|
441
|
-
placeholder_element: () => ({
|
|
442
|
-
elementType: 'p',
|
|
443
|
-
}),
|
|
444
|
-
pullquote_element: (node) => ({
|
|
445
|
-
contents: contents(node),
|
|
446
|
-
elementType: 'div',
|
|
447
|
-
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
448
|
-
placeholderInnerHTML: node.attrs.placeholder || '',
|
|
449
|
-
quoteType: 'pull',
|
|
450
|
-
}),
|
|
451
|
-
section: (node, parent, path, priority) => ({
|
|
452
|
-
category: (0, section_category_1.buildSectionCategory)(node),
|
|
453
|
-
priority: priority.value++,
|
|
454
|
-
title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
|
|
455
|
-
label: inlineContentsOfNodeType(node, node.type.schema.nodes.section_label) ||
|
|
456
|
-
undefined,
|
|
457
|
-
path: path.concat([node.attrs.id]),
|
|
458
|
-
elementIDs: sectionChildElementIds(node),
|
|
459
|
-
titleSuppressed: node.attrs.titleSuppressed || undefined,
|
|
460
|
-
generatedLabel: node.attrs.generatedLabel || undefined,
|
|
461
|
-
pageBreakStyle: node.attrs.pageBreakStyle || undefined,
|
|
462
|
-
}),
|
|
463
|
-
table: (node, parent) => ({
|
|
464
|
-
contents: tableContents(node, parent),
|
|
465
|
-
listingAttachment: node.attrs.listingAttachment || undefined,
|
|
466
|
-
}),
|
|
467
|
-
table_element: (node) => ({
|
|
468
|
-
containedObjectID: attributeOfNodeType(node, 'table', 'id'),
|
|
469
|
-
tableElementFooterID: attributeOfNodeType(node, 'table_element_footer', 'id') || undefined,
|
|
470
|
-
caption: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
|
|
471
|
-
title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
|
|
472
|
-
elementType: 'table',
|
|
473
|
-
listingID: attributeOfNodeType(node, 'listing', 'id') || undefined,
|
|
474
|
-
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
475
|
-
suppressCaption: Boolean(node.attrs.suppressCaption) || undefined,
|
|
476
|
-
suppressTitle: node.attrs.suppressTitle === undefined ||
|
|
477
|
-
node.attrs.suppressTitle === true
|
|
478
|
-
? undefined
|
|
479
|
-
: false,
|
|
480
|
-
suppressFooter: Boolean(node.attrs.suppressFooter) || undefined,
|
|
481
|
-
suppressHeader: Boolean(node.attrs.suppressHeader) || undefined,
|
|
482
|
-
tableStyle: node.attrs.tableStyle || undefined,
|
|
483
|
-
}),
|
|
484
|
-
toc_element: (node) => ({
|
|
485
|
-
contents: elementContents(node),
|
|
486
|
-
elementType: 'div',
|
|
487
|
-
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
488
|
-
}),
|
|
489
|
-
toc_section: (node, parent, path, priority) => ({
|
|
490
|
-
category: (0, section_category_1.buildSectionCategory)(node),
|
|
491
|
-
priority: priority.value++,
|
|
492
|
-
title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
|
|
493
|
-
path: path.concat([node.attrs.id]),
|
|
494
|
-
elementIDs: childElements(node)
|
|
495
|
-
.map((childNode) => childNode.attrs.id)
|
|
496
|
-
.filter((id) => id),
|
|
497
|
-
}),
|
|
498
|
-
affiliation: (node) => ({
|
|
499
|
-
institution: node.attrs.institution,
|
|
500
|
-
addressLine1: node.attrs.addressLine1,
|
|
501
|
-
addressLine2: node.attrs.addressLine2,
|
|
502
|
-
addressLine3: node.attrs.addressLine3,
|
|
503
|
-
department: node.attrs.department,
|
|
504
|
-
postCode: node.attrs.postCode,
|
|
505
|
-
country: node.attrs.country,
|
|
506
|
-
county: node.attrs.county,
|
|
507
|
-
city: node.attrs.city,
|
|
508
|
-
email: node.attrs.email,
|
|
509
|
-
priority: node.attrs.priority,
|
|
510
|
-
}),
|
|
511
|
-
contributor: (node) => ({
|
|
512
|
-
role: node.attrs.role,
|
|
513
|
-
affiliations: node.attrs.affiliations,
|
|
514
|
-
bibliographicName: node.attrs.bibliographicName,
|
|
515
|
-
userID: node.attrs.userID,
|
|
516
|
-
invitationID: node.attrs.invitationID,
|
|
517
|
-
isCorresponding: node.attrs.isCorresponding,
|
|
518
|
-
isJointContributor: node.attrs.isJointContributor,
|
|
519
|
-
ORCIDIdentifier: node.attrs.ORCIDIdentifier,
|
|
520
|
-
footnote: node.attrs.footnote,
|
|
521
|
-
corresp: node.attrs.corresp,
|
|
522
|
-
priority: node.attrs.priority,
|
|
523
|
-
}),
|
|
524
|
-
supplement: (node) => ({
|
|
525
|
-
href: node.attrs.href,
|
|
526
|
-
title: node.attrs.title,
|
|
527
|
-
MIME: node.attrs.mimeType && node.attrs.mimeSubType
|
|
528
|
-
? [node.attrs.mimeType, node.attrs.mimeSubType].join('/')
|
|
529
|
-
: '',
|
|
530
|
-
}),
|
|
531
|
-
corresp: (node) => ({
|
|
532
|
-
contents: (0, exports.inlineContents)(node),
|
|
533
|
-
label: node.attrs.label,
|
|
534
|
-
}),
|
|
535
|
-
};
|
|
536
|
-
const modelData = (node, parent, path, priority) => {
|
|
537
|
-
const encoder = encoders[node.type.name];
|
|
538
|
-
if (!encoder) {
|
|
539
|
-
throw new Error(`Unhandled model: ${node.type.name}`);
|
|
540
|
-
}
|
|
541
|
-
return encoder(node, parent, path, priority);
|
|
542
|
-
};
|
|
543
|
-
const modelFromNode = (node, parent, path, priority) => {
|
|
544
|
-
const objectType = node_types_1.nodeTypesMap.get(node.type);
|
|
545
|
-
if (!objectType) {
|
|
546
|
-
throw new Error(`No objectType is defined for ${node.type.name}`);
|
|
547
|
-
}
|
|
548
|
-
const { id } = node.attrs;
|
|
549
|
-
if (!id) {
|
|
550
|
-
throw new Error(`No id is defined for this ${node.type.name}`);
|
|
551
|
-
}
|
|
552
|
-
const data = Object.assign(Object.assign({}, modelData(node, parent, path, priority)), { _id: id, objectType: objectType });
|
|
553
|
-
const model = data;
|
|
554
|
-
const markers = (0, highlight_markers_1.extractCommentMarkers)(model);
|
|
555
|
-
return { model, markers };
|
|
556
|
-
};
|
|
557
|
-
exports.modelFromNode = modelFromNode;
|
|
558
|
-
const containerTypes = [
|
|
559
|
-
schema_1.schema.nodes.affiliations,
|
|
560
|
-
schema_1.schema.nodes.contributors,
|
|
561
|
-
schema_1.schema.nodes.affiliations,
|
|
562
|
-
schema_1.schema.nodes.keywords,
|
|
563
|
-
schema_1.schema.nodes.supplements,
|
|
564
|
-
schema_1.schema.nodes.abstracts,
|
|
565
|
-
schema_1.schema.nodes.body,
|
|
566
|
-
schema_1.schema.nodes.backmatter,
|
|
567
|
-
schema_1.schema.nodes.general_table_footnote,
|
|
568
|
-
];
|
|
569
|
-
const placeholderTypes = [
|
|
570
|
-
schema_1.schema.nodes.placeholder,
|
|
571
|
-
schema_1.schema.nodes.placeholder_element,
|
|
572
|
-
];
|
|
573
|
-
const encode = (node) => {
|
|
574
|
-
const models = new Map();
|
|
575
|
-
const priority = {
|
|
576
|
-
value: 1,
|
|
577
|
-
};
|
|
578
|
-
const processNode = (path, parent) => (child) => {
|
|
579
|
-
if (containerTypes.includes(child.type)) {
|
|
580
|
-
child.forEach(processNode([], child));
|
|
581
|
-
return;
|
|
582
|
-
}
|
|
583
|
-
if (!child.attrs.id) {
|
|
584
|
-
return;
|
|
585
|
-
}
|
|
586
|
-
if ((0, schema_1.isHighlightMarkerNode)(child)) {
|
|
587
|
-
return;
|
|
588
|
-
}
|
|
589
|
-
if (placeholderTypes.includes(child.type)) {
|
|
590
|
-
return;
|
|
591
|
-
}
|
|
592
|
-
if (parent.type === schema_1.schema.nodes.paragraph) {
|
|
593
|
-
return;
|
|
594
|
-
}
|
|
595
|
-
if (child.type === schema_1.schema.nodes.footnotes_element) {
|
|
596
|
-
addFootnotesOrderModel(child, models);
|
|
597
|
-
}
|
|
598
|
-
const { model, markers } = (0, exports.modelFromNode)(child, parent, path, priority);
|
|
599
|
-
markers.forEach((marker) => {
|
|
600
|
-
const comment = models.get(marker._id);
|
|
601
|
-
if (comment) {
|
|
602
|
-
comment.selector = {
|
|
603
|
-
from: marker.from,
|
|
604
|
-
to: marker.to,
|
|
605
|
-
};
|
|
606
|
-
}
|
|
607
|
-
});
|
|
608
|
-
if (models.has(model._id)) {
|
|
609
|
-
throw Error(`Duplicate ids in encode: ${model._id}`);
|
|
610
|
-
}
|
|
611
|
-
models.set(model._id, model);
|
|
612
|
-
child.forEach(processNode(path.concat(child.attrs.id), child));
|
|
613
|
-
};
|
|
614
|
-
const comments = node.lastChild;
|
|
615
|
-
if (comments && comments.type === schema_1.schema.nodes.comments) {
|
|
616
|
-
comments.forEach(processNode([], comments));
|
|
617
|
-
}
|
|
618
|
-
node.forEach(processNode([], node));
|
|
619
|
-
if ((0, schema_1.isManuscriptNode)(node)) {
|
|
620
|
-
builders_1.auxiliaryObjectTypes.forEach((t) => {
|
|
621
|
-
const order = generateElementOrder(node, t);
|
|
622
|
-
if (order) {
|
|
623
|
-
models.set(order._id, order);
|
|
624
|
-
}
|
|
625
|
-
});
|
|
626
|
-
}
|
|
627
|
-
return models;
|
|
628
|
-
};
|
|
629
|
-
exports.encode = encode;
|
|
630
|
-
const generateElementOrder = (node, nodeType) => {
|
|
631
|
-
const ids = [];
|
|
632
|
-
node.descendants((n) => {
|
|
633
|
-
if (n.type === nodeType) {
|
|
634
|
-
ids.push(n.attrs.id);
|
|
635
|
-
}
|
|
636
|
-
return true;
|
|
637
|
-
});
|
|
638
|
-
if (!ids.length) {
|
|
639
|
-
return undefined;
|
|
640
|
-
}
|
|
641
|
-
const type = node_types_1.nodeTypesMap.get(nodeType);
|
|
642
|
-
if (!type) {
|
|
643
|
-
return undefined;
|
|
644
|
-
}
|
|
645
|
-
const order = (0, builders_1.buildElementsOrder)(type);
|
|
646
|
-
order.elements = ids;
|
|
647
|
-
return order;
|
|
648
|
-
};
|
|
649
|
-
const addFootnotesOrderModel = (child, models) => {
|
|
650
|
-
const footnoteList = [];
|
|
651
|
-
child.forEach((footnote, _, index) => footnoteList.push({ id: footnote.attrs.id, index }));
|
|
652
|
-
const footnotesOrder = (0, builders_1.buildFootnotesOrder)(footnoteList, child.attrs.id);
|
|
653
|
-
models.set(footnotesOrder._id, footnotesOrder);
|
|
654
|
-
};
|