@manuscripts/transform 2.1.6 → 2.1.7-LEAN-3467-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.
@@ -202,34 +202,20 @@ exports.jatsBodyTransformations = {
202
202
  }
203
203
  },
204
204
  moveFootnotes(doc, group, createElement) {
205
- const footnotes = [
206
- ...doc.querySelectorAll('fn:not(table-wrap-foot fn, author-notes fn)'),
207
- ];
208
- const footnotesSection = doc.querySelector('sec[sec-type="endnotes"]');
209
- const footnotesSectionGroup = footnotesSection === null || footnotesSection === void 0 ? void 0 : footnotesSection.querySelector('fn-group');
210
- const containingGroup = footnotesSectionGroup || createElement('fn-group');
211
- for (const footnote of footnotes) {
212
- const type = footnote.getAttribute('fn-type');
213
- if (!type) {
205
+ var _a;
206
+ const footnotes = Array.from(doc.querySelectorAll('fn:not(table-wrap-foot fn, author-notes fn)'));
207
+ let footnotesSection = doc.querySelector('sec[sec-type="endnotes"]');
208
+ const containingGroup = (footnotesSection === null || footnotesSection === void 0 ? void 0 : footnotesSection.querySelector('fn-group')) || createElement('fn-group');
209
+ footnotes.forEach((footnote) => {
210
+ if (!footnote.getAttribute('fn-type')) {
214
211
  containingGroup.appendChild(footnote);
215
212
  }
216
- }
213
+ });
217
214
  if (!footnotesSection && containingGroup.innerHTML) {
218
- const section = this.createFootnotesSection([containingGroup], createElement);
219
- group.append(section);
215
+ footnotesSection = this.createFootnotesSection([containingGroup], createElement);
220
216
  }
221
- let regularFootnoteGroups = [
222
- ...doc.querySelectorAll('back > fn-group:not([fn-type])'),
223
- ];
224
- regularFootnoteGroups = regularFootnoteGroups.filter((group) => {
225
- return group.childElementCount === 0
226
- ? false
227
- : !group.querySelector('fn[fn-type]');
228
- });
229
- if (regularFootnoteGroups.length > 0) {
230
- regularFootnoteGroups.map((g) => removeNodeFromParent(g));
231
- const footnotes = this.createFootnotesSection(regularFootnoteGroups, createElement);
232
- group.appendChild(footnotes);
217
+ if (footnotesSection) {
218
+ group.insertBefore(footnotesSection, ((_a = group.firstChild) === null || _a === void 0 ? void 0 : _a.nextSibling) || group.firstChild);
233
219
  }
234
220
  },
235
221
  moveCaptionsToEnd(body) {
@@ -154,6 +154,7 @@ class JATSExporter {
154
154
  this.moveFloatsGroup(body, article);
155
155
  this.removeBackContainer(body);
156
156
  this.updateFootnoteTypes(front, back);
157
+ this.fillEmptyFootnotes(article);
157
158
  }
158
159
  await this.rewriteIDs(idGenerator);
159
160
  if (mediaPathGenerator) {
@@ -1706,5 +1707,9 @@ class JATSExporter {
1706
1707
  }
1707
1708
  });
1708
1709
  }
1710
+ fillEmptyFootnotes(articleElement) {
1711
+ const emptyFootnotes = Array.from(articleElement.querySelectorAll('fn')).filter((fn) => { var _a; return !((_a = fn.textContent) === null || _a === void 0 ? void 0 : _a.trim()); });
1712
+ emptyFootnotes.forEach((fn) => fn.appendChild(this.document.createElement('p')));
1713
+ }
1709
1714
  }
1710
1715
  exports.JATSExporter = JATSExporter;
@@ -199,34 +199,20 @@ export const jatsBodyTransformations = {
199
199
  }
200
200
  },
201
201
  moveFootnotes(doc, group, createElement) {
202
- const footnotes = [
203
- ...doc.querySelectorAll('fn:not(table-wrap-foot fn, author-notes fn)'),
204
- ];
205
- const footnotesSection = doc.querySelector('sec[sec-type="endnotes"]');
206
- const footnotesSectionGroup = footnotesSection === null || footnotesSection === void 0 ? void 0 : footnotesSection.querySelector('fn-group');
207
- const containingGroup = footnotesSectionGroup || createElement('fn-group');
208
- for (const footnote of footnotes) {
209
- const type = footnote.getAttribute('fn-type');
210
- if (!type) {
202
+ var _a;
203
+ const footnotes = Array.from(doc.querySelectorAll('fn:not(table-wrap-foot fn, author-notes fn)'));
204
+ let footnotesSection = doc.querySelector('sec[sec-type="endnotes"]');
205
+ const containingGroup = (footnotesSection === null || footnotesSection === void 0 ? void 0 : footnotesSection.querySelector('fn-group')) || createElement('fn-group');
206
+ footnotes.forEach((footnote) => {
207
+ if (!footnote.getAttribute('fn-type')) {
211
208
  containingGroup.appendChild(footnote);
212
209
  }
213
- }
210
+ });
214
211
  if (!footnotesSection && containingGroup.innerHTML) {
215
- const section = this.createFootnotesSection([containingGroup], createElement);
216
- group.append(section);
212
+ footnotesSection = this.createFootnotesSection([containingGroup], createElement);
217
213
  }
218
- let regularFootnoteGroups = [
219
- ...doc.querySelectorAll('back > fn-group:not([fn-type])'),
220
- ];
221
- regularFootnoteGroups = regularFootnoteGroups.filter((group) => {
222
- return group.childElementCount === 0
223
- ? false
224
- : !group.querySelector('fn[fn-type]');
225
- });
226
- if (regularFootnoteGroups.length > 0) {
227
- regularFootnoteGroups.map((g) => removeNodeFromParent(g));
228
- const footnotes = this.createFootnotesSection(regularFootnoteGroups, createElement);
229
- group.appendChild(footnotes);
214
+ if (footnotesSection) {
215
+ group.insertBefore(footnotesSection, ((_a = group.firstChild) === null || _a === void 0 ? void 0 : _a.nextSibling) || group.firstChild);
230
216
  }
231
217
  },
232
218
  moveCaptionsToEnd(body) {
@@ -16,7 +16,7 @@
16
16
  import { getModelsByType, ObjectTypes, } from '@manuscripts/json-schema';
17
17
  import { CitationProvider } from '@manuscripts/library';
18
18
  import debug from 'debug';
19
- import { DOMParser as ProseMirrorDOMParser, DOMSerializer, } from 'prosemirror-model';
19
+ import { DOMParser as ProsemirrorDOMParser, DOMSerializer, } from 'prosemirror-model';
20
20
  import serializeToXML from 'w3c-xmlserializer';
21
21
  import { nodeFromHTML, textFromHTML } from '../lib/html';
22
22
  import { normalizeStyleName } from '../lib/styled-content';
@@ -32,7 +32,7 @@ import { selectVersionIds } from './jats-versions';
32
32
  const warn = debug('manuscripts-transform');
33
33
  const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
34
34
  const normalizeID = (id) => id.replace(/:/g, '_');
35
- const parser = ProseMirrorDOMParser.fromSchema(schema);
35
+ const parser = ProsemirrorDOMParser.fromSchema(schema);
36
36
  const findChildNodeOfType = (node, nodeType) => {
37
37
  for (const child of iterateChildren(node)) {
38
38
  if (child.type === nodeType) {
@@ -146,6 +146,7 @@ export class JATSExporter {
146
146
  this.moveFloatsGroup(body, article);
147
147
  this.removeBackContainer(body);
148
148
  this.updateFootnoteTypes(front, back);
149
+ this.fillEmptyFootnotes(article);
149
150
  }
150
151
  await this.rewriteIDs(idGenerator);
151
152
  if (mediaPathGenerator) {
@@ -1698,4 +1699,8 @@ export class JATSExporter {
1698
1699
  }
1699
1700
  });
1700
1701
  }
1702
+ fillEmptyFootnotes(articleElement) {
1703
+ const emptyFootnotes = Array.from(articleElement.querySelectorAll('fn')).filter((fn) => { var _a; return !((_a = fn.textContent) === null || _a === void 0 ? void 0 : _a.trim()); });
1704
+ emptyFootnotes.forEach((fn) => fn.appendChild(this.document.createElement('p')));
1705
+ }
1701
1706
  }
@@ -104,5 +104,6 @@ export declare class JATSExporter {
104
104
  private buildContributorName;
105
105
  private moveCoiStatementToAuthorNotes;
106
106
  private updateFootnoteTypes;
107
+ private fillEmptyFootnotes;
107
108
  }
108
109
  export {};
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.6",
4
+ "version": "2.1.7-LEAN-3467-0",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",