@manuscripts/transform 2.1.1-LEAN-3377-2 → 2.1.1-LEAN-3336-24
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-dom-parser.js +2 -16
- package/dist/cjs/jats/importer/jats-body-transformations.js +7 -26
- package/dist/cjs/jats/importer/parse-jats-article.js +0 -1
- package/dist/cjs/jats/jats-exporter.js +27 -3
- package/dist/cjs/schema/index.js +3 -5
- package/dist/cjs/schema/nodes/table.js +52 -30
- package/dist/cjs/schema/nodes/table_element.js +1 -1
- package/dist/cjs/transformer/builders.js +1 -2
- package/dist/cjs/transformer/decode.js +43 -35
- package/dist/cjs/transformer/encode.js +2 -10
- package/dist/cjs/transformer/footnotes-order.js +4 -1
- package/dist/es/jats/importer/jats-body-dom-parser.js +2 -16
- package/dist/es/jats/importer/jats-body-transformations.js +7 -26
- package/dist/es/jats/importer/parse-jats-article.js +0 -1
- package/dist/es/jats/jats-exporter.js +27 -3
- package/dist/es/schema/index.js +2 -4
- package/dist/es/schema/nodes/table.js +51 -29
- package/dist/es/schema/nodes/table_element.js +1 -1
- package/dist/es/transformer/builders.js +1 -2
- package/dist/es/transformer/decode.js +44 -36
- package/dist/es/transformer/encode.js +3 -11
- package/dist/es/transformer/footnotes-order.js +2 -0
- package/dist/types/jats/importer/jats-body-transformations.d.ts +0 -1
- package/dist/types/schema/index.d.ts +0 -1
- package/dist/types/schema/nodes/table.d.ts +5 -12
- package/dist/types/schema/types.d.ts +1 -1
- package/dist/types/transformer/builders.d.ts +1 -1
- package/dist/types/transformer/decode.d.ts +1 -0
- package/dist/types/transformer/footnotes-order.d.ts +1 -0
- package/package.json +5 -4
- package/dist/cjs/schema/nodes/table_row.js +0 -123
- package/dist/es/schema/nodes/table_row.js +0 -120
- package/dist/types/schema/nodes/table_row.d.ts +0 -41
|
@@ -525,23 +525,9 @@ const nodes = [
|
|
|
525
525
|
const element = node;
|
|
526
526
|
return {
|
|
527
527
|
id: element.getAttribute('id'),
|
|
528
|
-
suppressFooter: !element.querySelector('table > tfoot > tr'),
|
|
529
|
-
suppressHeader: !element.querySelector('table > thead > tr'),
|
|
530
528
|
};
|
|
531
529
|
},
|
|
532
530
|
},
|
|
533
|
-
{
|
|
534
|
-
tag: 'tbody',
|
|
535
|
-
skip: true,
|
|
536
|
-
},
|
|
537
|
-
{
|
|
538
|
-
tag: 'tfoot',
|
|
539
|
-
skip: true,
|
|
540
|
-
},
|
|
541
|
-
{
|
|
542
|
-
tag: 'thead',
|
|
543
|
-
skip: true,
|
|
544
|
-
},
|
|
545
531
|
{
|
|
546
532
|
tag: 'title',
|
|
547
533
|
node: 'section_title',
|
|
@@ -568,12 +554,12 @@ const nodes = [
|
|
|
568
554
|
},
|
|
569
555
|
{
|
|
570
556
|
tag: 'th',
|
|
571
|
-
node: '
|
|
557
|
+
node: 'table_header',
|
|
572
558
|
getAttrs: (node) => {
|
|
573
559
|
const element = node;
|
|
574
560
|
const colspan = element.getAttribute('colspan');
|
|
575
561
|
const rowspan = element.getAttribute('rowspan');
|
|
576
|
-
return Object.assign(Object.assign(Object.assign({
|
|
562
|
+
return Object.assign(Object.assign(Object.assign({}, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
|
|
577
563
|
},
|
|
578
564
|
},
|
|
579
565
|
{
|
|
@@ -239,8 +239,12 @@ exports.jatsBodyTransformations = {
|
|
|
239
239
|
}
|
|
240
240
|
},
|
|
241
241
|
fixTables(body, createElement) {
|
|
242
|
-
const
|
|
243
|
-
|
|
242
|
+
const tableWraps = body.querySelectorAll('table-wrap');
|
|
243
|
+
tableWraps.forEach((tableWrap) => {
|
|
244
|
+
const table = tableWrap.querySelector('table');
|
|
245
|
+
if (!table) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
244
248
|
const colgroup = table.querySelector('colgroup');
|
|
245
249
|
const cols = table.querySelectorAll('col');
|
|
246
250
|
if (!colgroup && table.firstChild && cols.length > 0) {
|
|
@@ -248,33 +252,10 @@ exports.jatsBodyTransformations = {
|
|
|
248
252
|
for (const col of cols) {
|
|
249
253
|
colgroup.appendChild(col);
|
|
250
254
|
}
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
const tbody = table.querySelector('tbody');
|
|
254
|
-
if (tbody) {
|
|
255
|
-
const headerRow = table.querySelector('thead > tr');
|
|
256
|
-
if (!headerRow) {
|
|
257
|
-
const tr = createElement('tr');
|
|
258
|
-
tbody.insertBefore(tr, tbody.firstElementChild);
|
|
259
|
-
}
|
|
260
|
-
const footerRow = table.querySelector('tfoot > tr');
|
|
261
|
-
if (!footerRow) {
|
|
262
|
-
const tr = createElement('tr');
|
|
263
|
-
tbody.appendChild(tr);
|
|
264
|
-
}
|
|
255
|
+
tableWrap.insertBefore(colgroup, table.nextSibling);
|
|
265
256
|
}
|
|
266
257
|
});
|
|
267
258
|
},
|
|
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
|
-
},
|
|
278
259
|
moveFloatsGroupToBody(doc, body, createElement) {
|
|
279
260
|
const group = doc.querySelector('floats-group');
|
|
280
261
|
if (group) {
|
|
@@ -67,7 +67,6 @@ 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);
|
|
71
70
|
const node = jats_body_dom_parser_1.jatsBodyDOMParser.parse(body).firstChild;
|
|
72
71
|
if (!node) {
|
|
73
72
|
throw new Error('No content was parsed from the JATS article body');
|
|
@@ -873,9 +873,13 @@ class JATSExporter {
|
|
|
873
873
|
element.setAttribute('position', 'anchor');
|
|
874
874
|
return element;
|
|
875
875
|
},
|
|
876
|
-
table_body: () => ['tbody', 0],
|
|
877
876
|
table_cell: (node) => [
|
|
878
|
-
|
|
877
|
+
'td',
|
|
878
|
+
Object.assign(Object.assign({ valign: node.attrs.valign, align: node.attrs.align, scope: node.attrs.scope, style: node.attrs.style }, (node.attrs.rowspan > 1 && { rowspan: node.attrs.rowspan })), (node.attrs.colspan > 1 && { colspan: node.attrs.colspan })),
|
|
879
|
+
0,
|
|
880
|
+
],
|
|
881
|
+
table_header: (node) => [
|
|
882
|
+
'th',
|
|
879
883
|
Object.assign(Object.assign({ valign: node.attrs.valign, align: node.attrs.align, scope: node.attrs.scope, style: node.attrs.style }, (node.attrs.rowspan > 1 && { rowspan: node.attrs.rowspan })), (node.attrs.colspan > 1 && { colspan: node.attrs.colspan })),
|
|
880
884
|
0,
|
|
881
885
|
],
|
|
@@ -956,6 +960,26 @@ class JATSExporter {
|
|
|
956
960
|
element.appendChild(this.serializeNode(childNode));
|
|
957
961
|
}
|
|
958
962
|
};
|
|
963
|
+
const appendTable = (element, node) => {
|
|
964
|
+
const tableNode = findChildNodeOfType(node, node.type.schema.nodes.table);
|
|
965
|
+
const colGroupNode = findChildNodeOfType(node, node.type.schema.nodes.table_colgroup);
|
|
966
|
+
if (!tableNode) {
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
const table = this.serializeNode(tableNode);
|
|
970
|
+
const tbodyElement = this.document.createElement('tbody');
|
|
971
|
+
while (table.firstChild) {
|
|
972
|
+
const child = table.firstChild;
|
|
973
|
+
table.removeChild(child);
|
|
974
|
+
tbodyElement.appendChild(child);
|
|
975
|
+
}
|
|
976
|
+
table.appendChild(tbodyElement);
|
|
977
|
+
if (colGroupNode) {
|
|
978
|
+
const colGroup = this.serializeNode(colGroupNode);
|
|
979
|
+
table.insertBefore(colGroup, table.firstChild);
|
|
980
|
+
}
|
|
981
|
+
element.appendChild(table);
|
|
982
|
+
};
|
|
959
983
|
const createFigureElement = (node, nodeName, contentNodeType, figType) => {
|
|
960
984
|
const element = createElement(node, nodeName);
|
|
961
985
|
if (figType) {
|
|
@@ -976,7 +1000,7 @@ class JATSExporter {
|
|
|
976
1000
|
const element = createElement(node, nodeName);
|
|
977
1001
|
appendLabels(element, node);
|
|
978
1002
|
appendChildNodeOfType(element, node, node.type.schema.nodes.figcaption);
|
|
979
|
-
|
|
1003
|
+
appendTable(element, node);
|
|
980
1004
|
appendChildNodeOfType(element, node, node.type.schema.nodes.table_element_footer);
|
|
981
1005
|
if ((0, node_types_1.isExecutableNodeType)(node.type)) {
|
|
982
1006
|
processExecutableNode(node, element);
|
package/dist/cjs/schema/index.js
CHANGED
|
@@ -87,7 +87,6 @@ const table_1 = require("./nodes/table");
|
|
|
87
87
|
const table_col_1 = require("./nodes/table_col");
|
|
88
88
|
const table_element_1 = require("./nodes/table_element");
|
|
89
89
|
const table_element_footer_1 = require("./nodes/table_element_footer");
|
|
90
|
-
const table_row_1 = require("./nodes/table_row");
|
|
91
90
|
const text_1 = require("./nodes/text");
|
|
92
91
|
const title_1 = require("./nodes/title");
|
|
93
92
|
const toc_element_1 = require("./nodes/toc_element");
|
|
@@ -137,7 +136,6 @@ __exportStar(require("./nodes/section_title"), exports);
|
|
|
137
136
|
__exportStar(require("./nodes/table"), exports);
|
|
138
137
|
__exportStar(require("./nodes/table_col"), exports);
|
|
139
138
|
__exportStar(require("./nodes/table_element"), exports);
|
|
140
|
-
__exportStar(require("./nodes/table_row"), exports);
|
|
141
139
|
__exportStar(require("./nodes/text"), exports);
|
|
142
140
|
__exportStar(require("./nodes/toc_element"), exports);
|
|
143
141
|
__exportStar(require("./nodes/toc_section"), exports);
|
|
@@ -213,10 +211,9 @@ exports.schema = new prosemirror_model_1.Schema({
|
|
|
213
211
|
section_title: section_title_1.sectionTitle,
|
|
214
212
|
section_title_plain: section_title_1.sectionTitle,
|
|
215
213
|
table: table_1.table,
|
|
216
|
-
|
|
217
|
-
table_cell: table_row_1.tableCell,
|
|
214
|
+
table_cell: table_1.tableCell,
|
|
218
215
|
table_element: table_element_1.tableElement,
|
|
219
|
-
table_row:
|
|
216
|
+
table_row: table_1.tableRow,
|
|
220
217
|
table_col: table_col_1.tableCol,
|
|
221
218
|
table_colgroup: table_col_1.tableColGroup,
|
|
222
219
|
text: text_1.text,
|
|
@@ -230,5 +227,6 @@ exports.schema = new prosemirror_model_1.Schema({
|
|
|
230
227
|
contributors: contributors_1.contributors,
|
|
231
228
|
supplements: supplements_1.supplements,
|
|
232
229
|
supplement: supplement_1.supplement,
|
|
230
|
+
table_header: table_1.tableHeader,
|
|
233
231
|
},
|
|
234
232
|
});
|
|
@@ -15,20 +15,57 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
18
|
+
exports.tableHeader = exports.tableCell = exports.tableRow = exports.table = void 0;
|
|
19
|
+
const prosemirror_tables_1 = require("prosemirror-tables");
|
|
20
|
+
function createCellAttribute(attributeName, defaultValue = null, customGetFromDOM, customSetDOMAttr) {
|
|
21
|
+
return {
|
|
22
|
+
default: defaultValue,
|
|
23
|
+
getFromDOM(dom) {
|
|
24
|
+
if (customGetFromDOM) {
|
|
25
|
+
return customGetFromDOM(dom);
|
|
26
|
+
}
|
|
27
|
+
return dom.getAttribute(attributeName);
|
|
28
|
+
},
|
|
29
|
+
setDOMAttr(value, attrs) {
|
|
30
|
+
if (customSetDOMAttr) {
|
|
31
|
+
customSetDOMAttr(value, attrs);
|
|
32
|
+
}
|
|
33
|
+
else if (value) {
|
|
34
|
+
attrs[attributeName] = value;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const tableOptions = {
|
|
40
|
+
cellContent: 'inline*',
|
|
41
|
+
cellAttributes: {
|
|
42
|
+
placeholder: createCellAttribute('data-placeholder-text', 'Data', (dom) => dom.getAttribute('data-placeholder-text') || ''),
|
|
43
|
+
valign: createCellAttribute('valign'),
|
|
44
|
+
align: createCellAttribute('align'),
|
|
45
|
+
scope: createCellAttribute('scope'),
|
|
46
|
+
style: createCellAttribute('style'),
|
|
47
|
+
colspan: createCellAttribute('colspan', 1, (dom) => Number(dom.getAttribute('colspan') || 1), (value, attrs) => {
|
|
48
|
+
if (value && value !== 1) {
|
|
49
|
+
attrs['colspan'] = String(value);
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
rowspan: createCellAttribute('rowspan', 1, (dom) => Number(dom.getAttribute('rowspan') || 1), (value, attrs) => {
|
|
53
|
+
if (value && value !== 1) {
|
|
54
|
+
attrs['rowspan'] = String(value);
|
|
55
|
+
}
|
|
56
|
+
}),
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const tableNodes = (0, prosemirror_tables_1.tableNodes)(tableOptions);
|
|
19
60
|
exports.table = {
|
|
20
|
-
content: 'table_colgroup? table_body',
|
|
21
|
-
tableRole: 'table',
|
|
22
|
-
isolating: true,
|
|
23
|
-
group: 'block',
|
|
24
|
-
selectable: false,
|
|
25
61
|
attrs: {
|
|
26
62
|
id: { default: '' },
|
|
27
|
-
headerRows: { default: 1 },
|
|
28
|
-
footerRows: { default: 1 },
|
|
29
63
|
dataTracked: { default: null },
|
|
30
|
-
comments: { default: null },
|
|
31
64
|
},
|
|
65
|
+
content: 'table_row+',
|
|
66
|
+
tableRole: 'table',
|
|
67
|
+
isolating: true,
|
|
68
|
+
group: 'block',
|
|
32
69
|
parseDOM: [
|
|
33
70
|
{
|
|
34
71
|
tag: 'table',
|
|
@@ -36,35 +73,20 @@ exports.table = {
|
|
|
36
73
|
const dom = p;
|
|
37
74
|
return {
|
|
38
75
|
id: dom.getAttribute('id'),
|
|
39
|
-
headerRows: dom.dataset && dom.dataset['header-rows'],
|
|
40
|
-
footerRows: dom.dataset && dom.dataset['footer-rows'],
|
|
41
76
|
};
|
|
42
77
|
},
|
|
43
78
|
},
|
|
44
79
|
],
|
|
45
|
-
toDOM
|
|
46
|
-
const tableNode = node;
|
|
80
|
+
toDOM(node) {
|
|
47
81
|
return [
|
|
48
82
|
'table',
|
|
49
83
|
{
|
|
50
|
-
id:
|
|
51
|
-
'data-header-rows': String(node.attrs.headerRows),
|
|
52
|
-
'data-footer-rows': String(node.attrs.footerRows),
|
|
84
|
+
id: node.attrs.id,
|
|
53
85
|
},
|
|
54
|
-
0,
|
|
86
|
+
['tbody', 0],
|
|
55
87
|
];
|
|
56
88
|
},
|
|
57
89
|
};
|
|
58
|
-
exports.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
tableRole: 'table',
|
|
62
|
-
parseDOM: [
|
|
63
|
-
{
|
|
64
|
-
tag: 'tbody',
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
toDOM() {
|
|
68
|
-
return ['tbody', 0];
|
|
69
|
-
},
|
|
70
|
-
};
|
|
90
|
+
exports.tableRow = Object.assign(Object.assign({}, tableNodes.table_row), { attrs: Object.assign(Object.assign({}, tableNodes.table_row.attrs), { dataTracked: { default: null } }) });
|
|
91
|
+
exports.tableCell = Object.assign(Object.assign({}, tableNodes.table_cell), { attrs: Object.assign(Object.assign({}, tableNodes.table_cell.attrs), { dataTracked: { default: null } }) });
|
|
92
|
+
exports.tableHeader = Object.assign(Object.assign({}, tableNodes.table_header), { attrs: Object.assign(Object.assign({}, tableNodes.table_header.attrs), { dataTracked: { default: null } }) });
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.tableElement = void 0;
|
|
19
19
|
exports.tableElement = {
|
|
20
|
-
content: '(table | placeholder) table_element_footer? figcaption? (listing | placeholder)',
|
|
20
|
+
content: '(table | placeholder) table_colgroup? table_element_footer? figcaption? (listing | placeholder)',
|
|
21
21
|
attrs: {
|
|
22
22
|
id: { default: '' },
|
|
23
23
|
paragraphStyle: { default: '' },
|
|
@@ -130,11 +130,10 @@ const buildFootnote = (containingObject, contents, kind = 'footnote') => ({
|
|
|
130
130
|
kind,
|
|
131
131
|
});
|
|
132
132
|
exports.buildFootnote = buildFootnote;
|
|
133
|
-
const buildFootnotesOrder = (footnotesList
|
|
133
|
+
const buildFootnotesOrder = (footnotesList) => ({
|
|
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,
|
|
138
137
|
});
|
|
139
138
|
exports.buildFootnotesOrder = buildFootnotesOrder;
|
|
140
139
|
const buildCorresp = (contents) => ({
|
|
@@ -68,6 +68,7 @@ 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);
|
|
71
72
|
const hasParentSection = (id) => (section) => section.path &&
|
|
72
73
|
section.path.length > 1 &&
|
|
73
74
|
section.path[section.path.length - 2] === id;
|
|
@@ -310,25 +311,23 @@ class Decoder {
|
|
|
310
311
|
},
|
|
311
312
|
[json_schema_1.ObjectTypes.FootnotesElement]: (data) => {
|
|
312
313
|
const foonotesElementModel = data;
|
|
314
|
+
const collateByKind = foonotesElementModel.collateByKind || 'footnote';
|
|
313
315
|
const footnotesOfKind = [];
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
footnotesOfKind.push(footnote);
|
|
330
|
-
}
|
|
331
|
-
});
|
|
316
|
+
for (const model of this.modelMap.values()) {
|
|
317
|
+
if (isFootnote(model) &&
|
|
318
|
+
model.kind === collateByKind &&
|
|
319
|
+
model.containingObject === foonotesElementModel._id) {
|
|
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
|
+
}
|
|
332
331
|
}
|
|
333
332
|
return schema_1.schema.nodes.footnotes_element.create({
|
|
334
333
|
id: foonotesElementModel._id,
|
|
@@ -558,33 +557,32 @@ class Decoder {
|
|
|
558
557
|
},
|
|
559
558
|
[json_schema_1.ObjectTypes.Table]: (data) => {
|
|
560
559
|
const model = data;
|
|
561
|
-
|
|
562
|
-
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
563
|
-
return this.parseContents(model.contents, undefined, this.getComments(model), {
|
|
560
|
+
return this.parseContents(model.contents, undefined, [], {
|
|
564
561
|
topNode: schema_1.schema.nodes.table.create({
|
|
565
562
|
id: model._id,
|
|
566
|
-
comments: comments.map((c) => c.attrs.id),
|
|
567
563
|
}),
|
|
568
564
|
});
|
|
569
565
|
},
|
|
570
566
|
[json_schema_1.ObjectTypes.TableElement]: (data) => {
|
|
571
567
|
const model = data;
|
|
572
568
|
const table = this.createTable(model);
|
|
569
|
+
const tableColGroup = this.createTableColGroup(model);
|
|
573
570
|
const tableElementFooter = this.createTableElementFooter(model);
|
|
574
571
|
const figcaption = this.getFigcaption(model);
|
|
575
572
|
const comments = this.createCommentNodes(model);
|
|
576
573
|
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
577
|
-
const content =
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
if (model.listingID) {
|
|
581
|
-
const listing = this.createListing(model.listingID);
|
|
582
|
-
content.push(listing);
|
|
574
|
+
const content = [table];
|
|
575
|
+
if (tableColGroup) {
|
|
576
|
+
content.push(tableColGroup);
|
|
583
577
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
content.push(listing);
|
|
578
|
+
if (tableElementFooter) {
|
|
579
|
+
content.push(tableElementFooter);
|
|
587
580
|
}
|
|
581
|
+
content.push(figcaption);
|
|
582
|
+
const listing = model.listingID
|
|
583
|
+
? this.createListing(model.listingID)
|
|
584
|
+
: schema_1.schema.nodes.listing.create();
|
|
585
|
+
content.push(listing);
|
|
588
586
|
return schema_1.schema.nodes.table_element.createChecked({
|
|
589
587
|
id: model._id,
|
|
590
588
|
table: model.containedObjectID,
|
|
@@ -773,23 +771,33 @@ class Decoder {
|
|
|
773
771
|
this.allowMissingElements = allowMissingElements;
|
|
774
772
|
}
|
|
775
773
|
createTable(model) {
|
|
776
|
-
const
|
|
777
|
-
const tableModel = this.getModel(
|
|
774
|
+
const tableID = model.containedObjectID;
|
|
775
|
+
const tableModel = this.getModel(tableID);
|
|
778
776
|
let table;
|
|
779
777
|
if (tableModel) {
|
|
780
778
|
table = this.decode(tableModel);
|
|
781
779
|
}
|
|
782
780
|
else if (this.allowMissingElements) {
|
|
783
781
|
table = schema_1.schema.nodes.placeholder.create({
|
|
784
|
-
id:
|
|
782
|
+
id: tableID,
|
|
785
783
|
label: 'A table',
|
|
786
784
|
});
|
|
787
785
|
}
|
|
788
786
|
else {
|
|
789
|
-
throw new errors_1.MissingElement(
|
|
787
|
+
throw new errors_1.MissingElement(tableID);
|
|
790
788
|
}
|
|
791
789
|
return table;
|
|
792
790
|
}
|
|
791
|
+
createTableColGroup(model) {
|
|
792
|
+
const tableID = model.containedObjectID;
|
|
793
|
+
const tableModel = this.getModel(tableID);
|
|
794
|
+
if (!tableModel || !tableModel.contents.includes('<colgroup>')) {
|
|
795
|
+
return undefined;
|
|
796
|
+
}
|
|
797
|
+
return this.parseContents(tableModel.contents, undefined, [], {
|
|
798
|
+
topNode: schema_1.schema.nodes.table_colgroup.create(),
|
|
799
|
+
});
|
|
800
|
+
}
|
|
793
801
|
createTableElementFooter(model) {
|
|
794
802
|
const tableElementFooterID = model.tableElementFooterID;
|
|
795
803
|
if (!tableElementFooterID) {
|
|
@@ -115,8 +115,9 @@ function buildTableColGroup(cols) {
|
|
|
115
115
|
}
|
|
116
116
|
const tableContents = (node, parent) => {
|
|
117
117
|
const input = serializer.serializeNode(node);
|
|
118
|
+
const parentInput = serializer.serializeNode(parent);
|
|
118
119
|
const output = document.createElement('table');
|
|
119
|
-
const colgroup = buildTableColGroup(Array.from(
|
|
120
|
+
const colgroup = buildTableColGroup(Array.from(parentInput.querySelectorAll('col')));
|
|
120
121
|
if (colgroup) {
|
|
121
122
|
output.appendChild(colgroup);
|
|
122
123
|
}
|
|
@@ -596,9 +597,6 @@ const encode = (node) => {
|
|
|
596
597
|
child.type !== schema_1.schema.nodes.inline_equation) {
|
|
597
598
|
return;
|
|
598
599
|
}
|
|
599
|
-
if (child.type === schema_1.schema.nodes.footnotes_element) {
|
|
600
|
-
addFootnotesOrderModel(child, models);
|
|
601
|
-
}
|
|
602
600
|
const { model, markers } = (0, exports.modelFromNode)(child, parent, path, priority);
|
|
603
601
|
markers.forEach((marker) => {
|
|
604
602
|
const comment = models.get(marker._id);
|
|
@@ -650,9 +648,3 @@ const generateElementOrder = (node, nodeType) => {
|
|
|
650
648
|
order.elements = ids;
|
|
651
649
|
return order;
|
|
652
650
|
};
|
|
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,7 +15,8 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.handleFootnotesOrder = exports.createOrderedFootnotesIDs = void 0;
|
|
18
|
+
exports.createEmptyFootnotesOrder = exports.handleFootnotesOrder = exports.createOrderedFootnotesIDs = void 0;
|
|
19
|
+
const builders_1 = require("./builders");
|
|
19
20
|
const createOrderedFootnotesIDs = (doc) => {
|
|
20
21
|
const footnotesRefs = [...doc.querySelectorAll('xref[ref-type="fn"][rid]')];
|
|
21
22
|
const footnotes = [...doc.querySelectorAll('fn:not([fn-type])')];
|
|
@@ -58,3 +59,5 @@ const handleFootnotesOrder = (orderedFootnotesIDs, replacements, footnotesOrder)
|
|
|
58
59
|
footnotesOrder.footnotesList = footnotesList;
|
|
59
60
|
};
|
|
60
61
|
exports.handleFootnotesOrder = handleFootnotesOrder;
|
|
62
|
+
const createEmptyFootnotesOrder = () => (0, builders_1.buildFootnotesOrder)([]);
|
|
63
|
+
exports.createEmptyFootnotesOrder = createEmptyFootnotesOrder;
|
|
@@ -519,23 +519,9 @@ const nodes = [
|
|
|
519
519
|
const element = node;
|
|
520
520
|
return {
|
|
521
521
|
id: element.getAttribute('id'),
|
|
522
|
-
suppressFooter: !element.querySelector('table > tfoot > tr'),
|
|
523
|
-
suppressHeader: !element.querySelector('table > thead > tr'),
|
|
524
522
|
};
|
|
525
523
|
},
|
|
526
524
|
},
|
|
527
|
-
{
|
|
528
|
-
tag: 'tbody',
|
|
529
|
-
skip: true,
|
|
530
|
-
},
|
|
531
|
-
{
|
|
532
|
-
tag: 'tfoot',
|
|
533
|
-
skip: true,
|
|
534
|
-
},
|
|
535
|
-
{
|
|
536
|
-
tag: 'thead',
|
|
537
|
-
skip: true,
|
|
538
|
-
},
|
|
539
525
|
{
|
|
540
526
|
tag: 'title',
|
|
541
527
|
node: 'section_title',
|
|
@@ -562,12 +548,12 @@ const nodes = [
|
|
|
562
548
|
},
|
|
563
549
|
{
|
|
564
550
|
tag: 'th',
|
|
565
|
-
node: '
|
|
551
|
+
node: 'table_header',
|
|
566
552
|
getAttrs: (node) => {
|
|
567
553
|
const element = node;
|
|
568
554
|
const colspan = element.getAttribute('colspan');
|
|
569
555
|
const rowspan = element.getAttribute('rowspan');
|
|
570
|
-
return Object.assign(Object.assign(Object.assign({
|
|
556
|
+
return Object.assign(Object.assign(Object.assign({}, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
|
|
571
557
|
},
|
|
572
558
|
},
|
|
573
559
|
{
|
|
@@ -236,8 +236,12 @@ export const jatsBodyTransformations = {
|
|
|
236
236
|
}
|
|
237
237
|
},
|
|
238
238
|
fixTables(body, createElement) {
|
|
239
|
-
const
|
|
240
|
-
|
|
239
|
+
const tableWraps = body.querySelectorAll('table-wrap');
|
|
240
|
+
tableWraps.forEach((tableWrap) => {
|
|
241
|
+
const table = tableWrap.querySelector('table');
|
|
242
|
+
if (!table) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
241
245
|
const colgroup = table.querySelector('colgroup');
|
|
242
246
|
const cols = table.querySelectorAll('col');
|
|
243
247
|
if (!colgroup && table.firstChild && cols.length > 0) {
|
|
@@ -245,33 +249,10 @@ export const jatsBodyTransformations = {
|
|
|
245
249
|
for (const col of cols) {
|
|
246
250
|
colgroup.appendChild(col);
|
|
247
251
|
}
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
const tbody = table.querySelector('tbody');
|
|
251
|
-
if (tbody) {
|
|
252
|
-
const headerRow = table.querySelector('thead > tr');
|
|
253
|
-
if (!headerRow) {
|
|
254
|
-
const tr = createElement('tr');
|
|
255
|
-
tbody.insertBefore(tr, tbody.firstElementChild);
|
|
256
|
-
}
|
|
257
|
-
const footerRow = table.querySelector('tfoot > tr');
|
|
258
|
-
if (!footerRow) {
|
|
259
|
-
const tr = createElement('tr');
|
|
260
|
-
tbody.appendChild(tr);
|
|
261
|
-
}
|
|
252
|
+
tableWrap.insertBefore(colgroup, table.nextSibling);
|
|
262
253
|
}
|
|
263
254
|
});
|
|
264
255
|
},
|
|
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
|
-
},
|
|
275
256
|
moveFloatsGroupToBody(doc, body, createElement) {
|
|
276
257
|
const group = doc.querySelector('floats-group');
|
|
277
258
|
if (group) {
|
|
@@ -63,7 +63,6 @@ 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);
|
|
67
66
|
const node = jatsBodyDOMParser.parse(body).firstChild;
|
|
68
67
|
if (!node) {
|
|
69
68
|
throw new Error('No content was parsed from the JATS article body');
|
|
@@ -865,9 +865,13 @@ export class JATSExporter {
|
|
|
865
865
|
element.setAttribute('position', 'anchor');
|
|
866
866
|
return element;
|
|
867
867
|
},
|
|
868
|
-
table_body: () => ['tbody', 0],
|
|
869
868
|
table_cell: (node) => [
|
|
870
|
-
|
|
869
|
+
'td',
|
|
870
|
+
Object.assign(Object.assign({ valign: node.attrs.valign, align: node.attrs.align, scope: node.attrs.scope, style: node.attrs.style }, (node.attrs.rowspan > 1 && { rowspan: node.attrs.rowspan })), (node.attrs.colspan > 1 && { colspan: node.attrs.colspan })),
|
|
871
|
+
0,
|
|
872
|
+
],
|
|
873
|
+
table_header: (node) => [
|
|
874
|
+
'th',
|
|
871
875
|
Object.assign(Object.assign({ valign: node.attrs.valign, align: node.attrs.align, scope: node.attrs.scope, style: node.attrs.style }, (node.attrs.rowspan > 1 && { rowspan: node.attrs.rowspan })), (node.attrs.colspan > 1 && { colspan: node.attrs.colspan })),
|
|
872
876
|
0,
|
|
873
877
|
],
|
|
@@ -948,6 +952,26 @@ export class JATSExporter {
|
|
|
948
952
|
element.appendChild(this.serializeNode(childNode));
|
|
949
953
|
}
|
|
950
954
|
};
|
|
955
|
+
const appendTable = (element, node) => {
|
|
956
|
+
const tableNode = findChildNodeOfType(node, node.type.schema.nodes.table);
|
|
957
|
+
const colGroupNode = findChildNodeOfType(node, node.type.schema.nodes.table_colgroup);
|
|
958
|
+
if (!tableNode) {
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
const table = this.serializeNode(tableNode);
|
|
962
|
+
const tbodyElement = this.document.createElement('tbody');
|
|
963
|
+
while (table.firstChild) {
|
|
964
|
+
const child = table.firstChild;
|
|
965
|
+
table.removeChild(child);
|
|
966
|
+
tbodyElement.appendChild(child);
|
|
967
|
+
}
|
|
968
|
+
table.appendChild(tbodyElement);
|
|
969
|
+
if (colGroupNode) {
|
|
970
|
+
const colGroup = this.serializeNode(colGroupNode);
|
|
971
|
+
table.insertBefore(colGroup, table.firstChild);
|
|
972
|
+
}
|
|
973
|
+
element.appendChild(table);
|
|
974
|
+
};
|
|
951
975
|
const createFigureElement = (node, nodeName, contentNodeType, figType) => {
|
|
952
976
|
const element = createElement(node, nodeName);
|
|
953
977
|
if (figType) {
|
|
@@ -968,7 +992,7 @@ export class JATSExporter {
|
|
|
968
992
|
const element = createElement(node, nodeName);
|
|
969
993
|
appendLabels(element, node);
|
|
970
994
|
appendChildNodeOfType(element, node, node.type.schema.nodes.figcaption);
|
|
971
|
-
|
|
995
|
+
appendTable(element, node);
|
|
972
996
|
appendChildNodeOfType(element, node, node.type.schema.nodes.table_element_footer);
|
|
973
997
|
if (isExecutableNodeType(node.type)) {
|
|
974
998
|
processExecutableNode(node, element);
|