@manuscripts/transform 2.6.1-LEAN-3966.2 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -151,7 +151,6 @@ class JATSExporter {
151
151
  this.updateFootnoteTypes(front, back);
152
152
  this.fillEmptyTableFooters(article);
153
153
  this.fillEmptyFootnotes(article);
154
- this.moveAwards(front, body);
155
154
  await this.rewriteIDs();
156
155
  return (0, w3c_xmlserializer_1.default)(this.document);
157
156
  };
@@ -295,10 +294,10 @@ class JATSExporter {
295
294
  let countingElements = [];
296
295
  const figureCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.figure).length;
297
296
  countingElements.push(this.buildCountingElement('fig-count', figureCount));
298
- const equationCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.equation_element).length;
299
- countingElements.push(this.buildCountingElement('equation-count', equationCount));
300
297
  const tableCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.table).length;
301
298
  countingElements.push(this.buildCountingElement('table-count', tableCount));
299
+ const equationCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.equation_element).length;
300
+ countingElements.push(this.buildCountingElement('equation-count', equationCount));
302
301
  const referencesCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.bibliography_item).length;
303
302
  countingElements.push(this.buildCountingElement('ref-count', referencesCount));
304
303
  const wordCount = this.manuscriptNode.textContent.split(/\s+/).length;
@@ -512,18 +511,8 @@ class JATSExporter {
512
511
  };
513
512
  this.createSerializer = () => {
514
513
  const nodes = {
515
- awards: () => ['funding-group', 0],
516
- award: (node) => {
517
- const awardGroup = node;
518
- const awardGroupElement = this.document.createElement('award-group');
519
- awardGroupElement.setAttribute('id', normalizeID(awardGroup.attrs.id));
520
- appendChildIfPresent(awardGroupElement, 'funding-source', awardGroup.attrs.source);
521
- awardGroup.attrs.code
522
- .split(';')
523
- .forEach((code) => appendChildIfPresent(awardGroupElement, 'award-id', code));
524
- appendChildIfPresent(awardGroupElement, 'principal-award-recipient', awardGroup.attrs.recipient);
525
- return awardGroupElement;
526
- },
514
+ award: () => '',
515
+ awards: () => '',
527
516
  box_element: (node) => createBoxElement(node),
528
517
  author_notes: () => '',
529
518
  corresp: () => '',
@@ -801,14 +790,6 @@ class JATSExporter {
801
790
  tracked_delete: () => ['del'],
802
791
  };
803
792
  this.serializer = new prosemirror_model_1.DOMSerializer(nodes, marks);
804
- const appendChildIfPresent = (parent, tagName, textContent) => {
805
- if (!textContent) {
806
- return;
807
- }
808
- const element = this.document.createElement(tagName);
809
- element.textContent = textContent;
810
- parent.appendChild(element);
811
- };
812
793
  const processChildNodes = (element, node, contentNodeType) => {
813
794
  node.forEach((childNode) => {
814
795
  if (childNode.type === contentNodeType) {
@@ -1316,23 +1297,6 @@ class JATSExporter {
1316
1297
  }
1317
1298
  body.removeChild(container);
1318
1299
  };
1319
- this.moveAwards = (front, body) => {
1320
- const awardGroups = body.querySelectorAll(':scope > award-group');
1321
- if (!awardGroups.length) {
1322
- return;
1323
- }
1324
- const fundingGroup = this.document.createElement('funding-group');
1325
- awardGroups.forEach((award) => {
1326
- fundingGroup.appendChild(award);
1327
- });
1328
- const articleMeta = front.querySelector(':scope > article-meta');
1329
- if (articleMeta) {
1330
- const insertBeforeElement = articleMeta.querySelector(':scope > support-group, :scope > conference, :scope > counts, :scope > custom-meta-group');
1331
- insertBeforeElement
1332
- ? articleMeta.insertBefore(fundingGroup, insertBeforeElement)
1333
- : articleMeta.appendChild(fundingGroup);
1334
- }
1335
- };
1336
1300
  this.moveAbstracts = (front, body) => {
1337
1301
  const container = body.querySelector(':scope > sec[sec-type="abstracts"]');
1338
1302
  let abstractSections;
@@ -292,26 +292,6 @@ const nodes = [
292
292
  };
293
293
  },
294
294
  },
295
- {
296
- tag: 'funding-group',
297
- node: 'awards',
298
- },
299
- {
300
- tag: 'award-group',
301
- node: 'award',
302
- getAttrs: (node) => {
303
- var _a, _b;
304
- const element = node;
305
- return {
306
- id: element.getAttribute('id'),
307
- recipient: (_a = element.querySelector('principal-award-recipient')) === null || _a === void 0 ? void 0 : _a.textContent,
308
- code: Array.from(element.querySelectorAll('award-id'))
309
- .map((awardID) => awardID.textContent)
310
- .reduce((acc, text) => (acc ? `${acc};${text}` : text), ''),
311
- source: (_b = element.querySelector('funding-source')) === null || _b === void 0 ? void 0 : _b.textContent,
312
- };
313
- },
314
- },
315
295
  {
316
296
  tag: 'fn:not([fn-type])',
317
297
  node: 'footnote',
@@ -16,6 +16,7 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.htmlFromJatsNode = exports.updateDocumentIDs = void 0;
19
+ const uuid_1 = require("uuid");
19
20
  const schema_1 = require("../../schema");
20
21
  const transformer_1 = require("../../transformer");
21
22
  const updateDocumentIDs = (node) => {
@@ -34,6 +35,14 @@ const recurseDoc = (node, fn) => {
34
35
  node.descendants((n) => fn(n));
35
36
  };
36
37
  const updateNodeID = (node, replacements, warnings) => {
38
+ if (node.type === schema_1.schema.nodes.inline_equation) {
39
+ node.attrs = Object.assign(Object.assign({}, node.attrs), { id: `InlineMathFragment:${(0, uuid_1.v4)()}` });
40
+ return;
41
+ }
42
+ if (node.type === schema_1.schema.nodes.general_table_footnote) {
43
+ node.attrs = Object.assign(Object.assign({}, node.attrs), { id: `GeneralTableFootnote:${(0, uuid_1.v4)()}` });
44
+ return;
45
+ }
37
46
  if (node.type === schema_1.schema.nodes.comment ||
38
47
  node.type === schema_1.schema.nodes.highlight_marker) {
39
48
  return;
@@ -41,6 +50,11 @@ const updateNodeID = (node, replacements, warnings) => {
41
50
  if (!('id' in node.attrs)) {
42
51
  return;
43
52
  }
53
+ const objectType = transformer_1.nodeTypesMap.get(node.type);
54
+ if (!objectType) {
55
+ warnings.push(`Unknown object type for node type ${node.type.name}`);
56
+ return;
57
+ }
44
58
  const previousID = node.attrs.id;
45
59
  const nextID = (0, transformer_1.generateNodeID)(node.type);
46
60
  if (previousID) {
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.fixTables = exports.orderTableFootnote = exports.moveReferencesToBackmatter = exports.createSupplementaryMaterialsSection = exports.createKeywordsSection = exports.moveCaptionsToEnd = exports.createBackmatter = exports.createAbstracts = exports.createBody = exports.createBoxedElementSection = exports.moveAbstracts = exports.moveAffiliations = exports.moveContributors = exports.moveAwards = exports.moveAuthorNotes = exports.moveTitle = exports.ensureSection = void 0;
18
+ exports.fixTables = exports.orderTableFootnote = exports.moveReferencesToBackmatter = exports.createSupplementaryMaterialsSection = exports.createKeywordsSection = exports.moveCaptionsToEnd = exports.createBackmatter = exports.createAbstracts = exports.createBody = exports.createBoxedElementSection = exports.moveAbstracts = exports.moveAffiliations = exports.moveContributors = exports.moveAuthorNotes = exports.moveTitle = exports.ensureSection = void 0;
19
19
  const deafults_1 = require("../../lib/deafults");
20
20
  const section_group_type_1 = require("../../lib/section-group-type");
21
21
  const transformer_1 = require("../../transformer");
@@ -76,14 +76,6 @@ const moveAuthorNotes = (front, createElement) => {
76
76
  }
77
77
  };
78
78
  exports.moveAuthorNotes = moveAuthorNotes;
79
- const moveAwards = (front) => {
80
- var _a;
81
- const awards = front.querySelector('article-meta > funding-group');
82
- if (awards) {
83
- (_a = front.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(awards, front);
84
- }
85
- };
86
- exports.moveAwards = moveAwards;
87
79
  const moveContributors = (front, createElement) => {
88
80
  var _a;
89
81
  const contribs = front.querySelectorAll('contrib-group > contrib[contrib-type="author"]');
@@ -32,7 +32,6 @@ const processJATS = (doc) => {
32
32
  (0, jats_transformations_1.moveContributors)(front, createElement);
33
33
  (0, jats_transformations_1.moveAffiliations)(front, createElement);
34
34
  (0, jats_transformations_1.moveAuthorNotes)(front, createElement);
35
- (0, jats_transformations_1.moveAwards)(front);
36
35
  const body = doc.querySelector('body');
37
36
  if (!body) {
38
37
  return;
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "2.6.1-LEAN-3966.2";
4
+ exports.VERSION = "3.0.0";
@@ -143,7 +143,6 @@ export class JATSExporter {
143
143
  this.updateFootnoteTypes(front, back);
144
144
  this.fillEmptyTableFooters(article);
145
145
  this.fillEmptyFootnotes(article);
146
- this.moveAwards(front, body);
147
146
  await this.rewriteIDs();
148
147
  return serializeToXML(this.document);
149
148
  };
@@ -287,10 +286,10 @@ export class JATSExporter {
287
286
  let countingElements = [];
288
287
  const figureCount = findChildrenByType(this.manuscriptNode, schema.nodes.figure).length;
289
288
  countingElements.push(this.buildCountingElement('fig-count', figureCount));
290
- const equationCount = findChildrenByType(this.manuscriptNode, schema.nodes.equation_element).length;
291
- countingElements.push(this.buildCountingElement('equation-count', equationCount));
292
289
  const tableCount = findChildrenByType(this.manuscriptNode, schema.nodes.table).length;
293
290
  countingElements.push(this.buildCountingElement('table-count', tableCount));
291
+ const equationCount = findChildrenByType(this.manuscriptNode, schema.nodes.equation_element).length;
292
+ countingElements.push(this.buildCountingElement('equation-count', equationCount));
294
293
  const referencesCount = findChildrenByType(this.manuscriptNode, schema.nodes.bibliography_item).length;
295
294
  countingElements.push(this.buildCountingElement('ref-count', referencesCount));
296
295
  const wordCount = this.manuscriptNode.textContent.split(/\s+/).length;
@@ -504,18 +503,8 @@ export class JATSExporter {
504
503
  };
505
504
  this.createSerializer = () => {
506
505
  const nodes = {
507
- awards: () => ['funding-group', 0],
508
- award: (node) => {
509
- const awardGroup = node;
510
- const awardGroupElement = this.document.createElement('award-group');
511
- awardGroupElement.setAttribute('id', normalizeID(awardGroup.attrs.id));
512
- appendChildIfPresent(awardGroupElement, 'funding-source', awardGroup.attrs.source);
513
- awardGroup.attrs.code
514
- .split(';')
515
- .forEach((code) => appendChildIfPresent(awardGroupElement, 'award-id', code));
516
- appendChildIfPresent(awardGroupElement, 'principal-award-recipient', awardGroup.attrs.recipient);
517
- return awardGroupElement;
518
- },
506
+ award: () => '',
507
+ awards: () => '',
519
508
  box_element: (node) => createBoxElement(node),
520
509
  author_notes: () => '',
521
510
  corresp: () => '',
@@ -793,14 +782,6 @@ export class JATSExporter {
793
782
  tracked_delete: () => ['del'],
794
783
  };
795
784
  this.serializer = new DOMSerializer(nodes, marks);
796
- const appendChildIfPresent = (parent, tagName, textContent) => {
797
- if (!textContent) {
798
- return;
799
- }
800
- const element = this.document.createElement(tagName);
801
- element.textContent = textContent;
802
- parent.appendChild(element);
803
- };
804
785
  const processChildNodes = (element, node, contentNodeType) => {
805
786
  node.forEach((childNode) => {
806
787
  if (childNode.type === contentNodeType) {
@@ -1308,23 +1289,6 @@ export class JATSExporter {
1308
1289
  }
1309
1290
  body.removeChild(container);
1310
1291
  };
1311
- this.moveAwards = (front, body) => {
1312
- const awardGroups = body.querySelectorAll(':scope > award-group');
1313
- if (!awardGroups.length) {
1314
- return;
1315
- }
1316
- const fundingGroup = this.document.createElement('funding-group');
1317
- awardGroups.forEach((award) => {
1318
- fundingGroup.appendChild(award);
1319
- });
1320
- const articleMeta = front.querySelector(':scope > article-meta');
1321
- if (articleMeta) {
1322
- const insertBeforeElement = articleMeta.querySelector(':scope > support-group, :scope > conference, :scope > counts, :scope > custom-meta-group');
1323
- insertBeforeElement
1324
- ? articleMeta.insertBefore(fundingGroup, insertBeforeElement)
1325
- : articleMeta.appendChild(fundingGroup);
1326
- }
1327
- };
1328
1292
  this.moveAbstracts = (front, body) => {
1329
1293
  const container = body.querySelector(':scope > sec[sec-type="abstracts"]');
1330
1294
  let abstractSections;
@@ -286,26 +286,6 @@ const nodes = [
286
286
  };
287
287
  },
288
288
  },
289
- {
290
- tag: 'funding-group',
291
- node: 'awards',
292
- },
293
- {
294
- tag: 'award-group',
295
- node: 'award',
296
- getAttrs: (node) => {
297
- var _a, _b;
298
- const element = node;
299
- return {
300
- id: element.getAttribute('id'),
301
- recipient: (_a = element.querySelector('principal-award-recipient')) === null || _a === void 0 ? void 0 : _a.textContent,
302
- code: Array.from(element.querySelectorAll('award-id'))
303
- .map((awardID) => awardID.textContent)
304
- .reduce((acc, text) => (acc ? `${acc};${text}` : text), ''),
305
- source: (_b = element.querySelector('funding-source')) === null || _b === void 0 ? void 0 : _b.textContent,
306
- };
307
- },
308
- },
309
289
  {
310
290
  tag: 'fn:not([fn-type])',
311
291
  node: 'footnote',
@@ -13,8 +13,9 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { v4 as uuidv4 } from 'uuid';
16
17
  import { schema, } from '../../schema';
17
- import { generateNodeID } from '../../transformer';
18
+ import { generateNodeID, nodeTypesMap } from '../../transformer';
18
19
  export const updateDocumentIDs = (node) => {
19
20
  const replacements = new Map();
20
21
  const warnings = [];
@@ -30,6 +31,14 @@ const recurseDoc = (node, fn) => {
30
31
  node.descendants((n) => fn(n));
31
32
  };
32
33
  const updateNodeID = (node, replacements, warnings) => {
34
+ if (node.type === schema.nodes.inline_equation) {
35
+ node.attrs = Object.assign(Object.assign({}, node.attrs), { id: `InlineMathFragment:${uuidv4()}` });
36
+ return;
37
+ }
38
+ if (node.type === schema.nodes.general_table_footnote) {
39
+ node.attrs = Object.assign(Object.assign({}, node.attrs), { id: `GeneralTableFootnote:${uuidv4()}` });
40
+ return;
41
+ }
33
42
  if (node.type === schema.nodes.comment ||
34
43
  node.type === schema.nodes.highlight_marker) {
35
44
  return;
@@ -37,6 +46,11 @@ const updateNodeID = (node, replacements, warnings) => {
37
46
  if (!('id' in node.attrs)) {
38
47
  return;
39
48
  }
49
+ const objectType = nodeTypesMap.get(node.type);
50
+ if (!objectType) {
51
+ warnings.push(`Unknown object type for node type ${node.type.name}`);
52
+ return;
53
+ }
40
54
  const previousID = node.attrs.id;
41
55
  const nextID = generateNodeID(node.type);
42
56
  if (previousID) {
@@ -70,13 +70,6 @@ export const moveAuthorNotes = (front, createElement) => {
70
70
  (_a = front.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(authorNotes, front);
71
71
  }
72
72
  };
73
- export const moveAwards = (front) => {
74
- var _a;
75
- const awards = front.querySelector('article-meta > funding-group');
76
- if (awards) {
77
- (_a = front.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(awards, front);
78
- }
79
- };
80
73
  export const moveContributors = (front, createElement) => {
81
74
  var _a;
82
75
  const contribs = front.querySelectorAll('contrib-group > contrib[contrib-type="author"]');
@@ -17,7 +17,7 @@ import { markComments } from './jats-comments';
17
17
  import { jatsDOMParser } from './jats-dom-parser';
18
18
  import { parseJournal } from './jats-journal-meta-parser';
19
19
  import { updateDocumentIDs } from './jats-parser-utils';
20
- import { createAbstracts, createBackmatter, createBody, createBoxedElementSection, createKeywordsSection, createSupplementaryMaterialsSection, ensureSection, fixTables, moveAffiliations, moveAuthorNotes, moveAwards, moveCaptionsToEnd, moveContributors, moveReferencesToBackmatter, moveTitle, orderTableFootnote, } from './jats-transformations';
20
+ import { createAbstracts, createBackmatter, createBody, createBoxedElementSection, createKeywordsSection, createSupplementaryMaterialsSection, ensureSection, fixTables, moveAffiliations, moveAuthorNotes, moveCaptionsToEnd, moveContributors, moveReferencesToBackmatter, moveTitle, orderTableFootnote, } from './jats-transformations';
21
21
  const processJATS = (doc) => {
22
22
  const createElement = createElementFn(doc);
23
23
  markComments(doc);
@@ -29,7 +29,6 @@ const processJATS = (doc) => {
29
29
  moveContributors(front, createElement);
30
30
  moveAffiliations(front, createElement);
31
31
  moveAuthorNotes(front, createElement);
32
- moveAwards(front);
33
32
  const body = doc.querySelector('body');
34
33
  if (!body) {
35
34
  return;
@@ -1 +1 @@
1
- export const VERSION = "2.6.1-LEAN-3966.2";
1
+ export const VERSION = "3.0.0";
@@ -85,7 +85,6 @@ export declare class JATSExporter {
85
85
  private fixTable;
86
86
  private unwrapBody;
87
87
  private removeBackContainer;
88
- private moveAwards;
89
88
  private moveAbstracts;
90
89
  private moveSectionsToBack;
91
90
  sectionToFootnote: (section: Element, fnType: string) => HTMLElement;
@@ -17,7 +17,6 @@ export type CreateElement = (tagName: string) => HTMLElement;
17
17
  export declare const ensureSection: (body: Element, createElement: CreateElement) => void;
18
18
  export declare const moveTitle: (front: Element, createElement: CreateElement) => void;
19
19
  export declare const moveAuthorNotes: (front: Element, createElement: CreateElement) => void;
20
- export declare const moveAwards: (front: Element) => void;
21
20
  export declare const moveContributors: (front: Element, createElement: CreateElement) => void;
22
21
  export declare const moveAffiliations: (front: Element, createElement: CreateElement) => void;
23
22
  export declare const moveAbstracts: (doc: Document, group: Element, createElement: CreateElement) => void;
@@ -1 +1 @@
1
- export declare const VERSION = "2.6.1-LEAN-3966.2";
1
+ export declare const VERSION = "3.0.0";
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.6.1-LEAN-3966.2",
4
+ "version": "3.0.0",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",