@manuscripts/transform 2.1.1 → 2.1.2
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/jats-body-transformations.js +10 -0
- package/dist/cjs/jats/importer/parse-jats-article.js +1 -0
- package/dist/cjs/transformer/builders.js +2 -1
- package/dist/cjs/transformer/decode.js +18 -17
- package/dist/cjs/transformer/encode.js +9 -0
- package/dist/cjs/transformer/footnotes-order.js +1 -4
- package/dist/es/jats/importer/jats-body-transformations.js +10 -0
- package/dist/es/jats/importer/parse-jats-article.js +1 -0
- package/dist/es/transformer/builders.js +2 -1
- package/dist/es/transformer/decode.js +19 -18
- package/dist/es/transformer/encode.js +10 -1
- package/dist/es/transformer/footnotes-order.js +0 -2
- package/dist/types/jats/importer/jats-body-transformations.d.ts +1 -0
- package/dist/types/transformer/builders.d.ts +1 -1
- package/dist/types/transformer/footnotes-order.d.ts +0 -1
- package/package.json +3 -3
|
@@ -265,6 +265,16 @@ exports.jatsBodyTransformations = {
|
|
|
265
265
|
}
|
|
266
266
|
});
|
|
267
267
|
},
|
|
268
|
+
orderTableFootnote(doc, body) {
|
|
269
|
+
const tableInlineFootnotesIds = new Set(Array.from(body.querySelectorAll('tbody > tr > td > xref[ref-type="fn"]').values()).map((inlineFootnote) => inlineFootnote.getAttribute('rid')));
|
|
270
|
+
const fnGroups = doc.querySelectorAll('table-wrap-foot > fn-group');
|
|
271
|
+
fnGroups.forEach((fnGroup) => {
|
|
272
|
+
const orderedFootnotes = Array.from(fnGroup.querySelectorAll('fn')).sort((fn) => tableInlineFootnotesIds.has(fn.getAttribute('id'))
|
|
273
|
+
? -1
|
|
274
|
+
: 0);
|
|
275
|
+
fnGroup.replaceChildren(...orderedFootnotes);
|
|
276
|
+
});
|
|
277
|
+
},
|
|
268
278
|
moveFloatsGroupToBody(doc, body, createElement) {
|
|
269
279
|
const group = doc.querySelector('floats-group');
|
|
270
280
|
if (group) {
|
|
@@ -67,6 +67,7 @@ const parseJATSBody = (doc, body, references) => {
|
|
|
67
67
|
jats_body_transformations_1.jatsBodyTransformations.createBackmatter(doc, body, createElement);
|
|
68
68
|
jats_body_transformations_1.jatsBodyTransformations.createSuppleMaterials(doc, body, createElement);
|
|
69
69
|
jats_body_transformations_1.jatsBodyTransformations.createKeywords(doc, body, createElement);
|
|
70
|
+
jats_body_transformations_1.jatsBodyTransformations.orderTableFootnote(doc, body);
|
|
70
71
|
const node = jats_body_dom_parser_1.jatsBodyDOMParser.parse(body).firstChild;
|
|
71
72
|
if (!node) {
|
|
72
73
|
throw new Error('No content was parsed from the JATS article body');
|
|
@@ -130,10 +130,11 @@ const buildFootnote = (containingObject, contents, kind = 'footnote') => ({
|
|
|
130
130
|
kind,
|
|
131
131
|
});
|
|
132
132
|
exports.buildFootnote = buildFootnote;
|
|
133
|
-
const buildFootnotesOrder = (footnotesList) => ({
|
|
133
|
+
const buildFootnotesOrder = (footnotesList, containedObjectID) => ({
|
|
134
134
|
_id: (0, id_1.generateID)(json_schema_1.ObjectTypes.FootnotesOrder),
|
|
135
135
|
objectType: json_schema_1.ObjectTypes.FootnotesOrder,
|
|
136
136
|
footnotesList,
|
|
137
|
+
containedObjectID,
|
|
137
138
|
});
|
|
138
139
|
exports.buildFootnotesOrder = buildFootnotesOrder;
|
|
139
140
|
const buildCorresp = (contents) => ({
|
|
@@ -68,7 +68,6 @@ const getSupplements = (modelMap) => (0, exports.getModelsByType)(modelMap, json
|
|
|
68
68
|
const getKeywordGroups = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.KeywordGroup);
|
|
69
69
|
const getKeywords = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Keyword);
|
|
70
70
|
const getTitles = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Titles)[0];
|
|
71
|
-
const isFootnote = (0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.Footnote);
|
|
72
71
|
const hasParentSection = (id) => (section) => section.path &&
|
|
73
72
|
section.path.length > 1 &&
|
|
74
73
|
section.path[section.path.length - 2] === id;
|
|
@@ -311,23 +310,25 @@ class Decoder {
|
|
|
311
310
|
},
|
|
312
311
|
[json_schema_1.ObjectTypes.FootnotesElement]: (data) => {
|
|
313
312
|
const foonotesElementModel = data;
|
|
314
|
-
const collateByKind = foonotesElementModel.collateByKind || 'footnote';
|
|
315
313
|
const footnotesOfKind = [];
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
model
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
314
|
+
const footnoteOrder = (0, exports.getModelsByType)(this.modelMap, json_schema_1.ObjectTypes.FootnotesOrder).find((model) => model.containedObjectID === data._id);
|
|
315
|
+
if (footnoteOrder) {
|
|
316
|
+
footnoteOrder.footnotesList.map(({ id }) => {
|
|
317
|
+
const model = this.modelMap.get(id);
|
|
318
|
+
const collateByKind = foonotesElementModel.collateByKind || 'footnote';
|
|
319
|
+
if (model.kind === collateByKind) {
|
|
320
|
+
const comments = this.createCommentNodes(model);
|
|
321
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
322
|
+
const footnote = this.parseContents(model.contents || '<div></div>', undefined, this.getComments(model), {
|
|
323
|
+
topNode: schema_1.schema.nodes.footnote.create({
|
|
324
|
+
id: model._id,
|
|
325
|
+
kind: model.kind,
|
|
326
|
+
comments: comments.map((c) => c.attrs.id),
|
|
327
|
+
}),
|
|
328
|
+
});
|
|
329
|
+
footnotesOfKind.push(footnote);
|
|
330
|
+
}
|
|
331
|
+
});
|
|
331
332
|
}
|
|
332
333
|
return schema_1.schema.nodes.footnotes_element.create({
|
|
333
334
|
id: foonotesElementModel._id,
|
|
@@ -596,6 +596,9 @@ const encode = (node) => {
|
|
|
596
596
|
child.type !== schema_1.schema.nodes.inline_equation) {
|
|
597
597
|
return;
|
|
598
598
|
}
|
|
599
|
+
if (child.type === schema_1.schema.nodes.footnotes_element) {
|
|
600
|
+
addFootnotesOrderModel(child, models);
|
|
601
|
+
}
|
|
599
602
|
const { model, markers } = (0, exports.modelFromNode)(child, parent, path, priority);
|
|
600
603
|
markers.forEach((marker) => {
|
|
601
604
|
const comment = models.get(marker._id);
|
|
@@ -647,3 +650,9 @@ const generateElementOrder = (node, nodeType) => {
|
|
|
647
650
|
order.elements = ids;
|
|
648
651
|
return order;
|
|
649
652
|
};
|
|
653
|
+
const addFootnotesOrderModel = (child, models) => {
|
|
654
|
+
const footnoteList = [];
|
|
655
|
+
child.forEach((footnote, _, index) => footnoteList.push({ id: footnote.attrs.id, index }));
|
|
656
|
+
const footnotesOrder = (0, builders_1.buildFootnotesOrder)(footnoteList, child.attrs.id);
|
|
657
|
+
models.set(footnotesOrder._id, footnotesOrder);
|
|
658
|
+
};
|
|
@@ -15,8 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
19
|
-
const builders_1 = require("./builders");
|
|
18
|
+
exports.handleFootnotesOrder = exports.createOrderedFootnotesIDs = void 0;
|
|
20
19
|
const createOrderedFootnotesIDs = (doc) => {
|
|
21
20
|
const footnotesRefs = [...doc.querySelectorAll('xref[ref-type="fn"][rid]')];
|
|
22
21
|
const footnotes = [...doc.querySelectorAll('fn:not([fn-type])')];
|
|
@@ -59,5 +58,3 @@ const handleFootnotesOrder = (orderedFootnotesIDs, replacements, footnotesOrder)
|
|
|
59
58
|
footnotesOrder.footnotesList = footnotesList;
|
|
60
59
|
};
|
|
61
60
|
exports.handleFootnotesOrder = handleFootnotesOrder;
|
|
62
|
-
const createEmptyFootnotesOrder = () => (0, builders_1.buildFootnotesOrder)([]);
|
|
63
|
-
exports.createEmptyFootnotesOrder = createEmptyFootnotesOrder;
|
|
@@ -262,6 +262,16 @@ export const jatsBodyTransformations = {
|
|
|
262
262
|
}
|
|
263
263
|
});
|
|
264
264
|
},
|
|
265
|
+
orderTableFootnote(doc, body) {
|
|
266
|
+
const tableInlineFootnotesIds = new Set(Array.from(body.querySelectorAll('tbody > tr > td > xref[ref-type="fn"]').values()).map((inlineFootnote) => inlineFootnote.getAttribute('rid')));
|
|
267
|
+
const fnGroups = doc.querySelectorAll('table-wrap-foot > fn-group');
|
|
268
|
+
fnGroups.forEach((fnGroup) => {
|
|
269
|
+
const orderedFootnotes = Array.from(fnGroup.querySelectorAll('fn')).sort((fn) => tableInlineFootnotesIds.has(fn.getAttribute('id'))
|
|
270
|
+
? -1
|
|
271
|
+
: 0);
|
|
272
|
+
fnGroup.replaceChildren(...orderedFootnotes);
|
|
273
|
+
});
|
|
274
|
+
},
|
|
265
275
|
moveFloatsGroupToBody(doc, body, createElement) {
|
|
266
276
|
const group = doc.querySelector('floats-group');
|
|
267
277
|
if (group) {
|
|
@@ -63,6 +63,7 @@ export const parseJATSBody = (doc, body, references) => {
|
|
|
63
63
|
jatsBodyTransformations.createBackmatter(doc, body, createElement);
|
|
64
64
|
jatsBodyTransformations.createSuppleMaterials(doc, body, createElement);
|
|
65
65
|
jatsBodyTransformations.createKeywords(doc, body, createElement);
|
|
66
|
+
jatsBodyTransformations.orderTableFootnote(doc, body);
|
|
66
67
|
const node = jatsBodyDOMParser.parse(body).firstChild;
|
|
67
68
|
if (!node) {
|
|
68
69
|
throw new Error('No content was parsed from the JATS article body');
|
|
@@ -108,10 +108,11 @@ export const buildFootnote = (containingObject, contents, kind = 'footnote') =>
|
|
|
108
108
|
contents,
|
|
109
109
|
kind,
|
|
110
110
|
});
|
|
111
|
-
export const buildFootnotesOrder = (footnotesList) => ({
|
|
111
|
+
export const buildFootnotesOrder = (footnotesList, containedObjectID) => ({
|
|
112
112
|
_id: generateID(ObjectTypes.FootnotesOrder),
|
|
113
113
|
objectType: ObjectTypes.FootnotesOrder,
|
|
114
114
|
footnotesList,
|
|
115
|
+
containedObjectID,
|
|
115
116
|
});
|
|
116
117
|
export const buildCorresp = (contents) => ({
|
|
117
118
|
_id: generateID(ObjectTypes.Corresponding),
|
|
@@ -32,7 +32,7 @@ import { abstractsType, backmatterType, bodyType, } from '../lib/section-group-t
|
|
|
32
32
|
import { schema, } from '../schema';
|
|
33
33
|
import { buildTitles } from './builders';
|
|
34
34
|
import { insertHighlightMarkers } from './highlight-markers';
|
|
35
|
-
import { ExtraObjectTypes,
|
|
35
|
+
import { ExtraObjectTypes, isCommentAnnotation, isManuscript, } from './object-types';
|
|
36
36
|
import { chooseSectionLableName, chooseSectionNodeType, chooseSecType, getSectionGroupType, guessSectionCategory, } from './section-category';
|
|
37
37
|
import { timestamp } from './timestamp';
|
|
38
38
|
const warn = debug('manuscripts-transform');
|
|
@@ -59,7 +59,6 @@ const getSupplements = (modelMap) => getModelsByType(modelMap, ObjectTypes.Suppl
|
|
|
59
59
|
const getKeywordGroups = (modelMap) => getModelsByType(modelMap, ObjectTypes.KeywordGroup);
|
|
60
60
|
const getKeywords = (modelMap) => getModelsByType(modelMap, ObjectTypes.Keyword);
|
|
61
61
|
const getTitles = (modelMap) => getModelsByType(modelMap, ObjectTypes.Titles)[0];
|
|
62
|
-
const isFootnote = hasObjectType(ObjectTypes.Footnote);
|
|
63
62
|
const hasParentSection = (id) => (section) => section.path &&
|
|
64
63
|
section.path.length > 1 &&
|
|
65
64
|
section.path[section.path.length - 2] === id;
|
|
@@ -302,23 +301,25 @@ export class Decoder {
|
|
|
302
301
|
},
|
|
303
302
|
[ObjectTypes.FootnotesElement]: (data) => {
|
|
304
303
|
const foonotesElementModel = data;
|
|
305
|
-
const collateByKind = foonotesElementModel.collateByKind || 'footnote';
|
|
306
304
|
const footnotesOfKind = [];
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
model
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
305
|
+
const footnoteOrder = getModelsByType(this.modelMap, ObjectTypes.FootnotesOrder).find((model) => model.containedObjectID === data._id);
|
|
306
|
+
if (footnoteOrder) {
|
|
307
|
+
footnoteOrder.footnotesList.map(({ id }) => {
|
|
308
|
+
const model = this.modelMap.get(id);
|
|
309
|
+
const collateByKind = foonotesElementModel.collateByKind || 'footnote';
|
|
310
|
+
if (model.kind === collateByKind) {
|
|
311
|
+
const comments = this.createCommentNodes(model);
|
|
312
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
313
|
+
const footnote = this.parseContents(model.contents || '<div></div>', undefined, this.getComments(model), {
|
|
314
|
+
topNode: schema.nodes.footnote.create({
|
|
315
|
+
id: model._id,
|
|
316
|
+
kind: model.kind,
|
|
317
|
+
comments: comments.map((c) => c.attrs.id),
|
|
318
|
+
}),
|
|
319
|
+
});
|
|
320
|
+
footnotesOfKind.push(footnote);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
322
323
|
}
|
|
323
324
|
return schema.nodes.footnotes_element.create({
|
|
324
325
|
id: foonotesElementModel._id,
|
|
@@ -17,7 +17,7 @@ import { DOMSerializer } from 'prosemirror-model';
|
|
|
17
17
|
import serializeToXML from 'w3c-xmlserializer';
|
|
18
18
|
import { iterateChildren } from '../lib/utils';
|
|
19
19
|
import { hasGroup, isHighlightMarkerNode, isManuscriptNode, isSectionNode, schema, } from '../schema';
|
|
20
|
-
import { auxiliaryObjectTypes, buildAttribution, buildElementsOrder, } from './builders';
|
|
20
|
+
import { auxiliaryObjectTypes, buildAttribution, buildElementsOrder, buildFootnotesOrder, } from './builders';
|
|
21
21
|
import { extractCommentMarkers } from './highlight-markers';
|
|
22
22
|
import { nodeTypesMap } from './node-types';
|
|
23
23
|
import { buildSectionCategory } from './section-category';
|
|
@@ -587,6 +587,9 @@ export const encode = (node) => {
|
|
|
587
587
|
child.type !== schema.nodes.inline_equation) {
|
|
588
588
|
return;
|
|
589
589
|
}
|
|
590
|
+
if (child.type === schema.nodes.footnotes_element) {
|
|
591
|
+
addFootnotesOrderModel(child, models);
|
|
592
|
+
}
|
|
590
593
|
const { model, markers } = modelFromNode(child, parent, path, priority);
|
|
591
594
|
markers.forEach((marker) => {
|
|
592
595
|
const comment = models.get(marker._id);
|
|
@@ -637,3 +640,9 @@ const generateElementOrder = (node, nodeType) => {
|
|
|
637
640
|
order.elements = ids;
|
|
638
641
|
return order;
|
|
639
642
|
};
|
|
643
|
+
const addFootnotesOrderModel = (child, models) => {
|
|
644
|
+
const footnoteList = [];
|
|
645
|
+
child.forEach((footnote, _, index) => footnoteList.push({ id: footnote.attrs.id, index }));
|
|
646
|
+
const footnotesOrder = buildFootnotesOrder(footnoteList, child.attrs.id);
|
|
647
|
+
models.set(footnotesOrder._id, footnotesOrder);
|
|
648
|
+
};
|
|
@@ -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 { buildFootnotesOrder } from './builders';
|
|
17
16
|
export const createOrderedFootnotesIDs = (doc) => {
|
|
18
17
|
const footnotesRefs = [...doc.querySelectorAll('xref[ref-type="fn"][rid]')];
|
|
19
18
|
const footnotes = [...doc.querySelectorAll('fn:not([fn-type])')];
|
|
@@ -54,4 +53,3 @@ export const handleFootnotesOrder = (orderedFootnotesIDs, replacements, footnote
|
|
|
54
53
|
});
|
|
55
54
|
footnotesOrder.footnotesList = footnotesList;
|
|
56
55
|
};
|
|
57
|
-
export const createEmptyFootnotesOrder = () => buildFootnotesOrder([]);
|
|
@@ -32,6 +32,7 @@ export declare const jatsBodyTransformations: {
|
|
|
32
32
|
moveFootnotes(doc: Document, group: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
33
33
|
moveCaptionsToEnd(body: Element): void;
|
|
34
34
|
fixTables(body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
35
|
+
orderTableFootnote(doc: Document, body: Element): void;
|
|
35
36
|
moveFloatsGroupToBody(doc: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
36
37
|
createKeywords(document: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
37
38
|
createSuppleMaterials(document: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
@@ -46,7 +46,7 @@ export declare const buildComment: (target: string, contents?: string, selector?
|
|
|
46
46
|
export declare const buildNote: (target: string, source: 'EMAIL' | 'EDITOR' | 'DASHBOARD', contents?: string) => Build<ManuscriptNote>;
|
|
47
47
|
export declare const buildInlineMathFragment: (containingObject: string, TeXRepresentation: string) => Build<InlineMathFragment>;
|
|
48
48
|
export declare const buildFootnote: (containingObject: string, contents: string, kind?: 'footnote' | 'endnote') => Build<Footnote>;
|
|
49
|
-
export declare const buildFootnotesOrder: (footnotesList: FootnotesOrderIndexList) => Build<FootnotesOrder>;
|
|
49
|
+
export declare const buildFootnotesOrder: (footnotesList: FootnotesOrderIndexList, containedObjectID: string) => Build<FootnotesOrder>;
|
|
50
50
|
export declare const buildCorresp: (contents: string) => Build<Corresponding>;
|
|
51
51
|
export declare const buildSection: (priority?: number, path?: string[]) => Build<Section>;
|
|
52
52
|
export declare const buildParagraph: (placeholderInnerHTML: string) => Build<ParagraphElement>;
|
|
@@ -20,4 +20,3 @@ export type FootnotesOrderIndexList = {
|
|
|
20
20
|
}[];
|
|
21
21
|
export declare const createOrderedFootnotesIDs: (doc: Document) => string[];
|
|
22
22
|
export declare const handleFootnotesOrder: (orderedFootnotesIDs: Array<string>, replacements: Map<string, string>, footnotesOrder: FootnotesOrder) => void;
|
|
23
|
-
export declare const createEmptyFootnotesOrder: () => import("./builders").Build<FootnotesOrder>;
|
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": "2.1.
|
|
4
|
+
"version": "2.1.2",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-transform",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"version": "yarn build"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@manuscripts/json-schema": "^2.2.
|
|
33
|
-
"@manuscripts/library": "1.3.
|
|
32
|
+
"@manuscripts/json-schema": "^2.2.4",
|
|
33
|
+
"@manuscripts/library": "^1.3.3",
|
|
34
34
|
"debug": "^4.3.4",
|
|
35
35
|
"jszip": "^3.10.1",
|
|
36
36
|
"mathjax-full": "^3.2.2",
|