@manuscripts/transform 1.5.8 → 2.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 +1 -1
- package/dist/cjs/jats/importer/index.js +1 -3
- package/dist/cjs/jats/importer/jats-body-dom-parser.js +23 -227
- package/dist/cjs/jats/importer/jats-body-transformations.js +110 -201
- package/dist/cjs/jats/importer/jats-comments.js +100 -98
- package/dist/cjs/jats/importer/jats-front-parser.js +87 -81
- package/dist/cjs/jats/importer/jats-journal-meta-parser.js +51 -39
- package/dist/cjs/jats/importer/jats-parser-utils.js +17 -56
- package/dist/cjs/jats/importer/jats-reference-parser.js +24 -79
- package/dist/cjs/jats/importer/jats-references.js +34 -0
- package/dist/cjs/jats/importer/parse-jats-article.js +67 -173
- package/dist/cjs/jats/index.js +1 -3
- package/dist/cjs/jats/jats-exporter.js +34 -55
- package/dist/cjs/lib/section-group-type.js +30 -0
- package/dist/cjs/lib/utils.js +1 -25
- package/dist/cjs/schema/index.js +20 -17
- package/dist/cjs/schema/nodes/abstracts.js +27 -0
- package/dist/cjs/schema/nodes/affiliations.js +27 -0
- package/dist/cjs/schema/nodes/backmatter.js +27 -0
- package/dist/cjs/schema/nodes/body.js +27 -0
- package/dist/cjs/schema/nodes/citation.js +10 -15
- package/dist/cjs/schema/nodes/{comment_list.js → comments.js} +4 -4
- package/dist/cjs/schema/nodes/contributors.js +27 -0
- package/dist/cjs/schema/nodes/{meta_section.js → core_section.js} +6 -5
- package/dist/cjs/schema/nodes/cross_reference.js +4 -3
- package/dist/cjs/schema/nodes/inline_footnote.js +6 -5
- package/dist/cjs/schema/nodes/keyword.js +0 -1
- package/dist/cjs/schema/nodes/{keywords_group.js → keyword_group.js} +6 -6
- package/dist/cjs/schema/nodes/{keywords_section.js → keywords.js} +7 -7
- package/dist/cjs/schema/nodes/keywords_element.js +1 -1
- package/dist/cjs/schema/nodes/manuscript.js +5 -2
- package/dist/cjs/transformer/builders.js +9 -86
- package/dist/cjs/transformer/decode.js +147 -176
- package/dist/cjs/transformer/encode.js +66 -67
- package/dist/cjs/transformer/highlight-markers.js +48 -36
- package/dist/cjs/transformer/html.js +7 -23
- package/dist/cjs/transformer/labels.js +3 -17
- package/dist/cjs/transformer/node-names.js +1 -1
- package/dist/cjs/transformer/node-title.js +1 -1
- package/dist/cjs/transformer/node-types.js +7 -6
- package/dist/cjs/transformer/object-types.js +1 -2
- package/dist/cjs/transformer/section-category.js +31 -31
- package/dist/es/index.js +1 -1
- package/dist/es/jats/importer/index.js +1 -1
- package/dist/es/jats/importer/jats-body-dom-parser.js +23 -227
- package/dist/es/jats/importer/jats-body-transformations.js +111 -202
- package/dist/es/jats/importer/jats-comments.js +97 -96
- package/dist/es/jats/importer/jats-front-parser.js +88 -82
- package/dist/es/jats/importer/jats-journal-meta-parser.js +51 -39
- package/dist/es/jats/importer/jats-parser-utils.js +16 -54
- package/dist/es/jats/importer/jats-reference-parser.js +27 -82
- package/dist/es/jats/importer/jats-references.js +30 -0
- package/dist/es/jats/importer/parse-jats-article.js +70 -174
- package/dist/es/jats/index.js +1 -1
- package/dist/es/jats/jats-exporter.js +34 -55
- package/dist/es/lib/section-group-type.js +27 -0
- package/dist/es/lib/utils.js +0 -22
- package/dist/es/schema/index.js +21 -18
- package/dist/es/schema/nodes/abstracts.js +24 -0
- package/dist/es/schema/nodes/affiliations.js +24 -0
- package/dist/es/schema/nodes/backmatter.js +24 -0
- package/dist/es/schema/nodes/body.js +24 -0
- package/dist/es/schema/nodes/citation.js +10 -15
- package/dist/es/schema/nodes/{comment_list.js → comments.js} +3 -3
- package/dist/es/schema/nodes/contributors.js +24 -0
- package/dist/es/schema/nodes/{meta_section.js → core_section.js} +5 -4
- package/dist/es/schema/nodes/cross_reference.js +4 -3
- package/dist/es/schema/nodes/inline_footnote.js +6 -5
- package/dist/es/schema/nodes/keyword.js +0 -1
- package/dist/es/schema/nodes/{keywords_group.js → keyword_group.js} +4 -4
- package/dist/es/schema/nodes/{keywords_section.js → keywords.js} +5 -5
- package/dist/es/schema/nodes/keywords_element.js +1 -1
- package/dist/es/schema/nodes/manuscript.js +3 -1
- package/dist/es/transformer/builders.js +6 -73
- package/dist/es/transformer/decode.js +147 -175
- package/dist/es/transformer/encode.js +70 -71
- package/dist/es/transformer/highlight-markers.js +44 -32
- package/dist/es/transformer/html.js +7 -23
- package/dist/es/transformer/labels.js +3 -17
- package/dist/es/transformer/node-names.js +1 -1
- package/dist/es/transformer/node-title.js +1 -1
- package/dist/es/transformer/node-types.js +7 -6
- package/dist/es/transformer/object-types.js +0 -1
- package/dist/es/transformer/section-category.js +29 -29
- package/dist/types/index.d.ts +1 -1
- package/dist/types/jats/importer/index.d.ts +1 -1
- package/dist/types/jats/importer/jats-body-transformations.d.ts +16 -19
- package/dist/types/jats/importer/jats-comments.d.ts +13 -9
- package/dist/types/jats/importer/jats-front-parser.d.ts +35 -12
- package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +4 -4
- package/dist/types/jats/importer/jats-parser-utils.d.ts +1 -6
- package/dist/types/jats/importer/jats-reference-parser.d.ts +2 -6
- package/dist/types/jats/importer/jats-references.d.ts +12 -0
- package/dist/types/jats/importer/parse-jats-article.d.ts +5 -17
- package/dist/types/jats/index.d.ts +1 -1
- package/dist/types/lib/section-group-type.d.ts +23 -0
- package/dist/types/lib/utils.d.ts +1 -4
- package/dist/types/schema/index.d.ts +4 -5
- package/dist/types/schema/nodes/{meta_section.d.ts → abstracts.d.ts} +1 -9
- package/dist/types/schema/nodes/affiliations.d.ts +17 -0
- package/dist/types/schema/nodes/backmatter.d.ts +17 -0
- package/dist/types/schema/nodes/body.d.ts +17 -0
- package/dist/types/schema/nodes/citation.d.ts +3 -5
- package/dist/types/schema/nodes/comments.d.ts +17 -0
- package/dist/types/schema/nodes/contributors.d.ts +17 -0
- package/dist/types/schema/nodes/core_section.d.ts +17 -0
- package/dist/types/schema/nodes/cross_reference.d.ts +1 -1
- package/dist/types/schema/nodes/inline_footnote.d.ts +1 -1
- package/dist/types/schema/nodes/keyword.d.ts +0 -1
- package/dist/types/schema/nodes/{contributors_element.d.ts → keyword_group.d.ts} +3 -4
- package/dist/types/schema/nodes/{comment_list.d.ts → keywords.d.ts} +3 -2
- package/dist/types/schema/nodes/manuscript.d.ts +1 -0
- package/dist/types/schema/types.d.ts +1 -1
- package/dist/types/transformer/builders.d.ts +2 -14
- package/dist/types/transformer/decode.d.ts +5 -9
- package/dist/types/transformer/encode.d.ts +4 -4
- package/dist/types/transformer/highlight-markers.d.ts +7 -2
- package/dist/types/transformer/object-types.d.ts +1 -2
- package/dist/types/transformer/section-category.d.ts +4 -3
- package/package.json +1 -6
- package/dist/cjs/lib/core-section-categories.js +0 -29
- package/dist/cjs/schema/nodes/affiliations_section.js +0 -36
- package/dist/cjs/schema/nodes/contributors_element.js +0 -49
- package/dist/cjs/schema/nodes/contributors_section.js +0 -36
- package/dist/es/lib/core-section-categories.js +0 -26
- package/dist/es/schema/nodes/affiliations_section.js +0 -32
- package/dist/es/schema/nodes/contributors_element.js +0 -46
- package/dist/es/schema/nodes/contributors_section.js +0 -32
- package/dist/types/lib/core-section-categories.d.ts +0 -8
- package/dist/types/schema/nodes/affiliations_section.d.ts +0 -11
- package/dist/types/schema/nodes/contributors_section.d.ts +0 -12
- package/dist/types/schema/nodes/keywords_group.d.ts +0 -26
- package/dist/types/schema/nodes/keywords_section.d.ts +0 -26
|
@@ -15,11 +15,10 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { DOMSerializer } from 'prosemirror-model';
|
|
17
17
|
import serializeToXML from 'w3c-xmlserializer';
|
|
18
|
-
import { iterateChildren
|
|
19
|
-
import { hasGroup, isHighlightMarkerNode, isSectionNode, schema, } from '../schema';
|
|
20
|
-
import { buildAttribution } from './builders';
|
|
21
|
-
import {
|
|
22
|
-
import { generateID } from './id';
|
|
18
|
+
import { iterateChildren } from '../lib/utils';
|
|
19
|
+
import { hasGroup, isHighlightMarkerNode, isManuscriptNode, isSectionNode, schema, } from '../schema';
|
|
20
|
+
import { auxiliaryObjectTypes, buildAttribution, buildElementsOrder, } from './builders';
|
|
21
|
+
import { extractCommentMarkers } from './highlight-markers';
|
|
23
22
|
import { nodeTypesMap } from './node-types';
|
|
24
23
|
import { buildSectionCategory } from './section-category';
|
|
25
24
|
const serializer = DOMSerializer.fromSchema(schema);
|
|
@@ -421,34 +420,9 @@ const encoders = {
|
|
|
421
420
|
elementType: 'div',
|
|
422
421
|
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
423
422
|
}),
|
|
424
|
-
|
|
423
|
+
keyword_group: (node) => ({
|
|
425
424
|
type: node.attrs.type,
|
|
426
425
|
}),
|
|
427
|
-
keywords_section: (node, parent, path, priority) => ({
|
|
428
|
-
category: buildSectionCategory(node),
|
|
429
|
-
priority: priority.value++,
|
|
430
|
-
title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
|
|
431
|
-
path: path.concat([node.attrs.id]),
|
|
432
|
-
elementIDs: childElements(node)
|
|
433
|
-
.map((childNode) => childNode.attrs.id)
|
|
434
|
-
.filter((id) => id),
|
|
435
|
-
}),
|
|
436
|
-
affiliations_section: (node, parent, path, priority) => ({
|
|
437
|
-
category: buildSectionCategory(node),
|
|
438
|
-
priority: priority.value++,
|
|
439
|
-
path: path.concat([node.attrs.id]),
|
|
440
|
-
elementIDs: childElements(node)
|
|
441
|
-
.map((childNode) => childNode.attrs.id)
|
|
442
|
-
.filter((id) => id),
|
|
443
|
-
}),
|
|
444
|
-
contributors_section: (node, parent, path, priority) => ({
|
|
445
|
-
category: buildSectionCategory(node),
|
|
446
|
-
priority: priority.value++,
|
|
447
|
-
path: path.concat([node.attrs.id]),
|
|
448
|
-
elementIDs: childElements(node)
|
|
449
|
-
.map((childNode) => childNode.attrs.id)
|
|
450
|
-
.filter((id) => id),
|
|
451
|
-
}),
|
|
452
426
|
missing_figure: (node) => ({
|
|
453
427
|
position: node.attrs.position || undefined,
|
|
454
428
|
}),
|
|
@@ -552,7 +526,6 @@ const modelData = (node, parent, path, priority) => {
|
|
|
552
526
|
return encoder(node, parent, path, priority);
|
|
553
527
|
};
|
|
554
528
|
export const modelFromNode = (node, parent, path, priority) => {
|
|
555
|
-
const commentAnnotationsMap = new Map();
|
|
556
529
|
const objectType = nodeTypesMap.get(node.type);
|
|
557
530
|
if (!objectType) {
|
|
558
531
|
throw new Error(`No objectType is defined for ${node.type.name}`);
|
|
@@ -563,66 +536,92 @@ export const modelFromNode = (node, parent, path, priority) => {
|
|
|
563
536
|
}
|
|
564
537
|
const data = Object.assign(Object.assign({}, modelData(node, parent, path, priority)), { _id: id, objectType: objectType });
|
|
565
538
|
const model = data;
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
}
|
|
569
|
-
const comments = [...commentAnnotationsMap.values()];
|
|
570
|
-
return { model, comments };
|
|
539
|
+
const markers = extractCommentMarkers(model);
|
|
540
|
+
return { model, markers };
|
|
571
541
|
};
|
|
572
|
-
|
|
542
|
+
const containerTypes = [
|
|
543
|
+
schema.nodes.affiliations,
|
|
544
|
+
schema.nodes.contributors,
|
|
545
|
+
schema.nodes.affiliations,
|
|
546
|
+
schema.nodes.keywords,
|
|
547
|
+
schema.nodes.abstracts,
|
|
548
|
+
schema.nodes.body,
|
|
549
|
+
schema.nodes.backmatter,
|
|
550
|
+
];
|
|
551
|
+
const placeholderTypes = [
|
|
552
|
+
schema.nodes.placeholder,
|
|
553
|
+
schema.nodes.placeholder_element,
|
|
554
|
+
];
|
|
555
|
+
export const encode = (node) => {
|
|
573
556
|
const models = new Map();
|
|
574
557
|
const priority = {
|
|
575
558
|
value: 1,
|
|
576
559
|
};
|
|
577
|
-
const
|
|
578
|
-
|
|
560
|
+
const processNode = (path, parent) => (child) => {
|
|
561
|
+
if (containerTypes.includes(child.type)) {
|
|
562
|
+
child.forEach(processNode([], child));
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
579
565
|
if (!child.attrs.id) {
|
|
580
566
|
return;
|
|
581
567
|
}
|
|
582
568
|
if (isHighlightMarkerNode(child)) {
|
|
583
569
|
return;
|
|
584
570
|
}
|
|
585
|
-
if (child.type
|
|
571
|
+
if (placeholderTypes.includes(child.type)) {
|
|
586
572
|
return;
|
|
587
573
|
}
|
|
588
|
-
if (
|
|
574
|
+
if (parent.type === schema.nodes.paragraph &&
|
|
575
|
+
child.type !== schema.nodes.inline_equation) {
|
|
589
576
|
return;
|
|
590
577
|
}
|
|
591
|
-
const { model,
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
if (
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
comments.forEach((comment) => {
|
|
602
|
-
const proseMirrorComment = models.get(comment._id);
|
|
603
|
-
if (proseMirrorComment) {
|
|
604
|
-
;
|
|
605
|
-
proseMirrorComment.selector = comment.selector;
|
|
606
|
-
models.set(comment._id, proseMirrorComment);
|
|
578
|
+
const { model, markers } = modelFromNode(child, parent, path, priority);
|
|
579
|
+
markers.forEach((marker) => {
|
|
580
|
+
const comment = models.get(marker._id);
|
|
581
|
+
if (comment) {
|
|
582
|
+
comment.selector = {
|
|
583
|
+
from: marker.from,
|
|
584
|
+
to: marker.to,
|
|
585
|
+
};
|
|
607
586
|
}
|
|
608
587
|
});
|
|
588
|
+
if (models.has(model._id)) {
|
|
589
|
+
throw Error(`Duplicate ids in encode: ${model._id}`);
|
|
590
|
+
}
|
|
609
591
|
models.set(model._id, model);
|
|
610
|
-
child.forEach(
|
|
592
|
+
child.forEach(processNode(path.concat(child.attrs.id), child));
|
|
611
593
|
};
|
|
612
|
-
node.
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
594
|
+
const comments = node.lastChild;
|
|
595
|
+
if (comments && comments.type === schema.nodes.comments) {
|
|
596
|
+
comments.forEach(processNode([], comments));
|
|
597
|
+
}
|
|
598
|
+
node.forEach(processNode([], node));
|
|
599
|
+
if (isManuscriptNode(node)) {
|
|
600
|
+
auxiliaryObjectTypes.forEach((t) => {
|
|
601
|
+
const order = generateElementOrder(node, t);
|
|
602
|
+
if (order) {
|
|
603
|
+
models.set(order._id, order);
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
}
|
|
618
607
|
return models;
|
|
619
608
|
};
|
|
620
|
-
const
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
models.set(model._id, model);
|
|
609
|
+
const generateElementOrder = (node, nodeType) => {
|
|
610
|
+
const ids = [];
|
|
611
|
+
node.descendants((n) => {
|
|
612
|
+
if (n.type === nodeType) {
|
|
613
|
+
ids.push(n.attrs.id);
|
|
626
614
|
}
|
|
615
|
+
return true;
|
|
627
616
|
});
|
|
617
|
+
if (!ids.length) {
|
|
618
|
+
return undefined;
|
|
619
|
+
}
|
|
620
|
+
const type = nodeTypesMap.get(nodeType);
|
|
621
|
+
if (!type) {
|
|
622
|
+
return undefined;
|
|
623
|
+
}
|
|
624
|
+
const order = buildElementsOrder(type);
|
|
625
|
+
order.elements = ids;
|
|
626
|
+
return order;
|
|
628
627
|
};
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
const highlightableFields = [
|
|
16
|
+
export const highlightableFields = [
|
|
18
17
|
'caption',
|
|
19
18
|
'contents',
|
|
20
19
|
'title',
|
|
@@ -27,52 +26,65 @@ export const isHighlightableModel = (model) => {
|
|
|
27
26
|
}
|
|
28
27
|
return false;
|
|
29
28
|
};
|
|
30
|
-
export const
|
|
29
|
+
export const extractCommentMarkers = (model) => {
|
|
30
|
+
if (!isHighlightableModel(model)) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
const comments = new Map();
|
|
31
34
|
for (const field of highlightableFields) {
|
|
32
35
|
let html = model[field];
|
|
33
|
-
if (html
|
|
36
|
+
if (!html || !html.includes('highlight-marker')) {
|
|
34
37
|
continue;
|
|
35
38
|
}
|
|
36
39
|
const template = document.createElement('template');
|
|
37
40
|
template.innerHTML = `<div>${html}</div>`;
|
|
38
41
|
const element = template.content.firstChild;
|
|
39
|
-
if (!
|
|
42
|
+
if (!element) {
|
|
40
43
|
continue;
|
|
41
44
|
}
|
|
42
45
|
const markers = element.querySelectorAll('span.highlight-marker');
|
|
43
|
-
if (markers.length) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
if (!markers.length) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
for (const marker of markers) {
|
|
50
|
+
const markerHTML = marker.outerHTML;
|
|
51
|
+
const offset = html.indexOf(markerHTML);
|
|
52
|
+
if (offset === -1) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const id = marker.getAttribute('id');
|
|
56
|
+
const target = marker.getAttribute('data-target-id');
|
|
57
|
+
if (id && target) {
|
|
58
|
+
const position = marker.getAttribute('data-position');
|
|
59
|
+
if (position === 'start') {
|
|
60
|
+
const comment = {
|
|
61
|
+
_id: id,
|
|
62
|
+
from: offset,
|
|
63
|
+
to: -1,
|
|
64
|
+
};
|
|
65
|
+
comments.set(id, comment);
|
|
49
66
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const commentAnnotation = Object.assign(Object.assign({}, buildComment(target, '')), { _id: _id });
|
|
55
|
-
if (position === 'start') {
|
|
56
|
-
commentAnnotationsMap.set(commentAnnotation._id, Object.assign(Object.assign({}, commentAnnotation), { selector: {
|
|
57
|
-
from: offset,
|
|
58
|
-
to: -1,
|
|
59
|
-
} }));
|
|
60
|
-
}
|
|
61
|
-
else if (position === 'end') {
|
|
62
|
-
const comment = commentAnnotationsMap.get(commentAnnotation._id);
|
|
63
|
-
if (comment && comment.selector) {
|
|
64
|
-
commentAnnotationsMap.set(comment._id, Object.assign(Object.assign({}, comment), { selector: Object.assign(Object.assign({}, comment.selector), { to: offset }) }));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
else if (position === 'point') {
|
|
68
|
-
commentAnnotationsMap.set(commentAnnotation._id, Object.assign(Object.assign({}, commentAnnotation), { selector: { from: offset, to: offset } }));
|
|
67
|
+
else if (position === 'end') {
|
|
68
|
+
const comment = comments.get(id);
|
|
69
|
+
if (comment) {
|
|
70
|
+
comment.to = offset;
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
|
-
|
|
73
|
+
else if (position === 'point') {
|
|
74
|
+
const comment = {
|
|
75
|
+
_id: id,
|
|
76
|
+
from: offset,
|
|
77
|
+
to: offset,
|
|
78
|
+
};
|
|
79
|
+
comments.set(id, comment);
|
|
80
|
+
}
|
|
72
81
|
}
|
|
73
|
-
|
|
82
|
+
html =
|
|
83
|
+
html.substring(0, offset) + html.substring(offset + markerHTML.length);
|
|
74
84
|
}
|
|
85
|
+
model[field] = html;
|
|
75
86
|
}
|
|
87
|
+
return Array.from(comments.values());
|
|
76
88
|
};
|
|
77
89
|
export const insertHighlightMarkers = (contents, commentAnnotations) => {
|
|
78
90
|
let output = contents;
|
|
@@ -194,11 +194,9 @@ export class HTMLTransformer {
|
|
|
194
194
|
const citationNode = node;
|
|
195
195
|
const element = this.document.createElement('span');
|
|
196
196
|
element.setAttribute('class', 'citation');
|
|
197
|
-
const
|
|
198
|
-
if (
|
|
199
|
-
element.setAttribute('data-reference-ids',
|
|
200
|
-
.map((item) => item.bibliographyItem)
|
|
201
|
-
.join(' '));
|
|
197
|
+
const rids = citationNode.attrs.rids;
|
|
198
|
+
if (rids.length) {
|
|
199
|
+
element.setAttribute('data-reference-ids', rids.join(' '));
|
|
202
200
|
}
|
|
203
201
|
if (citationNode.attrs.contents) {
|
|
204
202
|
element.innerHTML = citationNode.attrs.contents;
|
|
@@ -206,25 +204,11 @@ export class HTMLTransformer {
|
|
|
206
204
|
return element;
|
|
207
205
|
};
|
|
208
206
|
nodes.cross_reference = (node) => {
|
|
209
|
-
const
|
|
207
|
+
const xref = node;
|
|
210
208
|
const element = this.document.createElement('a');
|
|
211
209
|
element.classList.add('cross-reference');
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
auxiliaryObjectReference.referencedObject) {
|
|
215
|
-
if (auxiliaryObjectReference.referencedObject.startsWith('MPFigureElement')) {
|
|
216
|
-
const model = getModel(auxiliaryObjectReference.referencedObject);
|
|
217
|
-
if (model && model.containedObjectIDs.length > 0) {
|
|
218
|
-
element.setAttribute('href', `#${model.containedObjectIDs[0]}`);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
element.setAttribute('href', `#${auxiliaryObjectReference.referencedObject}`);
|
|
223
|
-
}
|
|
224
|
-
element.setAttribute('data-reference-ids', crossReferenceNode.attrs.rid);
|
|
225
|
-
}
|
|
226
|
-
element.textContent =
|
|
227
|
-
crossReferenceNode.attrs.customLabel || crossReferenceNode.attrs.label;
|
|
210
|
+
element.setAttribute('data-reference-ids', xref.attrs.rids.join(' '));
|
|
211
|
+
element.textContent = xref.attrs.customLabel || xref.attrs.label;
|
|
228
212
|
return element;
|
|
229
213
|
};
|
|
230
214
|
nodes.listing = (node) => {
|
|
@@ -256,7 +240,7 @@ export class HTMLTransformer {
|
|
|
256
240
|
};
|
|
257
241
|
return ['span', attrs];
|
|
258
242
|
};
|
|
259
|
-
nodes.
|
|
243
|
+
nodes.comments = () => '';
|
|
260
244
|
const serializer = new DOMSerializer(nodes, marks);
|
|
261
245
|
return serializer.serializeFragment(fragment, { document });
|
|
262
246
|
};
|
|
@@ -27,6 +27,7 @@ const labelProperties = new Map([
|
|
|
27
27
|
[schema.nodes.equation_element, 'equationElementLabel'],
|
|
28
28
|
[schema.nodes.listing_element, 'listingElementLabel'],
|
|
29
29
|
]);
|
|
30
|
+
const excludedTypes = [schema.nodes.graphical_abstract_section];
|
|
30
31
|
const chooseLabel = (nodeType, manuscript) => {
|
|
31
32
|
const labelProperty = labelProperties.get(nodeType);
|
|
32
33
|
if (labelProperty) {
|
|
@@ -51,25 +52,10 @@ export const buildTargets = (fragment, manuscript) => {
|
|
|
51
52
|
return `${counter.label} ${counter.index}`;
|
|
52
53
|
};
|
|
53
54
|
const targets = new Map();
|
|
54
|
-
|
|
55
|
-
fragment.forEach((node) => {
|
|
56
|
-
if (node.attrs.category === 'MPSectionCategory:abstracts') {
|
|
57
|
-
node.forEach((child) => {
|
|
58
|
-
if (child.type === node.type.schema.nodes.graphical_abstract_section) {
|
|
59
|
-
child.forEach((item) => {
|
|
60
|
-
if (item.type === node.type.schema.nodes.figure_element) {
|
|
61
|
-
figures.push(item.attrs.id);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
fragment.descendants((node) => {
|
|
55
|
+
fragment.descendants((node, pos, parent) => {
|
|
69
56
|
var _a;
|
|
70
57
|
if (node.type.name in counters) {
|
|
71
|
-
|
|
72
|
-
if (isInGraphicalAbstract) {
|
|
58
|
+
if (parent && excludedTypes.includes(parent.type)) {
|
|
73
59
|
return;
|
|
74
60
|
}
|
|
75
61
|
const label = buildLabel(node.type);
|
|
@@ -35,6 +35,6 @@ export const nodeNames = new Map([
|
|
|
35
35
|
[schema.nodes.table_element, 'Table'],
|
|
36
36
|
[schema.nodes.blockquote_element, 'Block Quote'],
|
|
37
37
|
[schema.nodes.pullquote_element, 'Pull Quote'],
|
|
38
|
-
[schema.nodes.
|
|
38
|
+
[schema.nodes.keywords, 'Section'],
|
|
39
39
|
[schema.nodes.toc_section, 'Section'],
|
|
40
40
|
]);
|
|
@@ -47,7 +47,7 @@ export const nodeTitle = (node) => {
|
|
|
47
47
|
case nodes.section:
|
|
48
48
|
case nodes.bibliography_section:
|
|
49
49
|
case nodes.footnotes_section:
|
|
50
|
-
case nodes.
|
|
50
|
+
case nodes.keywords:
|
|
51
51
|
case nodes.toc_section:
|
|
52
52
|
case nodes.graphical_abstract_section:
|
|
53
53
|
return snippetOfNodeType(node, nodes.section_title);
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
import { ObjectTypes } from '@manuscripts/json-schema';
|
|
17
17
|
import { GROUP_ELEMENT, GROUP_EXECUTABLE, GROUP_SECTION, hasGroup, schema, } from '../schema';
|
|
18
18
|
export const nodeTypesMap = new Map([
|
|
19
|
+
[schema.nodes.abstracts, ObjectTypes.Section],
|
|
20
|
+
[schema.nodes.body, ObjectTypes.Section],
|
|
21
|
+
[schema.nodes.backmatter, ObjectTypes.Section],
|
|
19
22
|
[schema.nodes.comment, ObjectTypes.CommentAnnotation],
|
|
20
23
|
[schema.nodes.bibliography_item, ObjectTypes.BibliographyItem],
|
|
21
24
|
[schema.nodes.bibliography_element, ObjectTypes.BibliographyElement],
|
|
@@ -23,7 +26,6 @@ export const nodeTypesMap = new Map([
|
|
|
23
26
|
[schema.nodes.blockquote_element, ObjectTypes.QuoteElement],
|
|
24
27
|
[schema.nodes.bullet_list, ObjectTypes.ListElement],
|
|
25
28
|
[schema.nodes.citation, ObjectTypes.Citation],
|
|
26
|
-
[schema.nodes.cross_reference, ObjectTypes.AuxiliaryObjectReference],
|
|
27
29
|
[schema.nodes.equation, ObjectTypes.Equation],
|
|
28
30
|
[schema.nodes.equation_element, ObjectTypes.EquationElement],
|
|
29
31
|
[schema.nodes.figure, ObjectTypes.Figure],
|
|
@@ -37,8 +39,8 @@ export const nodeTypesMap = new Map([
|
|
|
37
39
|
[schema.nodes.inline_equation, ObjectTypes.InlineMathFragment],
|
|
38
40
|
[schema.nodes.keyword, ObjectTypes.Keyword],
|
|
39
41
|
[schema.nodes.keywords_element, ObjectTypes.KeywordsElement],
|
|
40
|
-
[schema.nodes.
|
|
41
|
-
[schema.nodes.
|
|
42
|
+
[schema.nodes.keywords, ObjectTypes.Section],
|
|
43
|
+
[schema.nodes.keyword_group, ObjectTypes.KeywordGroup],
|
|
42
44
|
[schema.nodes.listing, ObjectTypes.Listing],
|
|
43
45
|
[schema.nodes.listing_element, ObjectTypes.ListingElement],
|
|
44
46
|
[schema.nodes.manuscript, ObjectTypes.Manuscript],
|
|
@@ -50,13 +52,12 @@ export const nodeTypesMap = new Map([
|
|
|
50
52
|
[schema.nodes.table_element, ObjectTypes.TableElement],
|
|
51
53
|
[schema.nodes.toc_element, ObjectTypes.TOCElement],
|
|
52
54
|
[schema.nodes.toc_section, ObjectTypes.Section],
|
|
53
|
-
[schema.nodes.meta_section, ObjectTypes.MetaSection],
|
|
54
55
|
[schema.nodes.affiliation, ObjectTypes.Affiliation],
|
|
55
56
|
[schema.nodes.contributor, ObjectTypes.Contributor],
|
|
56
57
|
[schema.nodes.table_element_footer, ObjectTypes.TableElementFooter],
|
|
58
|
+
[schema.nodes.contributors, ObjectTypes.Section],
|
|
59
|
+
[schema.nodes.affiliations, ObjectTypes.Section],
|
|
57
60
|
[schema.nodes.title, ObjectTypes.Titles],
|
|
58
|
-
[schema.nodes.contributors_section, ObjectTypes.Section],
|
|
59
|
-
[schema.nodes.affiliations_section, ObjectTypes.Section],
|
|
60
61
|
]);
|
|
61
62
|
export const isExecutableNodeType = (type) => hasGroup(type, GROUP_EXECUTABLE);
|
|
62
63
|
export const isElementNodeType = (type) => hasGroup(type, GROUP_ELEMENT);
|
|
@@ -48,6 +48,5 @@ export const hasObjectType = (objectType) => (model) => model.objectType === obj
|
|
|
48
48
|
export const isFigure = hasObjectType(ObjectTypes.Figure);
|
|
49
49
|
export const isManuscript = hasObjectType(ObjectTypes.Manuscript);
|
|
50
50
|
export const isTable = hasObjectType(ObjectTypes.Table);
|
|
51
|
-
export const isUserProfile = hasObjectType(ObjectTypes.UserProfile);
|
|
52
51
|
export const isCommentAnnotation = hasObjectType(ObjectTypes.CommentAnnotation);
|
|
53
52
|
export const isKeyword = hasObjectType(ObjectTypes.Keyword);
|
|
@@ -14,22 +14,15 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { ObjectTypes } from '@manuscripts/json-schema';
|
|
17
|
-
import {
|
|
17
|
+
import { abstractsType, backmatterType, bodyType, } from '../lib/section-group-type';
|
|
18
18
|
import { schema } from '../schema';
|
|
19
19
|
const sectionNodeTypes = [
|
|
20
20
|
schema.nodes.bibliography_section,
|
|
21
21
|
schema.nodes.footnotes_section,
|
|
22
|
-
schema.nodes.
|
|
22
|
+
schema.nodes.keywords,
|
|
23
23
|
schema.nodes.section,
|
|
24
24
|
schema.nodes.toc_section,
|
|
25
25
|
];
|
|
26
|
-
export const getCoreSectionTitles = (sectionCategory) => {
|
|
27
|
-
const category = coreSectionCategories.find((section) => section._id === sectionCategory);
|
|
28
|
-
if (category) {
|
|
29
|
-
return category.titles.length ? category.titles : [' '];
|
|
30
|
-
}
|
|
31
|
-
throw new Error(`${sectionCategory} not found in core sections`);
|
|
32
|
-
};
|
|
33
26
|
export const isAnySectionNode = (node) => sectionNodeTypes.includes(node.type);
|
|
34
27
|
export const chooseSectionNodeType = (category) => {
|
|
35
28
|
switch (category) {
|
|
@@ -40,11 +33,7 @@ export const chooseSectionNodeType = (category) => {
|
|
|
40
33
|
case 'MPSectionCategory:endnotes':
|
|
41
34
|
return schema.nodes.footnotes_section;
|
|
42
35
|
case 'MPSectionCategory:keywords':
|
|
43
|
-
return schema.nodes.
|
|
44
|
-
case 'MPSectionCategory:affiliations':
|
|
45
|
-
return schema.nodes.affiliations_section;
|
|
46
|
-
case 'MPSectionCategory:contributors':
|
|
47
|
-
return schema.nodes.contributors_section;
|
|
36
|
+
return schema.nodes.keywords;
|
|
48
37
|
case 'MPSectionCategory:toc':
|
|
49
38
|
return schema.nodes.toc_section;
|
|
50
39
|
default:
|
|
@@ -82,16 +71,12 @@ export const buildSectionCategory = (node) => {
|
|
|
82
71
|
return 'MPSectionCategory:bibliography';
|
|
83
72
|
case schema.nodes.footnotes_section:
|
|
84
73
|
return 'MPSectionCategory:endnotes';
|
|
85
|
-
case schema.nodes.
|
|
74
|
+
case schema.nodes.keywords:
|
|
86
75
|
return 'MPSectionCategory:keywords';
|
|
87
76
|
case schema.nodes.toc_section:
|
|
88
77
|
return 'MPSectionCategory:toc';
|
|
89
78
|
case schema.nodes.graphical_abstract_section:
|
|
90
79
|
return 'MPSectionCategory:abstract-graphical';
|
|
91
|
-
case schema.nodes.affiliations_section:
|
|
92
|
-
return 'MPSectionCategory:affiliations';
|
|
93
|
-
case schema.nodes.contributors_section:
|
|
94
|
-
return 'MPSectionCategory:contributors';
|
|
95
80
|
default:
|
|
96
81
|
return node.attrs.category || undefined;
|
|
97
82
|
}
|
|
@@ -117,6 +102,31 @@ export const chooseSecType = (sectionCategory) => {
|
|
|
117
102
|
return suffix;
|
|
118
103
|
}
|
|
119
104
|
};
|
|
105
|
+
export const getSectionGroupType = (category) => {
|
|
106
|
+
switch (category) {
|
|
107
|
+
case 'MPSectionCategory:abstract':
|
|
108
|
+
case 'MPSectionCategory:abstract-graphical':
|
|
109
|
+
return abstractsType;
|
|
110
|
+
case 'MPSectionCategory:competing-interests':
|
|
111
|
+
case 'MPSectionCategory:con':
|
|
112
|
+
case 'MPSectionCategory:ethics-statement':
|
|
113
|
+
case 'MPSectionCategory:financial-disclosure':
|
|
114
|
+
case 'MPSectionCategory:supplementary-material':
|
|
115
|
+
case 'MPSectionCategory:supported-by':
|
|
116
|
+
case 'MPSectionCategory:availability':
|
|
117
|
+
case 'MPSectionCategory:acknowledgement':
|
|
118
|
+
case 'MPSectionCategory:endnotes':
|
|
119
|
+
case 'MPSectionCategory:bibliography':
|
|
120
|
+
case 'MPSectionCategory:appendices':
|
|
121
|
+
case 'MPSectionCategory:deceased':
|
|
122
|
+
case 'MPSectionCategory:equal':
|
|
123
|
+
case 'MPSectionCategory:present-address':
|
|
124
|
+
case 'MPSectionCategory:presented-at':
|
|
125
|
+
case 'MPSectionCategory:previously-at':
|
|
126
|
+
return backmatterType;
|
|
127
|
+
}
|
|
128
|
+
return bodyType;
|
|
129
|
+
};
|
|
120
130
|
export const chooseSectionCategoryByType = (secType) => {
|
|
121
131
|
switch (secType) {
|
|
122
132
|
case 'abstract':
|
|
@@ -176,16 +186,6 @@ export const chooseSectionCategoryByType = (secType) => {
|
|
|
176
186
|
return 'MPSectionCategory:supported-by';
|
|
177
187
|
case 'ethics-statement':
|
|
178
188
|
return 'MPSectionCategory:ethics-statement';
|
|
179
|
-
case 'body':
|
|
180
|
-
return 'MPSectionCategory:body';
|
|
181
|
-
case 'backmatter':
|
|
182
|
-
return 'MPSectionCategory:backmatter';
|
|
183
|
-
case 'abstracts':
|
|
184
|
-
return 'MPSectionCategory:abstracts';
|
|
185
|
-
case 'affiliations':
|
|
186
|
-
return 'MPSectionCategory:affiliations';
|
|
187
|
-
case 'contributors':
|
|
188
|
-
return 'MPSectionCategory:contributors';
|
|
189
189
|
default:
|
|
190
190
|
return undefined;
|
|
191
191
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -13,4 +13,4 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export { parseJATSFront, parseJATSBody,
|
|
16
|
+
export { parseJATSFront, parseJATSBody, parseJATSArticle, } from './parse-jats-article';
|
|
@@ -13,29 +13,26 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { Affiliation, BibliographyItem, Contributor } from '@manuscripts/json-schema';
|
|
17
|
-
import { Build } from '../../transformer';
|
|
18
16
|
export declare const jatsBodyTransformations: {
|
|
19
17
|
ensureSection(body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
createFootnotes(footnoteGroups: Element[], createElement: (tagName: string) => HTMLElement): HTMLElement;
|
|
18
|
+
createAbstractSection(abstractNode: Element, createElement: (tagName: string) => HTMLElement): HTMLElement;
|
|
19
|
+
createAcknowledgmentsSection(ackNode: Element, createElement: (tagName: string) => HTMLElement): HTMLElement;
|
|
20
|
+
createFootnotesSection(footnoteGroups: Element[], createElement: (tagName: string) => HTMLElement): HTMLElement;
|
|
24
21
|
createAppendixSection(app: Element, createElement: (tagName: string) => HTMLElement): HTMLElement;
|
|
25
|
-
createFloatsGroupSection(
|
|
26
|
-
|
|
27
|
-
wrapBodySections(doc: Document,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
22
|
+
createFloatsGroupSection(group: Element, createElement: (tagName: string) => HTMLElement): HTMLElement;
|
|
23
|
+
moveAbstracts(doc: Document, group: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
24
|
+
wrapBodySections(doc: Document, group: Element): void;
|
|
25
|
+
moveBackSections(doc: Document, group: Element): void;
|
|
26
|
+
moveAcknowledgments(doc: Document, group: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
27
|
+
moveAppendices(doc: Document, group: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
28
|
+
createBody(doc: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
29
|
+
createAbstracts(doc: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
30
|
+
createBackmatter(doc: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
31
|
+
moveSpecialFootnotes(doc: Document, group: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
32
|
+
moveFootnotes(doc: Document, group: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
34
33
|
moveCaptionsToEnd(body: Element): void;
|
|
34
|
+
fixTables(body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
35
35
|
moveTableFooterToEnd(body: Element): void;
|
|
36
|
-
moveAffiliationsToBody(doc: Document, affiliations: Build<Affiliation>[] | undefined, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
37
|
-
moveAuthorsToBody(doc: Document, authors: Build<Contributor>[] | undefined, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
38
36
|
moveFloatsGroupToBody(doc: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
39
|
-
|
|
40
|
-
moveKeywordsToBody(document: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
37
|
+
createKeywords(document: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
41
38
|
};
|
|
@@ -13,14 +13,18 @@
|
|
|
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
|
-
type
|
|
16
|
+
import { CommentAnnotation, Model } from '@manuscripts/json-schema';
|
|
17
|
+
import { References } from './jats-references';
|
|
18
|
+
export type JATSComment = {
|
|
19
19
|
id: string;
|
|
20
|
-
|
|
20
|
+
text: string;
|
|
21
21
|
};
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export
|
|
22
|
+
export type JATSCommentMark = {
|
|
23
|
+
token: string;
|
|
24
|
+
comment: JATSComment;
|
|
25
|
+
};
|
|
26
|
+
export declare const isJATSComment: (node: Node) => boolean;
|
|
27
|
+
export declare const parseJATSComment: (node: Node) => JATSComment | undefined;
|
|
28
|
+
export declare const markComments: (doc: Document) => JATSCommentMark[];
|
|
29
|
+
export declare const createComments: (models: Model[], marks: JATSCommentMark[]) => CommentAnnotation[];
|
|
30
|
+
export declare const createReferenceComments: (references: References) => CommentAnnotation[];
|