@manuscripts/transform 2.3.36 → 2.3.37-LEAN-3911.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/jats/importer/create-article-node.js +31 -0
- package/dist/cjs/jats/importer/index.js +3 -3
- package/dist/cjs/jats/importer/jats-body-transformations.js +70 -0
- package/dist/cjs/jats/importer/jats-comments.js +27 -104
- package/dist/cjs/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +229 -9
- package/dist/cjs/jats/importer/jats-front-transformations.js +262 -0
- package/dist/cjs/jats/importer/jats-journal-meta-parser.js +8 -1
- package/dist/cjs/jats/importer/jats-parser-utils.js +39 -5
- package/dist/cjs/jats/importer/jats-reference-parser.js +16 -27
- package/dist/cjs/jats/importer/jats-references.js +18 -18
- package/dist/cjs/jats/importer/parse-jats-article.js +42 -78
- package/dist/cjs/jats/index.js +4 -3
- package/dist/cjs/jats/jats-exporter.js +251 -354
- package/dist/cjs/{transformer → jats}/labels.js +3 -3
- package/dist/cjs/lib/utils.js +9 -1
- package/dist/cjs/transformer/id.js +10 -5
- package/dist/cjs/transformer/index.js +0 -18
- package/dist/cjs/version.js +1 -1
- package/dist/{cjs/transformer/serializer.js → es/jats/importer/create-article-node.js} +12 -8
- package/dist/es/jats/importer/index.js +2 -1
- package/dist/es/jats/importer/jats-body-transformations.js +70 -0
- package/dist/es/jats/importer/jats-comments.js +26 -101
- package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +230 -10
- package/dist/es/jats/importer/jats-front-transformations.js +259 -0
- package/dist/es/jats/importer/jats-journal-meta-parser.js +6 -0
- package/dist/es/jats/importer/jats-parser-utils.js +40 -6
- package/dist/es/jats/importer/jats-reference-parser.js +16 -27
- package/dist/es/jats/importer/jats-references.js +18 -18
- package/dist/es/jats/importer/parse-jats-article.js +43 -77
- package/dist/es/jats/index.js +3 -1
- package/dist/es/jats/jats-exporter.js +253 -356
- package/dist/es/{transformer → jats}/labels.js +3 -3
- package/dist/es/lib/utils.js +7 -0
- package/dist/es/transformer/id.js +8 -3
- package/dist/es/transformer/index.js +0 -16
- package/dist/es/version.js +1 -1
- package/dist/{cjs/transformer/models.js → types/jats/importer/create-article-node.d.ts} +3 -3
- package/dist/types/jats/importer/index.d.ts +2 -1
- package/dist/types/jats/importer/jats-body-transformations.d.ts +5 -0
- package/dist/types/jats/importer/jats-comments.d.ts +4 -10
- package/dist/types/jats/importer/{jats-body-dom-parser.d.ts → jats-dom-parser.d.ts} +1 -1
- package/dist/types/jats/importer/jats-front-transformations.d.ts +38 -0
- package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +10 -0
- package/dist/types/jats/importer/jats-references.d.ts +19 -8
- package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
- package/dist/types/jats/index.d.ts +3 -1
- package/dist/types/jats/jats-exporter.d.ts +10 -29
- package/dist/types/{transformer → jats}/labels.d.ts +2 -1
- package/dist/types/lib/utils.d.ts +3 -0
- package/dist/types/schema/nodes/bibliography_item.d.ts +28 -5
- package/dist/types/schema/nodes/contributor.d.ts +10 -0
- package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
- package/dist/types/transformer/id.d.ts +5 -2
- package/dist/types/transformer/index.d.ts +0 -16
- package/dist/types/version.d.ts +1 -1
- package/package.json +3 -2
- package/dist/cjs/__tests__/data/project-dump.json +0 -825
- package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
- 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 -874
- package/dist/cjs/transformer/document-object-types.js +0 -31
- package/dist/cjs/transformer/encode.js +0 -664
- package/dist/cjs/transformer/footnote-category.js +0 -20
- 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 -400
- package/dist/cjs/transformer/manuscript-dependencies.js +0 -21
- package/dist/cjs/transformer/model-map.js +0 -26
- package/dist/cjs/transformer/object-types.js +0 -57
- package/dist/cjs/transformer/project-bundle.js +0 -94
- package/dist/cjs/transformer/update-identifiers.js +0 -93
- package/dist/es/__tests__/data/project-dump.json +0 -825
- package/dist/es/jats/importer/jats-front-parser.js +0 -315
- package/dist/es/transformer/__tests__/__helpers__/doc.js +0 -29
- package/dist/es/transformer/builders.js +0 -186
- package/dist/es/transformer/decode.js +0 -864
- package/dist/es/transformer/document-object-types.js +0 -28
- package/dist/es/transformer/encode.js +0 -654
- package/dist/es/transformer/footnote-category.js +0 -16
- 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 -393
- package/dist/es/transformer/manuscript-dependencies.js +0 -17
- package/dist/es/transformer/model-map.js +0 -22
- package/dist/es/transformer/models.js +0 -16
- 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/update-identifiers.js +0 -87
- package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
- 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 -51
- package/dist/types/transformer/document-object-types.d.ts +0 -17
- package/dist/types/transformer/encode.d.ts +0 -29
- package/dist/types/transformer/footnote-category.d.ts +0 -17
- package/dist/types/transformer/footnotes-order.d.ts +0 -22
- 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/cjs/{transformer → jats}/filename.js +0 -0
- /package/dist/cjs/{transformer → jats}/timestamp.js +0 -0
- /package/dist/es/{transformer → jats}/filename.js +0 -0
- /package/dist/es/{transformer → jats}/timestamp.js +0 -0
- /package/dist/types/{transformer → jats}/filename.d.ts +0 -0
- /package/dist/types/{transformer → jats}/timestamp.d.ts +0 -0
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.buildTargets = void 0;
|
|
19
19
|
const schema_1 = require("../schema");
|
|
20
|
-
const node_names_1 = require("
|
|
20
|
+
const node_names_1 = require("../transformer/node-names");
|
|
21
21
|
const labelledNodeTypes = [
|
|
22
22
|
schema_1.schema.nodes.figure_element,
|
|
23
23
|
schema_1.schema.nodes.table_element,
|
|
@@ -28,7 +28,7 @@ const excludedTypes = [schema_1.schema.nodes.graphical_abstract_section];
|
|
|
28
28
|
const chooseLabel = (nodeType) => {
|
|
29
29
|
return node_names_1.nodeNames.get(nodeType);
|
|
30
30
|
};
|
|
31
|
-
const buildTargets = (
|
|
31
|
+
const buildTargets = (node) => {
|
|
32
32
|
const counters = {};
|
|
33
33
|
for (const nodeType of labelledNodeTypes) {
|
|
34
34
|
counters[nodeType.name] = {
|
|
@@ -42,7 +42,7 @@ const buildTargets = (fragment) => {
|
|
|
42
42
|
return `${counter.label} ${counter.index}`;
|
|
43
43
|
};
|
|
44
44
|
const targets = new Map();
|
|
45
|
-
|
|
45
|
+
node.descendants((node, pos, parent) => {
|
|
46
46
|
var _a;
|
|
47
47
|
if (node.type.name in counters) {
|
|
48
48
|
if (parent && excludedTypes.includes(parent.type)) {
|
package/dist/cjs/lib/utils.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.getTrimmedTextContent = exports.findParentNodeClosestToPos = exports.isInBibliographySection = exports.isInGraphicalAbstractSection = exports.findNodePositions = exports.iterateChildren = void 0;
|
|
18
|
+
exports.setElementAttributes = exports.getTrimmedTextContent = exports.findParentNodeClosestToPos = exports.isInBibliographySection = exports.isInGraphicalAbstractSection = exports.findNodePositions = exports.iterateChildren = void 0;
|
|
19
19
|
const bibliography_section_1 = require("../schema/nodes/bibliography_section");
|
|
20
20
|
const graphical_abstract_section_1 = require("../schema/nodes/graphical_abstract_section");
|
|
21
21
|
function* iterateChildren(node, recurse = false) {
|
|
@@ -83,3 +83,11 @@ const getTrimmedTextContent = (node, querySelector) => {
|
|
|
83
83
|
return (_b = (_a = node.querySelector(querySelector)) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim();
|
|
84
84
|
};
|
|
85
85
|
exports.getTrimmedTextContent = getTrimmedTextContent;
|
|
86
|
+
const setElementAttributes = (element, attributes) => {
|
|
87
|
+
Object.entries(attributes).forEach(([key, value]) => {
|
|
88
|
+
if (value) {
|
|
89
|
+
element.setAttribute(key, value);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
exports.setElementAttributes = setElementAttributes;
|
|
@@ -15,14 +15,19 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.generateID = exports.
|
|
18
|
+
exports.generateNodeID = exports.generateID = exports.ExtraObjectTypes = void 0;
|
|
19
19
|
const uuid_1 = require("uuid");
|
|
20
20
|
const node_types_1 = require("./node-types");
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
var ExtraObjectTypes;
|
|
22
|
+
(function (ExtraObjectTypes) {
|
|
23
|
+
ExtraObjectTypes["PlaceholderElement"] = "MPPlaceholderElement";
|
|
24
|
+
ExtraObjectTypes["GeneralTableFootnote"] = "MPGeneralTableFootnote";
|
|
25
|
+
})(ExtraObjectTypes = exports.ExtraObjectTypes || (exports.ExtraObjectTypes = {}));
|
|
25
26
|
const generateID = (objectType) => {
|
|
26
27
|
return objectType + ':' + (0, uuid_1.v4)().toUpperCase();
|
|
27
28
|
};
|
|
28
29
|
exports.generateID = generateID;
|
|
30
|
+
const generateNodeID = (type) => {
|
|
31
|
+
return node_types_1.nodeTypesMap.get(type) + ':' + (0, uuid_1.v4)().toUpperCase();
|
|
32
|
+
};
|
|
33
|
+
exports.generateNodeID = generateNodeID;
|
|
@@ -29,26 +29,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
29
29
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
30
30
|
};
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.createTestDoc = void 0;
|
|
33
|
-
__exportStar(require("./builders"), exports);
|
|
34
|
-
__exportStar(require("./decode"), exports);
|
|
35
|
-
__exportStar(require("./document-object-types"), exports);
|
|
36
|
-
__exportStar(require("./encode"), exports);
|
|
37
|
-
__exportStar(require("./filename"), exports);
|
|
38
|
-
__exportStar(require("./highlight-markers"), exports);
|
|
39
|
-
__exportStar(require("./html"), exports);
|
|
40
32
|
__exportStar(require("./id"), exports);
|
|
41
|
-
__exportStar(require("./labels"), exports);
|
|
42
|
-
__exportStar(require("./manuscript-dependencies"), exports);
|
|
43
|
-
__exportStar(require("./models"), exports);
|
|
44
33
|
__exportStar(require("./node-names"), exports);
|
|
45
34
|
__exportStar(require("./node-title"), exports);
|
|
46
35
|
__exportStar(require("./node-types"), exports);
|
|
47
|
-
__exportStar(require("./object-types"), exports);
|
|
48
|
-
__exportStar(require("./project-bundle"), exports);
|
|
49
36
|
__exportStar(require("./section-category"), exports);
|
|
50
|
-
__exportStar(require("./serializer"), exports);
|
|
51
|
-
__exportStar(require("./timestamp"), exports);
|
|
52
|
-
__exportStar(require("./update-identifiers"), exports);
|
|
53
|
-
var doc_1 = require("./__tests__/__helpers__/doc");
|
|
54
|
-
Object.defineProperty(exports, "createTestDoc", { enumerable: true, get: function () { return doc_1.createTestDoc; } });
|
package/dist/cjs/version.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*!
|
|
3
|
-
* ©
|
|
2
|
+
* © 2024 Atypon Systems LLC
|
|
4
3
|
*
|
|
5
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
5
|
* you may not use this file except in compliance with the License.
|
|
@@ -14,10 +13,15 @@
|
|
|
14
13
|
* See the License for the specific language governing permissions and
|
|
15
14
|
* limitations under the License.
|
|
16
15
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
import { schema } from '../../schema';
|
|
17
|
+
import { defaultTitle } from './jats-front-transformations';
|
|
18
|
+
export const createArticleNode = (manuscript) => {
|
|
19
|
+
const title = schema.nodes.title.createChecked({}, schema.text(defaultTitle));
|
|
20
|
+
return schema.nodes.manuscript.createAndFill({
|
|
21
|
+
id: manuscript._id,
|
|
22
|
+
doi: manuscript.DOI,
|
|
23
|
+
articleType: manuscript.articleType,
|
|
24
|
+
prototype: manuscript.prototype,
|
|
25
|
+
primaryLanguageCode: manuscript.primaryLanguageCode,
|
|
26
|
+
}, title);
|
|
19
27
|
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.xmlSerializer = void 0;
|
|
22
|
-
const w3c_xmlserializer_1 = __importDefault(require("w3c-xmlserializer"));
|
|
23
|
-
exports.xmlSerializer = { serializeToString: w3c_xmlserializer_1.default };
|
|
@@ -13,4 +13,5 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export {
|
|
16
|
+
export { createArticleNode } from './create-article-node';
|
|
17
|
+
export { parseJATSArticle } from './parse-jats-article';
|
|
@@ -299,4 +299,74 @@ export const jatsBodyTransformations = {
|
|
|
299
299
|
body.prepend(section);
|
|
300
300
|
}
|
|
301
301
|
},
|
|
302
|
+
moveReferencesToBackmatter(body, references, createElement) {
|
|
303
|
+
const backmatter = body.querySelector('sec[sec-type="backmatter"]');
|
|
304
|
+
if (!references || !references.items.size || !backmatter) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
const bibliographySection = this.createBibliographySection(createElement);
|
|
308
|
+
const bibliographyElement = createElement('bibliography-element');
|
|
309
|
+
references.getBibliographyItems().forEach((item) => {
|
|
310
|
+
const bibliographyItem = this.createBibliographyItem(item, createElement);
|
|
311
|
+
bibliographyElement.appendChild(bibliographyItem);
|
|
312
|
+
});
|
|
313
|
+
bibliographySection.appendChild(bibliographyElement);
|
|
314
|
+
backmatter.appendChild(bibliographySection);
|
|
315
|
+
},
|
|
316
|
+
createBibliographySection(createElement) {
|
|
317
|
+
const section = createElement('sec');
|
|
318
|
+
section.setAttribute('sec-type', 'bibliography_section');
|
|
319
|
+
const title = createElement('title');
|
|
320
|
+
title.textContent = 'References';
|
|
321
|
+
section.appendChild(title);
|
|
322
|
+
return section;
|
|
323
|
+
},
|
|
324
|
+
createBibliographyItem(item, createElement) {
|
|
325
|
+
var _a, _b, _c;
|
|
326
|
+
const bibliographyItem = createElement('bibliography-item');
|
|
327
|
+
bibliographyItem.setAttribute('id', item.id);
|
|
328
|
+
bibliographyItem.setAttribute('type', item.type);
|
|
329
|
+
(_a = item.author) === null || _a === void 0 ? void 0 : _a.forEach((author) => {
|
|
330
|
+
const authorElement = createElement('author');
|
|
331
|
+
authorElement.setAttribute('id', author._id);
|
|
332
|
+
authorElement.setAttribute('family', author.family || '');
|
|
333
|
+
authorElement.setAttribute('given', author.given || '');
|
|
334
|
+
bibliographyItem.appendChild(authorElement);
|
|
335
|
+
});
|
|
336
|
+
if (item.issued) {
|
|
337
|
+
const issuedEl = createElement('issued');
|
|
338
|
+
issuedEl.setAttribute('id', ((_b = item.issued) === null || _b === void 0 ? void 0 : _b._id) || '');
|
|
339
|
+
const dateParts = item.issued['date-parts'];
|
|
340
|
+
const year = (_c = dateParts === null || dateParts === void 0 ? void 0 : dateParts[0]) === null || _c === void 0 ? void 0 : _c[0];
|
|
341
|
+
if (year) {
|
|
342
|
+
issuedEl.setAttribute('year', year.toString());
|
|
343
|
+
}
|
|
344
|
+
bibliographyItem.appendChild(issuedEl);
|
|
345
|
+
}
|
|
346
|
+
if (item.containerTitle) {
|
|
347
|
+
bibliographyItem.setAttribute('containerTitle', item.containerTitle);
|
|
348
|
+
}
|
|
349
|
+
if (item.volume) {
|
|
350
|
+
bibliographyItem.setAttribute('volume', item.volume.toString());
|
|
351
|
+
}
|
|
352
|
+
if (item.issue) {
|
|
353
|
+
bibliographyItem.setAttribute('issue', item.issue.toString());
|
|
354
|
+
}
|
|
355
|
+
if (item.supplement) {
|
|
356
|
+
bibliographyItem.setAttribute('supplement', item.supplement);
|
|
357
|
+
}
|
|
358
|
+
if (item.page) {
|
|
359
|
+
bibliographyItem.setAttribute('page', item.page.toString());
|
|
360
|
+
}
|
|
361
|
+
if (item.title) {
|
|
362
|
+
bibliographyItem.setAttribute('title', item.title);
|
|
363
|
+
}
|
|
364
|
+
if (item.literal) {
|
|
365
|
+
bibliographyItem.setAttribute('literal', item.literal);
|
|
366
|
+
}
|
|
367
|
+
if (item.doi) {
|
|
368
|
+
bibliographyItem.setAttribute('DOI', item.doi);
|
|
369
|
+
}
|
|
370
|
+
return bibliographyItem;
|
|
371
|
+
},
|
|
302
372
|
};
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
const DEFAULT_PROFILE_ID = 'MPUserProfile:0000000000000000000000000000000000000001';
|
|
16
|
+
import { ObjectTypes } from '@manuscripts/json-schema';
|
|
17
|
+
import { generateID } from '../../transformer';
|
|
18
|
+
export const DEFAULT_PROFILE_ID = 'MPUserProfile:0000000000000000000000000000000000000001';
|
|
19
19
|
export const isJATSComment = (node) => {
|
|
20
20
|
return (node.nodeType === node.PROCESSING_INSTRUCTION_NODE &&
|
|
21
21
|
node.nodeName === 'AuthorQuery');
|
|
@@ -23,34 +23,33 @@ export const isJATSComment = (node) => {
|
|
|
23
23
|
export const parseJATSComment = (node) => {
|
|
24
24
|
const text = node.textContent;
|
|
25
25
|
if (text) {
|
|
26
|
-
const id = /id="(.+)"/.exec(text);
|
|
27
26
|
const queryText = /queryText="(.+)"/.exec(text);
|
|
28
|
-
if (
|
|
27
|
+
if (queryText) {
|
|
28
|
+
const parentNode = node.parentNode;
|
|
29
|
+
const index = parentNode.outerHTML.indexOf(queryText[1]);
|
|
29
30
|
return {
|
|
30
|
-
id:
|
|
31
|
+
id: generateID(ObjectTypes.CommentAnnotation),
|
|
31
32
|
text: queryText[1],
|
|
33
|
+
index,
|
|
32
34
|
};
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
};
|
|
36
38
|
export const markComments = (doc) => {
|
|
37
|
-
|
|
39
|
+
var _a;
|
|
38
40
|
const root = doc.getRootNode();
|
|
39
41
|
const queue = [root];
|
|
42
|
+
const commentsElement = doc.createElement('comments-annotations');
|
|
40
43
|
while (queue.length !== 0) {
|
|
41
44
|
const node = queue.shift();
|
|
42
45
|
if (node) {
|
|
43
46
|
if (isJATSComment(node)) {
|
|
44
47
|
const comment = parseJATSComment(node);
|
|
45
48
|
if (comment) {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
comment,
|
|
51
|
-
};
|
|
52
|
-
marks.push(mark);
|
|
53
|
-
}
|
|
49
|
+
const highlightMarker = createHighlightMarkerElement(doc, comment.id);
|
|
50
|
+
(_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(highlightMarker, node);
|
|
51
|
+
const commentElement = createCommentElement(doc, comment);
|
|
52
|
+
commentsElement.appendChild(commentElement);
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
node.childNodes.forEach((child) => {
|
|
@@ -58,93 +57,19 @@ export const markComments = (doc) => {
|
|
|
58
57
|
});
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const addMark = (doc, node) => {
|
|
64
|
-
const parent = node.parentElement;
|
|
65
|
-
if (parent) {
|
|
66
|
-
const token = uuidv4();
|
|
67
|
-
const tokenNode = doc.createTextNode(token);
|
|
68
|
-
parent.insertBefore(tokenNode, node);
|
|
69
|
-
return token;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
export const createComments = (models, marks) => {
|
|
73
|
-
const comments = [];
|
|
74
|
-
for (const model of models) {
|
|
75
|
-
if (isHighlightableModel(model)) {
|
|
76
|
-
comments.push(...processModel(model, marks));
|
|
77
|
-
}
|
|
78
|
-
else if (isKeyword(model)) {
|
|
79
|
-
comments.push(...processKeyword(model, marks));
|
|
80
|
-
}
|
|
60
|
+
if (commentsElement.hasChildNodes()) {
|
|
61
|
+
doc.documentElement.appendChild(commentsElement);
|
|
81
62
|
}
|
|
82
|
-
return comments;
|
|
83
|
-
};
|
|
84
|
-
const getFieldMarks = (content, marks) => {
|
|
85
|
-
return marks
|
|
86
|
-
.filter((m) => content.indexOf(m.token) >= 0)
|
|
87
|
-
.sort((a, b) => content.indexOf(a.token) - content.indexOf(b.token));
|
|
88
63
|
};
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
const results = processContent(model, content, getFieldMarks(content, marks));
|
|
97
|
-
model[field] = results.content;
|
|
98
|
-
comments.push(...results.comments);
|
|
99
|
-
}
|
|
100
|
-
return comments;
|
|
64
|
+
const createHighlightMarkerElement = (doc, id) => {
|
|
65
|
+
const highlightMarker = doc.createElement('highlight-marker');
|
|
66
|
+
highlightMarker.setAttribute('id', id);
|
|
67
|
+
highlightMarker.setAttribute('position', 'point');
|
|
68
|
+
return highlightMarker;
|
|
101
69
|
};
|
|
102
|
-
const
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
content = name.replace(mark.token, '');
|
|
108
|
-
const target = model.containedGroup;
|
|
109
|
-
if (!target) {
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
const contributions = [buildContribution(DEFAULT_PROFILE_ID)];
|
|
113
|
-
const comment = buildComment(target, mark.comment.text, undefined, contributions);
|
|
114
|
-
model.name = content;
|
|
115
|
-
comments.push(comment);
|
|
116
|
-
}
|
|
117
|
-
return comments;
|
|
118
|
-
};
|
|
119
|
-
const processContent = (model, content, marks) => {
|
|
120
|
-
const comments = [];
|
|
121
|
-
let result = content;
|
|
122
|
-
for (const mark of marks) {
|
|
123
|
-
const token = mark.token;
|
|
124
|
-
const index = result.indexOf(token);
|
|
125
|
-
result = result.replace(token, '');
|
|
126
|
-
const contributions = [buildContribution(DEFAULT_PROFILE_ID)];
|
|
127
|
-
const selector = {
|
|
128
|
-
from: index,
|
|
129
|
-
to: index,
|
|
130
|
-
};
|
|
131
|
-
const comment = buildComment(model._id, mark.comment.text, selector, contributions);
|
|
132
|
-
comments.push(comment);
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
content: result,
|
|
136
|
-
comments,
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
export const createReferenceComments = (references) => {
|
|
140
|
-
const comments = [];
|
|
141
|
-
for (const item of references.getBibliographyItems()) {
|
|
142
|
-
const id = item._id;
|
|
143
|
-
for (const comment of references.getComments(id)) {
|
|
144
|
-
const contributions = [buildContribution(DEFAULT_PROFILE_ID)];
|
|
145
|
-
const c = buildComment(id, comment.text, undefined, contributions);
|
|
146
|
-
comments.push(c);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return comments;
|
|
70
|
+
const createCommentElement = (doc, comment) => {
|
|
71
|
+
const commentElement = doc.createElement('comment-annotation');
|
|
72
|
+
commentElement.setAttribute('id', comment.id);
|
|
73
|
+
commentElement.textContent = comment.text;
|
|
74
|
+
return commentElement;
|
|
150
75
|
};
|