@manuscripts/transform 1.5.8-LEAN-3030-2 → 1.5.8-LEAN-3030-3
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/jats-exporter.js +1 -1
- package/dist/cjs/lib/utils.js +1 -14
- package/dist/cjs/schema/index.js +3 -3
- package/dist/cjs/schema/nodes/affiliations.js +1 -1
- package/dist/cjs/transformer/decode.js +18 -14
- package/dist/cjs/transformer/encode.js +25 -28
- package/dist/cjs/transformer/highlight-markers.js +45 -33
- package/dist/cjs/transformer/html.js +3 -4
- package/dist/es/jats/index.js +1 -1
- package/dist/es/jats/jats-exporter.js +1 -1
- package/dist/es/lib/utils.js +0 -12
- package/dist/es/schema/index.js +3 -3
- package/dist/es/schema/nodes/affiliations.js +1 -1
- package/dist/es/transformer/decode.js +18 -14
- package/dist/es/transformer/encode.js +27 -30
- package/dist/es/transformer/highlight-markers.js +43 -31
- package/dist/es/transformer/html.js +3 -4
- package/dist/types/jats/index.d.ts +1 -1
- package/dist/types/lib/utils.d.ts +0 -2
- package/dist/types/transformer/encode.d.ts +4 -4
- package/dist/types/transformer/highlight-markers.d.ts +6 -2
- package/package.json +1 -1
|
@@ -735,7 +735,7 @@ class JATSExporter {
|
|
|
735
735
|
};
|
|
736
736
|
return ['sec', attrs, 0];
|
|
737
737
|
},
|
|
738
|
-
hard_break: () =>
|
|
738
|
+
hard_break: () => '',
|
|
739
739
|
highlight_marker: () => '',
|
|
740
740
|
inline_equation: (node) => {
|
|
741
741
|
const formula = this.document.createElement('inline-formula');
|
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.
|
|
18
|
+
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,16 +83,3 @@ 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
|
-
function modelsEqual(model, model2) {
|
|
87
|
-
for (const v in model) {
|
|
88
|
-
for (const v2 in model2) {
|
|
89
|
-
const prepV = typeof v == 'object' ? JSON.stringify(v) : v;
|
|
90
|
-
const prepV2 = typeof v2 == 'object' ? JSON.stringify(v2) : v2;
|
|
91
|
-
if (prepV !== prepV2) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
exports.modelsEqual = modelsEqual;
|
package/dist/cjs/schema/index.js
CHANGED
|
@@ -32,13 +32,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
exports.schema = void 0;
|
|
33
33
|
const prosemirror_model_1 = require("prosemirror-model");
|
|
34
34
|
const marks_1 = require("./marks");
|
|
35
|
+
const abstracts_1 = require("./nodes/abstracts");
|
|
35
36
|
const affiliation_1 = require("./nodes/affiliation");
|
|
36
37
|
const affiliations_1 = require("./nodes/affiliations");
|
|
37
38
|
const attribution_1 = require("./nodes/attribution");
|
|
39
|
+
const backmatter_1 = require("./nodes/backmatter");
|
|
38
40
|
const bibliography_element_1 = require("./nodes/bibliography_element");
|
|
39
41
|
const bibliography_item_1 = require("./nodes/bibliography_item");
|
|
40
42
|
const bibliography_section_1 = require("./nodes/bibliography_section");
|
|
41
43
|
const blockquote_element_1 = require("./nodes/blockquote_element");
|
|
44
|
+
const body_1 = require("./nodes/body");
|
|
42
45
|
const caption_1 = require("./nodes/caption");
|
|
43
46
|
const caption_title_1 = require("./nodes/caption_title");
|
|
44
47
|
const citation_1 = require("./nodes/citation");
|
|
@@ -87,9 +90,6 @@ const text_1 = require("./nodes/text");
|
|
|
87
90
|
const title_1 = require("./nodes/title");
|
|
88
91
|
const toc_element_1 = require("./nodes/toc_element");
|
|
89
92
|
const toc_section_1 = require("./nodes/toc_section");
|
|
90
|
-
const abstracts_1 = require("./nodes/abstracts");
|
|
91
|
-
const body_1 = require("./nodes/body");
|
|
92
|
-
const backmatter_1 = require("./nodes/backmatter");
|
|
93
93
|
__exportStar(require("./groups"), exports);
|
|
94
94
|
__exportStar(require("./types"), exports);
|
|
95
95
|
__exportStar(require("./nodes/comment"), exports);
|
|
@@ -71,6 +71,11 @@ const isFootnote = (0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.F
|
|
|
71
71
|
const hasParentSection = (id) => (section) => section.path &&
|
|
72
72
|
section.path.length > 1 &&
|
|
73
73
|
section.path[section.path.length - 2] === id;
|
|
74
|
+
const deprecatedCategories = [
|
|
75
|
+
'MPSectionCategory:contributors',
|
|
76
|
+
'MPSectionCategory:affiliations',
|
|
77
|
+
'MPSectionCategory:keywords',
|
|
78
|
+
];
|
|
74
79
|
class Decoder {
|
|
75
80
|
createTitleNode() {
|
|
76
81
|
const titles = getTitles(this.modelMap) || (0, builders_1.buildTitles)();
|
|
@@ -115,9 +120,10 @@ class Decoder {
|
|
|
115
120
|
continue;
|
|
116
121
|
}
|
|
117
122
|
const category = section.category;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
123
|
+
if (category && deprecatedCategories.includes(category)) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const group = category ? (0, section_category_1.getSectionGroupType)(category) : section_group_type_1.bodyType;
|
|
121
127
|
groups[group._id].push(this.decode(section));
|
|
122
128
|
}
|
|
123
129
|
const abstracts = schema_1.schema.nodes.abstracts.createAndFill({}, groups[section_group_type_1.abstractsType._id]);
|
|
@@ -141,7 +147,7 @@ class Decoder {
|
|
|
141
147
|
}
|
|
142
148
|
extractListing(model) {
|
|
143
149
|
if (model.listingID) {
|
|
144
|
-
return this.createListing(model);
|
|
150
|
+
return this.createListing(model.listingID);
|
|
145
151
|
}
|
|
146
152
|
}
|
|
147
153
|
constructor(modelMap, allowMissingElements = false) {
|
|
@@ -561,7 +567,7 @@ class Decoder {
|
|
|
561
567
|
? [table, figcaption, tableElementFooter]
|
|
562
568
|
: [table, figcaption];
|
|
563
569
|
if (model.listingID) {
|
|
564
|
-
const listing = this.createListing(model);
|
|
570
|
+
const listing = this.createListing(model.listingID);
|
|
565
571
|
content.push(listing);
|
|
566
572
|
}
|
|
567
573
|
else {
|
|
@@ -766,22 +772,20 @@ class Decoder {
|
|
|
766
772
|
? this.decode(tableElementFooterModel)
|
|
767
773
|
: undefined;
|
|
768
774
|
}
|
|
769
|
-
createListing(
|
|
770
|
-
const
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
listing = this.decode(listingModel);
|
|
775
|
+
createListing(id) {
|
|
776
|
+
const listing = this.getModel(id);
|
|
777
|
+
if (listing) {
|
|
778
|
+
return this.decode(listing);
|
|
774
779
|
}
|
|
775
780
|
else if (this.allowMissingElements) {
|
|
776
|
-
|
|
777
|
-
id
|
|
781
|
+
return schema_1.schema.nodes.placeholder.create({
|
|
782
|
+
id,
|
|
778
783
|
label: 'A listing',
|
|
779
784
|
});
|
|
780
785
|
}
|
|
781
786
|
else {
|
|
782
|
-
throw new errors_1.MissingElement(
|
|
787
|
+
throw new errors_1.MissingElement(id);
|
|
783
788
|
}
|
|
784
|
-
return listing;
|
|
785
789
|
}
|
|
786
790
|
}
|
|
787
791
|
exports.Decoder = Decoder;
|
|
@@ -25,7 +25,6 @@ const utils_1 = require("../lib/utils");
|
|
|
25
25
|
const schema_1 = require("../schema");
|
|
26
26
|
const builders_1 = require("./builders");
|
|
27
27
|
const highlight_markers_1 = require("./highlight-markers");
|
|
28
|
-
const id_1 = require("./id");
|
|
29
28
|
const node_types_1 = require("./node-types");
|
|
30
29
|
const section_category_1 = require("./section-category");
|
|
31
30
|
const serializer = prosemirror_model_1.DOMSerializer.fromSchema(schema_1.schema);
|
|
@@ -535,7 +534,6 @@ const modelData = (node, parent, path, priority) => {
|
|
|
535
534
|
return encoder(node, parent, path, priority);
|
|
536
535
|
};
|
|
537
536
|
const modelFromNode = (node, parent, path, priority) => {
|
|
538
|
-
const commentAnnotationsMap = new Map();
|
|
539
537
|
const objectType = node_types_1.nodeTypesMap.get(node.type);
|
|
540
538
|
if (!objectType) {
|
|
541
539
|
throw new Error(`No objectType is defined for ${node.type.name}`);
|
|
@@ -546,11 +544,8 @@ const modelFromNode = (node, parent, path, priority) => {
|
|
|
546
544
|
}
|
|
547
545
|
const data = Object.assign(Object.assign({}, modelData(node, parent, path, priority)), { _id: id, objectType: objectType });
|
|
548
546
|
const model = data;
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
}
|
|
552
|
-
const comments = [...commentAnnotationsMap.values()];
|
|
553
|
-
return { model, comments };
|
|
547
|
+
const markers = (0, highlight_markers_1.extractCommentMarkers)(model);
|
|
548
|
+
return { model, markers };
|
|
554
549
|
};
|
|
555
550
|
exports.modelFromNode = modelFromNode;
|
|
556
551
|
const containerTypes = [
|
|
@@ -561,14 +556,16 @@ const containerTypes = [
|
|
|
561
556
|
schema_1.schema.nodes.abstracts,
|
|
562
557
|
schema_1.schema.nodes.body,
|
|
563
558
|
schema_1.schema.nodes.backmatter,
|
|
564
|
-
schema_1.schema.nodes.comments,
|
|
565
559
|
];
|
|
566
|
-
const
|
|
560
|
+
const placeholderTypes = [
|
|
561
|
+
schema_1.schema.nodes.placeholder,
|
|
562
|
+
schema_1.schema.nodes.placeholder_element,
|
|
563
|
+
];
|
|
564
|
+
const encode = (node) => {
|
|
567
565
|
const models = new Map();
|
|
568
566
|
const priority = {
|
|
569
567
|
value: 1,
|
|
570
568
|
};
|
|
571
|
-
const placeholders = ['placeholder', 'placeholder_element'];
|
|
572
569
|
const processNode = (path, parent) => (child) => {
|
|
573
570
|
if (containerTypes.includes(child.type)) {
|
|
574
571
|
child.forEach(processNode([], child));
|
|
@@ -580,33 +577,33 @@ const encode = (node, preserveWithRepeatedID = false) => {
|
|
|
580
577
|
if ((0, schema_1.isHighlightMarkerNode)(child)) {
|
|
581
578
|
return;
|
|
582
579
|
}
|
|
583
|
-
if (
|
|
580
|
+
if (placeholderTypes.includes(child.type)) {
|
|
584
581
|
return;
|
|
585
582
|
}
|
|
586
|
-
if (parent.type === schema_1.schema.nodes.paragraph
|
|
583
|
+
if (parent.type === schema_1.schema.nodes.paragraph &&
|
|
584
|
+
child.type !== schema_1.schema.nodes.inline_equation) {
|
|
587
585
|
return;
|
|
588
586
|
}
|
|
589
|
-
const { model,
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
if (
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
comments.forEach((comment) => {
|
|
600
|
-
const proseMirrorComment = models.get(comment._id);
|
|
601
|
-
if (proseMirrorComment) {
|
|
602
|
-
;
|
|
603
|
-
proseMirrorComment.selector = comment.selector;
|
|
604
|
-
models.set(comment._id, proseMirrorComment);
|
|
587
|
+
const { model, markers } = (0, exports.modelFromNode)(child, parent, path, priority);
|
|
588
|
+
markers.forEach((marker) => {
|
|
589
|
+
const comment = models.get(marker._id);
|
|
590
|
+
if (comment) {
|
|
591
|
+
comment.selector = {
|
|
592
|
+
from: marker.from,
|
|
593
|
+
to: marker.to,
|
|
594
|
+
};
|
|
605
595
|
}
|
|
606
596
|
});
|
|
597
|
+
if (models.has(model._id)) {
|
|
598
|
+
throw Error(`Duplicate ids in encode: ${model._id}`);
|
|
599
|
+
}
|
|
607
600
|
models.set(model._id, model);
|
|
608
601
|
child.forEach(processNode(path.concat(child.attrs.id), child));
|
|
609
602
|
};
|
|
603
|
+
const comments = node.lastChild;
|
|
604
|
+
if (comments && comments.type === schema_1.schema.nodes.comments) {
|
|
605
|
+
comments.forEach(processNode([], comments));
|
|
606
|
+
}
|
|
610
607
|
node.forEach(processNode([], node));
|
|
611
608
|
if ((0, schema_1.isManuscriptNode)(node)) {
|
|
612
609
|
builders_1.auxiliaryObjectTypes.forEach((t) => {
|
|
@@ -15,8 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.insertHighlightMarkers = exports.
|
|
19
|
-
const builders_1 = require("./builders");
|
|
18
|
+
exports.insertHighlightMarkers = exports.extractCommentMarkers = exports.isHighlightableModel = exports.highlightableFields = void 0;
|
|
20
19
|
exports.highlightableFields = [
|
|
21
20
|
'caption',
|
|
22
21
|
'contents',
|
|
@@ -31,54 +30,67 @@ const isHighlightableModel = (model) => {
|
|
|
31
30
|
return false;
|
|
32
31
|
};
|
|
33
32
|
exports.isHighlightableModel = isHighlightableModel;
|
|
34
|
-
const
|
|
33
|
+
const extractCommentMarkers = (model) => {
|
|
34
|
+
if (!(0, exports.isHighlightableModel)(model)) {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
const comments = new Map();
|
|
35
38
|
for (const field of exports.highlightableFields) {
|
|
36
39
|
let html = model[field];
|
|
37
|
-
if (html
|
|
40
|
+
if (!html || !html.includes('highlight-marker')) {
|
|
38
41
|
continue;
|
|
39
42
|
}
|
|
40
43
|
const template = document.createElement('template');
|
|
41
44
|
template.innerHTML = `<div>${html}</div>`;
|
|
42
45
|
const element = template.content.firstChild;
|
|
43
|
-
if (!
|
|
46
|
+
if (!element) {
|
|
44
47
|
continue;
|
|
45
48
|
}
|
|
46
49
|
const markers = element.querySelectorAll('span.highlight-marker');
|
|
47
|
-
if (markers.length) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
if (!markers.length) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
for (const marker of markers) {
|
|
54
|
+
const markerHTML = marker.outerHTML;
|
|
55
|
+
const offset = html.indexOf(markerHTML);
|
|
56
|
+
if (offset === -1) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const id = marker.getAttribute('id');
|
|
60
|
+
const target = marker.getAttribute('data-target-id');
|
|
61
|
+
if (id && target) {
|
|
62
|
+
const position = marker.getAttribute('data-position');
|
|
63
|
+
if (position === 'start') {
|
|
64
|
+
const comment = {
|
|
65
|
+
_id: id,
|
|
66
|
+
from: offset,
|
|
67
|
+
to: -1,
|
|
68
|
+
};
|
|
69
|
+
comments.set(id, comment);
|
|
53
70
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const commentAnnotation = Object.assign(Object.assign({}, (0, builders_1.buildComment)(target, '')), { _id: _id });
|
|
59
|
-
if (position === 'start') {
|
|
60
|
-
commentAnnotationsMap.set(commentAnnotation._id, Object.assign(Object.assign({}, commentAnnotation), { selector: {
|
|
61
|
-
from: offset,
|
|
62
|
-
to: -1,
|
|
63
|
-
} }));
|
|
64
|
-
}
|
|
65
|
-
else if (position === 'end') {
|
|
66
|
-
const comment = commentAnnotationsMap.get(commentAnnotation._id);
|
|
67
|
-
if (comment && comment.selector) {
|
|
68
|
-
commentAnnotationsMap.set(comment._id, Object.assign(Object.assign({}, comment), { selector: Object.assign(Object.assign({}, comment.selector), { to: offset }) }));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else if (position === 'point') {
|
|
72
|
-
commentAnnotationsMap.set(commentAnnotation._id, Object.assign(Object.assign({}, commentAnnotation), { selector: { from: offset, to: offset } }));
|
|
71
|
+
else if (position === 'end') {
|
|
72
|
+
const comment = comments.get(id);
|
|
73
|
+
if (comment) {
|
|
74
|
+
comment.to = offset;
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
|
-
|
|
77
|
+
else if (position === 'point') {
|
|
78
|
+
const comment = {
|
|
79
|
+
_id: id,
|
|
80
|
+
from: offset,
|
|
81
|
+
to: offset,
|
|
82
|
+
};
|
|
83
|
+
comments.set(id, comment);
|
|
84
|
+
}
|
|
76
85
|
}
|
|
77
|
-
|
|
86
|
+
html =
|
|
87
|
+
html.substring(0, offset) + html.substring(offset + markerHTML.length);
|
|
78
88
|
}
|
|
89
|
+
model[field] = html;
|
|
79
90
|
}
|
|
91
|
+
return Array.from(comments.values());
|
|
80
92
|
};
|
|
81
|
-
exports.
|
|
93
|
+
exports.extractCommentMarkers = extractCommentMarkers;
|
|
82
94
|
const insertHighlightMarkers = (contents, commentAnnotations) => {
|
|
83
95
|
let output = contents;
|
|
84
96
|
const sortedComments = commentAnnotations.sort((a, b) => {
|
|
@@ -210,12 +210,11 @@ class HTMLTransformer {
|
|
|
210
210
|
return element;
|
|
211
211
|
};
|
|
212
212
|
nodes.cross_reference = (node) => {
|
|
213
|
-
const
|
|
213
|
+
const xref = node;
|
|
214
214
|
const element = this.document.createElement('a');
|
|
215
215
|
element.classList.add('cross-reference');
|
|
216
|
-
element.setAttribute('data-reference-ids',
|
|
217
|
-
element.textContent =
|
|
218
|
-
crossReferenceNode.attrs.customLabel || crossReferenceNode.attrs.label;
|
|
216
|
+
element.setAttribute('data-reference-ids', xref.attrs.rids.join(' '));
|
|
217
|
+
element.textContent = xref.attrs.customLabel || xref.attrs.label;
|
|
219
218
|
return element;
|
|
220
219
|
};
|
|
221
220
|
nodes.listing = (node) => {
|
package/dist/es/jats/index.js
CHANGED
|
@@ -13,6 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export { parseJATSFront, parseJATSBody, parseJATSArticle
|
|
16
|
+
export { parseJATSFront, parseJATSBody, parseJATSArticle } from './importer';
|
|
17
17
|
export * from './jats-exporter';
|
|
18
18
|
export * from './jats-versions';
|
|
@@ -728,7 +728,7 @@ export class JATSExporter {
|
|
|
728
728
|
};
|
|
729
729
|
return ['sec', attrs, 0];
|
|
730
730
|
},
|
|
731
|
-
hard_break: () =>
|
|
731
|
+
hard_break: () => '',
|
|
732
732
|
highlight_marker: () => '',
|
|
733
733
|
inline_equation: (node) => {
|
|
734
734
|
const formula = this.document.createElement('inline-formula');
|
package/dist/es/lib/utils.js
CHANGED
|
@@ -74,15 +74,3 @@ export const getTrimmedTextContent = (node, querySelector) => {
|
|
|
74
74
|
}
|
|
75
75
|
return (_b = (_a = node.querySelector(querySelector)) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim();
|
|
76
76
|
};
|
|
77
|
-
export function modelsEqual(model, model2) {
|
|
78
|
-
for (const v in model) {
|
|
79
|
-
for (const v2 in model2) {
|
|
80
|
-
const prepV = typeof v == 'object' ? JSON.stringify(v) : v;
|
|
81
|
-
const prepV2 = typeof v2 == 'object' ? JSON.stringify(v2) : v2;
|
|
82
|
-
if (prepV !== prepV2) {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return true;
|
|
88
|
-
}
|
package/dist/es/schema/index.js
CHANGED
|
@@ -15,13 +15,16 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { Schema } from 'prosemirror-model';
|
|
17
17
|
import { bold, code, italic, smallcaps, strikethrough, styled, subscript, superscript, tracked_delete, tracked_insert, underline, } from './marks';
|
|
18
|
+
import { abstracts } from './nodes/abstracts';
|
|
18
19
|
import { affiliation } from './nodes/affiliation';
|
|
19
20
|
import { affiliations } from './nodes/affiliations';
|
|
20
21
|
import { attribution } from './nodes/attribution';
|
|
22
|
+
import { backmatter } from './nodes/backmatter';
|
|
21
23
|
import { bibliographyElement } from './nodes/bibliography_element';
|
|
22
24
|
import { bibliographyItem } from './nodes/bibliography_item';
|
|
23
25
|
import { bibliographySection } from './nodes/bibliography_section';
|
|
24
26
|
import { blockquoteElement } from './nodes/blockquote_element';
|
|
27
|
+
import { body } from './nodes/body';
|
|
25
28
|
import { caption } from './nodes/caption';
|
|
26
29
|
import { captionTitle } from './nodes/caption_title';
|
|
27
30
|
import { citation } from './nodes/citation';
|
|
@@ -70,9 +73,6 @@ import { text } from './nodes/text';
|
|
|
70
73
|
import { title } from './nodes/title';
|
|
71
74
|
import { tocElement } from './nodes/toc_element';
|
|
72
75
|
import { tocSection } from './nodes/toc_section';
|
|
73
|
-
import { abstracts } from "./nodes/abstracts";
|
|
74
|
-
import { body } from "./nodes/body";
|
|
75
|
-
import { backmatter } from "./nodes/backmatter";
|
|
76
76
|
export * from './groups';
|
|
77
77
|
export * from './types';
|
|
78
78
|
export * from './nodes/comment';
|
|
@@ -62,6 +62,11 @@ const isFootnote = hasObjectType(ObjectTypes.Footnote);
|
|
|
62
62
|
const hasParentSection = (id) => (section) => section.path &&
|
|
63
63
|
section.path.length > 1 &&
|
|
64
64
|
section.path[section.path.length - 2] === id;
|
|
65
|
+
const deprecatedCategories = [
|
|
66
|
+
'MPSectionCategory:contributors',
|
|
67
|
+
'MPSectionCategory:affiliations',
|
|
68
|
+
'MPSectionCategory:keywords',
|
|
69
|
+
];
|
|
65
70
|
export class Decoder {
|
|
66
71
|
createTitleNode() {
|
|
67
72
|
const titles = getTitles(this.modelMap) || buildTitles();
|
|
@@ -106,9 +111,10 @@ export class Decoder {
|
|
|
106
111
|
continue;
|
|
107
112
|
}
|
|
108
113
|
const category = section.category;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
if (category && deprecatedCategories.includes(category)) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const group = category ? getSectionGroupType(category) : bodyType;
|
|
112
118
|
groups[group._id].push(this.decode(section));
|
|
113
119
|
}
|
|
114
120
|
const abstracts = schema.nodes.abstracts.createAndFill({}, groups[abstractsType._id]);
|
|
@@ -132,7 +138,7 @@ export class Decoder {
|
|
|
132
138
|
}
|
|
133
139
|
extractListing(model) {
|
|
134
140
|
if (model.listingID) {
|
|
135
|
-
return this.createListing(model);
|
|
141
|
+
return this.createListing(model.listingID);
|
|
136
142
|
}
|
|
137
143
|
}
|
|
138
144
|
constructor(modelMap, allowMissingElements = false) {
|
|
@@ -552,7 +558,7 @@ export class Decoder {
|
|
|
552
558
|
? [table, figcaption, tableElementFooter]
|
|
553
559
|
: [table, figcaption];
|
|
554
560
|
if (model.listingID) {
|
|
555
|
-
const listing = this.createListing(model);
|
|
561
|
+
const listing = this.createListing(model.listingID);
|
|
556
562
|
content.push(listing);
|
|
557
563
|
}
|
|
558
564
|
else {
|
|
@@ -757,21 +763,19 @@ export class Decoder {
|
|
|
757
763
|
? this.decode(tableElementFooterModel)
|
|
758
764
|
: undefined;
|
|
759
765
|
}
|
|
760
|
-
createListing(
|
|
761
|
-
const
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
listing = this.decode(listingModel);
|
|
766
|
+
createListing(id) {
|
|
767
|
+
const listing = this.getModel(id);
|
|
768
|
+
if (listing) {
|
|
769
|
+
return this.decode(listing);
|
|
765
770
|
}
|
|
766
771
|
else if (this.allowMissingElements) {
|
|
767
|
-
|
|
768
|
-
id
|
|
772
|
+
return schema.nodes.placeholder.create({
|
|
773
|
+
id,
|
|
769
774
|
label: 'A listing',
|
|
770
775
|
});
|
|
771
776
|
}
|
|
772
777
|
else {
|
|
773
|
-
throw new MissingElement(
|
|
778
|
+
throw new MissingElement(id);
|
|
774
779
|
}
|
|
775
|
-
return listing;
|
|
776
780
|
}
|
|
777
781
|
}
|
|
@@ -15,11 +15,10 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { DOMSerializer } from 'prosemirror-model';
|
|
17
17
|
import serializeToXML from 'w3c-xmlserializer';
|
|
18
|
-
import { iterateChildren
|
|
18
|
+
import { iterateChildren } from '../lib/utils';
|
|
19
19
|
import { hasGroup, isHighlightMarkerNode, isManuscriptNode, isSectionNode, schema, } from '../schema';
|
|
20
20
|
import { auxiliaryObjectTypes, buildAttribution, buildElementsOrder, } from './builders';
|
|
21
|
-
import {
|
|
22
|
-
import { generateID } from './id';
|
|
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);
|
|
@@ -527,7 +526,6 @@ const modelData = (node, parent, path, priority) => {
|
|
|
527
526
|
return encoder(node, parent, path, priority);
|
|
528
527
|
};
|
|
529
528
|
export const modelFromNode = (node, parent, path, priority) => {
|
|
530
|
-
const commentAnnotationsMap = new Map();
|
|
531
529
|
const objectType = nodeTypesMap.get(node.type);
|
|
532
530
|
if (!objectType) {
|
|
533
531
|
throw new Error(`No objectType is defined for ${node.type.name}`);
|
|
@@ -538,11 +536,8 @@ export const modelFromNode = (node, parent, path, priority) => {
|
|
|
538
536
|
}
|
|
539
537
|
const data = Object.assign(Object.assign({}, modelData(node, parent, path, priority)), { _id: id, objectType: objectType });
|
|
540
538
|
const model = data;
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
}
|
|
544
|
-
const comments = [...commentAnnotationsMap.values()];
|
|
545
|
-
return { model, comments };
|
|
539
|
+
const markers = extractCommentMarkers(model);
|
|
540
|
+
return { model, markers };
|
|
546
541
|
};
|
|
547
542
|
const containerTypes = [
|
|
548
543
|
schema.nodes.affiliations,
|
|
@@ -552,14 +547,16 @@ const containerTypes = [
|
|
|
552
547
|
schema.nodes.abstracts,
|
|
553
548
|
schema.nodes.body,
|
|
554
549
|
schema.nodes.backmatter,
|
|
555
|
-
schema.nodes.comments,
|
|
556
550
|
];
|
|
557
|
-
|
|
551
|
+
const placeholderTypes = [
|
|
552
|
+
schema.nodes.placeholder,
|
|
553
|
+
schema.nodes.placeholder_element,
|
|
554
|
+
];
|
|
555
|
+
export const encode = (node) => {
|
|
558
556
|
const models = new Map();
|
|
559
557
|
const priority = {
|
|
560
558
|
value: 1,
|
|
561
559
|
};
|
|
562
|
-
const placeholders = ['placeholder', 'placeholder_element'];
|
|
563
560
|
const processNode = (path, parent) => (child) => {
|
|
564
561
|
if (containerTypes.includes(child.type)) {
|
|
565
562
|
child.forEach(processNode([], child));
|
|
@@ -571,33 +568,33 @@ export const encode = (node, preserveWithRepeatedID = false) => {
|
|
|
571
568
|
if (isHighlightMarkerNode(child)) {
|
|
572
569
|
return;
|
|
573
570
|
}
|
|
574
|
-
if (
|
|
571
|
+
if (placeholderTypes.includes(child.type)) {
|
|
575
572
|
return;
|
|
576
573
|
}
|
|
577
|
-
if (parent.type === schema.nodes.paragraph
|
|
574
|
+
if (parent.type === schema.nodes.paragraph &&
|
|
575
|
+
child.type !== schema.nodes.inline_equation) {
|
|
578
576
|
return;
|
|
579
577
|
}
|
|
580
|
-
const { model,
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
if (
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
comments.forEach((comment) => {
|
|
591
|
-
const proseMirrorComment = models.get(comment._id);
|
|
592
|
-
if (proseMirrorComment) {
|
|
593
|
-
;
|
|
594
|
-
proseMirrorComment.selector = comment.selector;
|
|
595
|
-
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
|
+
};
|
|
596
586
|
}
|
|
597
587
|
});
|
|
588
|
+
if (models.has(model._id)) {
|
|
589
|
+
throw Error(`Duplicate ids in encode: ${model._id}`);
|
|
590
|
+
}
|
|
598
591
|
models.set(model._id, model);
|
|
599
592
|
child.forEach(processNode(path.concat(child.attrs.id), child));
|
|
600
593
|
};
|
|
594
|
+
const comments = node.lastChild;
|
|
595
|
+
if (comments && comments.type === schema.nodes.comments) {
|
|
596
|
+
comments.forEach(processNode([], comments));
|
|
597
|
+
}
|
|
601
598
|
node.forEach(processNode([], node));
|
|
602
599
|
if (isManuscriptNode(node)) {
|
|
603
600
|
auxiliaryObjectTypes.forEach((t) => {
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { buildComment } from './builders';
|
|
17
16
|
export const highlightableFields = [
|
|
18
17
|
'caption',
|
|
19
18
|
'contents',
|
|
@@ -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;
|
|
@@ -204,12 +204,11 @@ export class HTMLTransformer {
|
|
|
204
204
|
return element;
|
|
205
205
|
};
|
|
206
206
|
nodes.cross_reference = (node) => {
|
|
207
|
-
const
|
|
207
|
+
const xref = node;
|
|
208
208
|
const element = this.document.createElement('a');
|
|
209
209
|
element.classList.add('cross-reference');
|
|
210
|
-
element.setAttribute('data-reference-ids',
|
|
211
|
-
element.textContent =
|
|
212
|
-
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;
|
|
213
212
|
return element;
|
|
214
213
|
};
|
|
215
214
|
nodes.listing = (node) => {
|
|
@@ -13,6 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export { parseJATSFront, parseJATSBody, parseJATSArticle
|
|
16
|
+
export { parseJATSFront, parseJATSBody, parseJATSArticle } from './importer';
|
|
17
17
|
export * from './jats-exporter';
|
|
18
18
|
export * from './jats-versions';
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { Model } from '@manuscripts/json-schema';
|
|
17
16
|
import { Node as ProsemirrorNode, ResolvedPos } from 'prosemirror-model';
|
|
18
17
|
import { ManuscriptEditorState, ManuscriptNode } from '../schema';
|
|
19
18
|
export declare function iterateChildren(node: ManuscriptNode, recurse?: boolean): Iterable<ManuscriptNode>;
|
|
@@ -27,4 +26,3 @@ export declare const findParentNodeClosestToPos: ($pos: ResolvedPos, predicate:
|
|
|
27
26
|
node: ProsemirrorNode;
|
|
28
27
|
} | undefined;
|
|
29
28
|
export declare const getTrimmedTextContent: (node: Element | Document | null, querySelector: string) => string | null | undefined;
|
|
30
|
-
export declare function modelsEqual(model: Model, model2: Model): boolean;
|
|
@@ -13,17 +13,17 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
16
|
+
import { Model } from '@manuscripts/json-schema';
|
|
17
17
|
import { ManuscriptNode } from '../schema';
|
|
18
|
-
import {
|
|
18
|
+
import { CommentMarker } from './highlight-markers';
|
|
19
19
|
export declare const inlineContents: (node: ManuscriptNode) => string;
|
|
20
20
|
export declare const inlineText: (node: ManuscriptNode) => string;
|
|
21
21
|
export declare const modelFromNode: (node: ManuscriptNode, parent: ManuscriptNode, path: string[], priority: PrioritizedValue) => {
|
|
22
22
|
model: Model;
|
|
23
|
-
|
|
23
|
+
markers: CommentMarker[];
|
|
24
24
|
};
|
|
25
25
|
interface PrioritizedValue {
|
|
26
26
|
value: number;
|
|
27
27
|
}
|
|
28
|
-
export declare const encode: (node: ManuscriptNode
|
|
28
|
+
export declare const encode: (node: ManuscriptNode) => Map<string, Model>;
|
|
29
29
|
export {};
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { CommentAnnotation, Model } from '@manuscripts/json-schema';
|
|
17
|
-
import { Build } from './builders';
|
|
18
17
|
export type HighlightableField = 'title' | 'caption' | 'contents';
|
|
19
18
|
export declare const highlightableFields: HighlightableField[];
|
|
20
19
|
export declare const isHighlightableModel: (model: Model) => model is HighlightableModel;
|
|
@@ -23,5 +22,10 @@ export interface HighlightableModel extends Model {
|
|
|
23
22
|
title?: string;
|
|
24
23
|
caption?: string;
|
|
25
24
|
}
|
|
26
|
-
export
|
|
25
|
+
export type CommentMarker = {
|
|
26
|
+
_id: string;
|
|
27
|
+
from: number;
|
|
28
|
+
to: number;
|
|
29
|
+
};
|
|
30
|
+
export declare const extractCommentMarkers: (model: Model) => CommentMarker[];
|
|
27
31
|
export declare const insertHighlightMarkers: (contents: string, commentAnnotations: CommentAnnotation[]) => string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manuscripts/transform",
|
|
3
3
|
"description": "ProseMirror transformer for Manuscripts applications",
|
|
4
|
-
"version": "1.5.8-LEAN-3030-
|
|
4
|
+
"version": "1.5.8-LEAN-3030-3",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-transform",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|