@manuscripts/transform 2.1.1-LEAN-3336-23 → 2.1.1-LEAN-3377-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-dom-parser.js +16 -2
- package/dist/cjs/jats/importer/jats-body-transformations.js +26 -7
- package/dist/cjs/jats/importer/parse-jats-article.js +1 -0
- package/dist/cjs/jats/jats-exporter.js +3 -27
- package/dist/cjs/schema/index.js +5 -3
- package/dist/cjs/schema/nodes/table.js +30 -52
- package/dist/cjs/schema/nodes/table_element.js +1 -1
- package/dist/cjs/schema/nodes/table_row.js +123 -0
- package/dist/cjs/transformer/builders.js +2 -1
- package/dist/cjs/transformer/decode.js +25 -37
- package/dist/cjs/transformer/encode.js +10 -2
- package/dist/cjs/transformer/footnotes-order.js +1 -4
- package/dist/es/jats/importer/jats-body-dom-parser.js +16 -2
- package/dist/es/jats/importer/jats-body-transformations.js +26 -7
- package/dist/es/jats/importer/parse-jats-article.js +1 -0
- package/dist/es/jats/jats-exporter.js +3 -27
- package/dist/es/schema/index.js +4 -2
- package/dist/es/schema/nodes/table.js +29 -51
- package/dist/es/schema/nodes/table_element.js +1 -1
- package/dist/es/schema/nodes/table_row.js +120 -0
- package/dist/es/transformer/builders.js +2 -1
- package/dist/es/transformer/decode.js +26 -38
- package/dist/es/transformer/encode.js +11 -3
- package/dist/es/transformer/footnotes-order.js +0 -2
- package/dist/types/jats/importer/jats-body-transformations.d.ts +1 -0
- package/dist/types/schema/index.d.ts +1 -0
- package/dist/types/schema/nodes/table.d.ts +12 -5
- package/dist/types/schema/nodes/table_row.d.ts +41 -0
- 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 +0 -1
- package/dist/types/transformer/footnotes-order.d.ts +0 -1
- package/package.json +4 -5
|
@@ -525,9 +525,23 @@ 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'),
|
|
528
530
|
};
|
|
529
531
|
},
|
|
530
532
|
},
|
|
533
|
+
{
|
|
534
|
+
tag: 'tbody',
|
|
535
|
+
skip: true,
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
tag: 'tfoot',
|
|
539
|
+
skip: true,
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
tag: 'thead',
|
|
543
|
+
skip: true,
|
|
544
|
+
},
|
|
531
545
|
{
|
|
532
546
|
tag: 'title',
|
|
533
547
|
node: 'section_title',
|
|
@@ -554,12 +568,12 @@ const nodes = [
|
|
|
554
568
|
},
|
|
555
569
|
{
|
|
556
570
|
tag: 'th',
|
|
557
|
-
node: '
|
|
571
|
+
node: 'table_cell',
|
|
558
572
|
getAttrs: (node) => {
|
|
559
573
|
const element = node;
|
|
560
574
|
const colspan = element.getAttribute('colspan');
|
|
561
575
|
const rowspan = element.getAttribute('rowspan');
|
|
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') });
|
|
576
|
+
return Object.assign(Object.assign(Object.assign({ celltype: 'th' }, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
|
|
563
577
|
},
|
|
564
578
|
},
|
|
565
579
|
{
|
|
@@ -239,12 +239,8 @@ exports.jatsBodyTransformations = {
|
|
|
239
239
|
}
|
|
240
240
|
},
|
|
241
241
|
fixTables(body, createElement) {
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
const table = tableWrap.querySelector('table');
|
|
245
|
-
if (!table) {
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
242
|
+
const tables = body.querySelectorAll('table-wrap > table');
|
|
243
|
+
tables.forEach((table) => {
|
|
248
244
|
const colgroup = table.querySelector('colgroup');
|
|
249
245
|
const cols = table.querySelectorAll('col');
|
|
250
246
|
if (!colgroup && table.firstChild && cols.length > 0) {
|
|
@@ -252,10 +248,33 @@ exports.jatsBodyTransformations = {
|
|
|
252
248
|
for (const col of cols) {
|
|
253
249
|
colgroup.appendChild(col);
|
|
254
250
|
}
|
|
255
|
-
|
|
251
|
+
table.insertBefore(colgroup, table.firstChild);
|
|
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
|
+
}
|
|
256
265
|
}
|
|
257
266
|
});
|
|
258
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
|
+
},
|
|
259
278
|
moveFloatsGroupToBody(doc, body, createElement) {
|
|
260
279
|
const group = doc.querySelector('floats-group');
|
|
261
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');
|
|
@@ -873,13 +873,9 @@ class JATSExporter {
|
|
|
873
873
|
element.setAttribute('position', 'anchor');
|
|
874
874
|
return element;
|
|
875
875
|
},
|
|
876
|
+
table_body: () => ['tbody', 0],
|
|
876
877
|
table_cell: (node) => [
|
|
877
|
-
|
|
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',
|
|
878
|
+
node.attrs.celltype,
|
|
883
879
|
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 })),
|
|
884
880
|
0,
|
|
885
881
|
],
|
|
@@ -960,26 +956,6 @@ class JATSExporter {
|
|
|
960
956
|
element.appendChild(this.serializeNode(childNode));
|
|
961
957
|
}
|
|
962
958
|
};
|
|
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
|
-
};
|
|
983
959
|
const createFigureElement = (node, nodeName, contentNodeType, figType) => {
|
|
984
960
|
const element = createElement(node, nodeName);
|
|
985
961
|
if (figType) {
|
|
@@ -1000,7 +976,7 @@ class JATSExporter {
|
|
|
1000
976
|
const element = createElement(node, nodeName);
|
|
1001
977
|
appendLabels(element, node);
|
|
1002
978
|
appendChildNodeOfType(element, node, node.type.schema.nodes.figcaption);
|
|
1003
|
-
|
|
979
|
+
appendChildNodeOfType(element, node, node.type.schema.nodes.table);
|
|
1004
980
|
appendChildNodeOfType(element, node, node.type.schema.nodes.table_element_footer);
|
|
1005
981
|
if ((0, node_types_1.isExecutableNodeType)(node.type)) {
|
|
1006
982
|
processExecutableNode(node, element);
|
package/dist/cjs/schema/index.js
CHANGED
|
@@ -87,6 +87,7 @@ 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");
|
|
90
91
|
const text_1 = require("./nodes/text");
|
|
91
92
|
const title_1 = require("./nodes/title");
|
|
92
93
|
const toc_element_1 = require("./nodes/toc_element");
|
|
@@ -136,6 +137,7 @@ __exportStar(require("./nodes/section_title"), exports);
|
|
|
136
137
|
__exportStar(require("./nodes/table"), exports);
|
|
137
138
|
__exportStar(require("./nodes/table_col"), exports);
|
|
138
139
|
__exportStar(require("./nodes/table_element"), exports);
|
|
140
|
+
__exportStar(require("./nodes/table_row"), exports);
|
|
139
141
|
__exportStar(require("./nodes/text"), exports);
|
|
140
142
|
__exportStar(require("./nodes/toc_element"), exports);
|
|
141
143
|
__exportStar(require("./nodes/toc_section"), exports);
|
|
@@ -211,9 +213,10 @@ exports.schema = new prosemirror_model_1.Schema({
|
|
|
211
213
|
section_title: section_title_1.sectionTitle,
|
|
212
214
|
section_title_plain: section_title_1.sectionTitle,
|
|
213
215
|
table: table_1.table,
|
|
214
|
-
|
|
216
|
+
table_body: table_1.tableBody,
|
|
217
|
+
table_cell: table_row_1.tableCell,
|
|
215
218
|
table_element: table_element_1.tableElement,
|
|
216
|
-
table_row:
|
|
219
|
+
table_row: table_row_1.tableRow,
|
|
217
220
|
table_col: table_col_1.tableCol,
|
|
218
221
|
table_colgroup: table_col_1.tableColGroup,
|
|
219
222
|
text: text_1.text,
|
|
@@ -227,6 +230,5 @@ exports.schema = new prosemirror_model_1.Schema({
|
|
|
227
230
|
contributors: contributors_1.contributors,
|
|
228
231
|
supplements: supplements_1.supplements,
|
|
229
232
|
supplement: supplement_1.supplement,
|
|
230
|
-
table_header: table_1.tableHeader,
|
|
231
233
|
},
|
|
232
234
|
});
|
|
@@ -15,57 +15,20 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
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);
|
|
18
|
+
exports.tableBody = exports.table = void 0;
|
|
60
19
|
exports.table = {
|
|
20
|
+
content: 'table_colgroup? table_body',
|
|
21
|
+
tableRole: 'table',
|
|
22
|
+
isolating: true,
|
|
23
|
+
group: 'block',
|
|
24
|
+
selectable: false,
|
|
61
25
|
attrs: {
|
|
62
26
|
id: { default: '' },
|
|
27
|
+
headerRows: { default: 1 },
|
|
28
|
+
footerRows: { default: 1 },
|
|
63
29
|
dataTracked: { default: null },
|
|
30
|
+
comments: { default: null },
|
|
64
31
|
},
|
|
65
|
-
content: 'table_row+',
|
|
66
|
-
tableRole: 'table',
|
|
67
|
-
isolating: true,
|
|
68
|
-
group: 'block',
|
|
69
32
|
parseDOM: [
|
|
70
33
|
{
|
|
71
34
|
tag: 'table',
|
|
@@ -73,20 +36,35 @@ exports.table = {
|
|
|
73
36
|
const dom = p;
|
|
74
37
|
return {
|
|
75
38
|
id: dom.getAttribute('id'),
|
|
39
|
+
headerRows: dom.dataset && dom.dataset['header-rows'],
|
|
40
|
+
footerRows: dom.dataset && dom.dataset['footer-rows'],
|
|
76
41
|
};
|
|
77
42
|
},
|
|
78
43
|
},
|
|
79
44
|
],
|
|
80
|
-
toDOM(node) {
|
|
45
|
+
toDOM: (node) => {
|
|
46
|
+
const tableNode = node;
|
|
81
47
|
return [
|
|
82
48
|
'table',
|
|
83
49
|
{
|
|
84
|
-
id:
|
|
50
|
+
id: tableNode.attrs.id,
|
|
51
|
+
'data-header-rows': String(node.attrs.headerRows),
|
|
52
|
+
'data-footer-rows': String(node.attrs.footerRows),
|
|
85
53
|
},
|
|
86
|
-
|
|
54
|
+
0,
|
|
87
55
|
];
|
|
88
56
|
},
|
|
89
57
|
};
|
|
90
|
-
exports.
|
|
91
|
-
|
|
92
|
-
|
|
58
|
+
exports.tableBody = {
|
|
59
|
+
content: 'table_row+',
|
|
60
|
+
group: 'block',
|
|
61
|
+
tableRole: 'table',
|
|
62
|
+
parseDOM: [
|
|
63
|
+
{
|
|
64
|
+
tag: 'tbody',
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
toDOM() {
|
|
68
|
+
return ['tbody', 0];
|
|
69
|
+
},
|
|
70
|
+
};
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.tableElement = void 0;
|
|
19
19
|
exports.tableElement = {
|
|
20
|
-
content: '
|
|
20
|
+
content: '(table | placeholder) table_element_footer? figcaption? (listing | placeholder)',
|
|
21
21
|
attrs: {
|
|
22
22
|
id: { default: '' },
|
|
23
23
|
paragraphStyle: { default: '' },
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* © 2019 Atypon Systems LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.tableCell = exports.tableRow = void 0;
|
|
19
|
+
const table_cell_styles_1 = require("../../lib/table-cell-styles");
|
|
20
|
+
const getCellAttrs = (p) => {
|
|
21
|
+
const dom = p;
|
|
22
|
+
const celltype = dom.tagName.toLowerCase();
|
|
23
|
+
const widthAttr = dom.getAttribute('data-colwidth');
|
|
24
|
+
const widths = widthAttr && /^\d+(,\d+)*$/.test(widthAttr)
|
|
25
|
+
? widthAttr.split(',').map((s) => Number(s))
|
|
26
|
+
: null;
|
|
27
|
+
const colspan = Number(dom.getAttribute('colspan') || 1);
|
|
28
|
+
const valign = dom.getAttribute('valign');
|
|
29
|
+
const align = dom.getAttribute('align');
|
|
30
|
+
const scope = dom.getAttribute('scope');
|
|
31
|
+
const style = dom.getAttribute('style');
|
|
32
|
+
return {
|
|
33
|
+
celltype,
|
|
34
|
+
colspan,
|
|
35
|
+
rowspan: Number(dom.getAttribute('rowspan') || 1),
|
|
36
|
+
colwidth: widths && widths.length === colspan ? widths : null,
|
|
37
|
+
placeholder: dom.getAttribute('data-placeholder-text') || '',
|
|
38
|
+
styles: (0, table_cell_styles_1.getTableCellStyles)(dom.style),
|
|
39
|
+
valign,
|
|
40
|
+
align,
|
|
41
|
+
scope,
|
|
42
|
+
style,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
exports.tableRow = {
|
|
46
|
+
content: 'table_cell+',
|
|
47
|
+
tableRole: 'row',
|
|
48
|
+
attrs: {
|
|
49
|
+
placeholder: { default: '' },
|
|
50
|
+
},
|
|
51
|
+
parseDOM: [
|
|
52
|
+
{
|
|
53
|
+
tag: 'tr',
|
|
54
|
+
priority: 80,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
toDOM: (node) => {
|
|
58
|
+
const tableRowNode = node;
|
|
59
|
+
const attrs = {};
|
|
60
|
+
if (tableRowNode.attrs.placeholder) {
|
|
61
|
+
attrs['data-placeholder-text'] = tableRowNode.attrs.placeholder;
|
|
62
|
+
}
|
|
63
|
+
return ['tr', attrs, 0];
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
exports.tableCell = {
|
|
67
|
+
content: 'inline*',
|
|
68
|
+
attrs: {
|
|
69
|
+
celltype: { default: 'td' },
|
|
70
|
+
colspan: { default: 1 },
|
|
71
|
+
rowspan: { default: 1 },
|
|
72
|
+
colwidth: { default: null },
|
|
73
|
+
placeholder: { default: 'Data' },
|
|
74
|
+
styles: { default: {} },
|
|
75
|
+
valign: { default: null },
|
|
76
|
+
align: { default: null },
|
|
77
|
+
scope: { default: null },
|
|
78
|
+
style: { default: null },
|
|
79
|
+
},
|
|
80
|
+
tableRole: 'cell',
|
|
81
|
+
isolating: true,
|
|
82
|
+
parseDOM: [
|
|
83
|
+
{ tag: 'td', getAttrs: getCellAttrs },
|
|
84
|
+
{ tag: 'th', getAttrs: getCellAttrs },
|
|
85
|
+
],
|
|
86
|
+
toDOM: (node) => {
|
|
87
|
+
const tableCellNode = node;
|
|
88
|
+
const attrs = {};
|
|
89
|
+
const tag = tableCellNode.attrs.celltype;
|
|
90
|
+
if (tableCellNode.attrs.colspan && tableCellNode.attrs.colspan !== 1) {
|
|
91
|
+
attrs.colspan = String(tableCellNode.attrs.colspan);
|
|
92
|
+
}
|
|
93
|
+
if (tableCellNode.attrs.rowspan && tableCellNode.attrs.rowspan !== 1) {
|
|
94
|
+
attrs.rowspan = String(tableCellNode.attrs.rowspan);
|
|
95
|
+
}
|
|
96
|
+
if (tableCellNode.attrs.colwidth) {
|
|
97
|
+
attrs['data-colwidth'] = tableCellNode.attrs.colwidth.join(',');
|
|
98
|
+
}
|
|
99
|
+
if (tableCellNode.attrs.placeholder) {
|
|
100
|
+
attrs['data-placeholder-text'] = tableCellNode.attrs.placeholder;
|
|
101
|
+
}
|
|
102
|
+
if (!tableCellNode.textContent) {
|
|
103
|
+
attrs.class = 'placeholder';
|
|
104
|
+
}
|
|
105
|
+
const styleString = (0, table_cell_styles_1.serializeTableCellStyles)(tableCellNode.attrs.styles);
|
|
106
|
+
if (styleString) {
|
|
107
|
+
attrs.style = styleString;
|
|
108
|
+
}
|
|
109
|
+
if (tableCellNode.attrs.valign) {
|
|
110
|
+
attrs.valign = tableCellNode.attrs.valign;
|
|
111
|
+
}
|
|
112
|
+
if (tableCellNode.attrs.align) {
|
|
113
|
+
attrs.align = tableCellNode.attrs.align;
|
|
114
|
+
}
|
|
115
|
+
if (tableCellNode.attrs.scope) {
|
|
116
|
+
attrs.scope = tableCellNode.attrs.scope;
|
|
117
|
+
}
|
|
118
|
+
if (tableCellNode.attrs.style) {
|
|
119
|
+
attrs.style = tableCellNode.attrs.style;
|
|
120
|
+
}
|
|
121
|
+
return [tag, attrs, 0];
|
|
122
|
+
},
|
|
123
|
+
};
|
|
@@ -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,
|
|
@@ -557,28 +558,25 @@ class Decoder {
|
|
|
557
558
|
},
|
|
558
559
|
[json_schema_1.ObjectTypes.Table]: (data) => {
|
|
559
560
|
const model = data;
|
|
560
|
-
|
|
561
|
+
const comments = this.createCommentNodes(model);
|
|
562
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
563
|
+
return this.parseContents(model.contents, undefined, this.getComments(model), {
|
|
561
564
|
topNode: schema_1.schema.nodes.table.create({
|
|
562
565
|
id: model._id,
|
|
566
|
+
comments: comments.map((c) => c.attrs.id),
|
|
563
567
|
}),
|
|
564
568
|
});
|
|
565
569
|
},
|
|
566
570
|
[json_schema_1.ObjectTypes.TableElement]: (data) => {
|
|
567
571
|
const model = data;
|
|
568
572
|
const table = this.createTable(model);
|
|
569
|
-
const tableColGroup = this.createTableColGroup(model);
|
|
570
573
|
const tableElementFooter = this.createTableElementFooter(model);
|
|
571
574
|
const figcaption = this.getFigcaption(model);
|
|
572
575
|
const comments = this.createCommentNodes(model);
|
|
573
576
|
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
574
|
-
const content =
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
}
|
|
578
|
-
if (tableElementFooter) {
|
|
579
|
-
content.push(tableElementFooter);
|
|
580
|
-
}
|
|
581
|
-
content.push(figcaption);
|
|
577
|
+
const content = tableElementFooter
|
|
578
|
+
? [table, tableElementFooter, figcaption]
|
|
579
|
+
: [table, figcaption];
|
|
582
580
|
if (model.listingID) {
|
|
583
581
|
const listing = this.createListing(model.listingID);
|
|
584
582
|
content.push(listing);
|
|
@@ -792,16 +790,6 @@ class Decoder {
|
|
|
792
790
|
}
|
|
793
791
|
return table;
|
|
794
792
|
}
|
|
795
|
-
createTableColGroup(model) {
|
|
796
|
-
const tableId = model.containedObjectID;
|
|
797
|
-
const tableModel = this.getModel(tableId);
|
|
798
|
-
if (!tableModel || !tableModel.contents.includes('<colgroup>')) {
|
|
799
|
-
return undefined;
|
|
800
|
-
}
|
|
801
|
-
return this.parseContents(tableModel.contents, undefined, [], {
|
|
802
|
-
topNode: schema_1.schema.nodes.table_colgroup.create(),
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
793
|
createTableElementFooter(model) {
|
|
806
794
|
const tableElementFooterID = model.tableElementFooterID;
|
|
807
795
|
if (!tableElementFooterID) {
|
|
@@ -115,9 +115,8 @@ function buildTableColGroup(cols) {
|
|
|
115
115
|
}
|
|
116
116
|
const tableContents = (node, parent) => {
|
|
117
117
|
const input = serializer.serializeNode(node);
|
|
118
|
-
const parentInput = serializer.serializeNode(parent);
|
|
119
118
|
const output = document.createElement('table');
|
|
120
|
-
const colgroup = buildTableColGroup(Array.from(
|
|
119
|
+
const colgroup = buildTableColGroup(Array.from(input.querySelectorAll('col')));
|
|
121
120
|
if (colgroup) {
|
|
122
121
|
output.appendChild(colgroup);
|
|
123
122
|
}
|
|
@@ -597,6 +596,9 @@ const encode = (node) => {
|
|
|
597
596
|
child.type !== schema_1.schema.nodes.inline_equation) {
|
|
598
597
|
return;
|
|
599
598
|
}
|
|
599
|
+
if (child.type === schema_1.schema.nodes.footnotes_element) {
|
|
600
|
+
addFootnotesOrderModel(child, models);
|
|
601
|
+
}
|
|
600
602
|
const { model, markers } = (0, exports.modelFromNode)(child, parent, path, priority);
|
|
601
603
|
markers.forEach((marker) => {
|
|
602
604
|
const comment = models.get(marker._id);
|
|
@@ -648,3 +650,9 @@ const generateElementOrder = (node, nodeType) => {
|
|
|
648
650
|
order.elements = ids;
|
|
649
651
|
return order;
|
|
650
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;
|
|
@@ -519,9 +519,23 @@ 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'),
|
|
522
524
|
};
|
|
523
525
|
},
|
|
524
526
|
},
|
|
527
|
+
{
|
|
528
|
+
tag: 'tbody',
|
|
529
|
+
skip: true,
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
tag: 'tfoot',
|
|
533
|
+
skip: true,
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
tag: 'thead',
|
|
537
|
+
skip: true,
|
|
538
|
+
},
|
|
525
539
|
{
|
|
526
540
|
tag: 'title',
|
|
527
541
|
node: 'section_title',
|
|
@@ -548,12 +562,12 @@ const nodes = [
|
|
|
548
562
|
},
|
|
549
563
|
{
|
|
550
564
|
tag: 'th',
|
|
551
|
-
node: '
|
|
565
|
+
node: 'table_cell',
|
|
552
566
|
getAttrs: (node) => {
|
|
553
567
|
const element = node;
|
|
554
568
|
const colspan = element.getAttribute('colspan');
|
|
555
569
|
const rowspan = element.getAttribute('rowspan');
|
|
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') });
|
|
570
|
+
return Object.assign(Object.assign(Object.assign({ celltype: 'th' }, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
|
|
557
571
|
},
|
|
558
572
|
},
|
|
559
573
|
{
|