@manuscripts/transform 3.0.24 → 3.0.25

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.
@@ -443,7 +443,7 @@ class JATSDOMParser {
443
443
  {
444
444
  tag: 'caption',
445
445
  node: 'figcaption',
446
- context: 'figure_element/',
446
+ context: 'figure_element/|table_element/',
447
447
  getContent: (node, schema) => {
448
448
  const element = node;
449
449
  const content = [];
@@ -462,11 +462,6 @@ class JATSDOMParser {
462
462
  return prosemirror_model_1.Fragment.from(content);
463
463
  },
464
464
  },
465
- {
466
- tag: 'caption',
467
- node: 'figcaption',
468
- context: 'table_element/',
469
- },
470
465
  {
471
466
  tag: 'caption',
472
467
  node: 'figcaption',
@@ -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 = 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.moveAwards = exports.moveAuthorNotes = exports.moveTitle = exports.addMissingCaptions = void 0;
19
19
  const deafults_1 = require("../../lib/deafults");
20
20
  const jats_parser_utils_1 = require("./jats-parser-utils");
21
21
  const removeNodeFromParent = (node) => node.parentNode && node.parentNode.removeChild(node);
@@ -25,6 +25,25 @@ const createSectionGroup = (type, createElement) => {
25
25
  sec.setAttribute('sec-type', type);
26
26
  return sec;
27
27
  };
28
+ const addMissingCaptions = (doc, createElement) => {
29
+ const elements = doc.querySelectorAll('fig, table-wrap');
30
+ for (const element of elements) {
31
+ let caption = element.querySelector('caption');
32
+ if (!caption) {
33
+ caption = createElement('caption');
34
+ element.nodeName === 'fig'
35
+ ? element.appendChild(caption)
36
+ : element.prepend(caption);
37
+ }
38
+ if (!caption.querySelector('title')) {
39
+ caption.prepend(createElement('title'));
40
+ }
41
+ if (!caption.querySelector('p')) {
42
+ caption.appendChild(createElement('p'));
43
+ }
44
+ }
45
+ };
46
+ exports.addMissingCaptions = addMissingCaptions;
28
47
  const moveTitle = (front, createElement) => {
29
48
  var _a, _b;
30
49
  let title = front.querySelector('article-meta > title-group > article-title');
@@ -29,6 +29,7 @@ const processJATS = (doc, sectionCategories) => {
29
29
  if (!front) {
30
30
  return;
31
31
  }
32
+ (0, jats_transformations_1.addMissingCaptions)(doc, createElement);
32
33
  (0, jats_transformations_1.moveTitle)(front, createElement);
33
34
  (0, jats_transformations_1.moveContributors)(front, createElement);
34
35
  (0, jats_transformations_1.moveAffiliations)(front, createElement);
@@ -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 = "3.0.24";
4
+ exports.VERSION = "3.0.25";
@@ -437,7 +437,7 @@ export class JATSDOMParser {
437
437
  {
438
438
  tag: 'caption',
439
439
  node: 'figcaption',
440
- context: 'figure_element/',
440
+ context: 'figure_element/|table_element/',
441
441
  getContent: (node, schema) => {
442
442
  const element = node;
443
443
  const content = [];
@@ -456,11 +456,6 @@ export class JATSDOMParser {
456
456
  return Fragment.from(content);
457
457
  },
458
458
  },
459
- {
460
- tag: 'caption',
461
- node: 'figcaption',
462
- context: 'table_element/',
463
- },
464
459
  {
465
460
  tag: 'caption',
466
461
  node: 'figcaption',
@@ -22,6 +22,24 @@ const createSectionGroup = (type, createElement) => {
22
22
  sec.setAttribute('sec-type', type);
23
23
  return sec;
24
24
  };
25
+ export const addMissingCaptions = (doc, createElement) => {
26
+ const elements = doc.querySelectorAll('fig, table-wrap');
27
+ for (const element of elements) {
28
+ let caption = element.querySelector('caption');
29
+ if (!caption) {
30
+ caption = createElement('caption');
31
+ element.nodeName === 'fig'
32
+ ? element.appendChild(caption)
33
+ : element.prepend(caption);
34
+ }
35
+ if (!caption.querySelector('title')) {
36
+ caption.prepend(createElement('title'));
37
+ }
38
+ if (!caption.querySelector('p')) {
39
+ caption.appendChild(createElement('p'));
40
+ }
41
+ }
42
+ };
25
43
  export const moveTitle = (front, createElement) => {
26
44
  var _a, _b;
27
45
  let title = front.querySelector('article-meta > title-group > article-title');
@@ -18,7 +18,7 @@ import { markComments } from './jats-comments';
18
18
  import { JATSDOMParser } from './jats-dom-parser';
19
19
  import { parseJournal } from './jats-journal-meta-parser';
20
20
  import { updateDocumentIDs } from './jats-parser-utils';
21
- import { createAbstracts, createBackmatter, createBody, createBoxedElementSection, createKeywordsSection, createSupplementaryMaterialsSection, fixTables, moveAffiliations, moveAuthorNotes, moveAwards, moveCaptionsToEnd, moveContributors, moveReferencesToBackmatter, moveTitle, orderTableFootnote, } from './jats-transformations';
21
+ import { addMissingCaptions, createAbstracts, createBackmatter, createBody, createBoxedElementSection, createKeywordsSection, createSupplementaryMaterialsSection, fixTables, moveAffiliations, moveAuthorNotes, moveAwards, moveCaptionsToEnd, moveContributors, moveReferencesToBackmatter, moveTitle, orderTableFootnote, } from './jats-transformations';
22
22
  const processJATS = (doc, sectionCategories) => {
23
23
  const createElement = createElementFn(doc);
24
24
  markComments(doc);
@@ -26,6 +26,7 @@ const processJATS = (doc, sectionCategories) => {
26
26
  if (!front) {
27
27
  return;
28
28
  }
29
+ addMissingCaptions(doc, createElement);
29
30
  moveTitle(front, createElement);
30
31
  moveContributors(front, createElement);
31
32
  moveAffiliations(front, createElement);
@@ -1 +1 @@
1
- export const VERSION = "3.0.24";
1
+ export const VERSION = "3.0.25";
@@ -15,6 +15,7 @@
15
15
  */
16
16
  import { SectionCategory } from '../../schema';
17
17
  export type CreateElement = (tagName: string) => HTMLElement;
18
+ export declare const addMissingCaptions: (doc: Document, createElement: CreateElement) => void;
18
19
  export declare const moveTitle: (front: Element, createElement: CreateElement) => void;
19
20
  export declare const moveAuthorNotes: (front: Element, createElement: CreateElement) => void;
20
21
  export declare const moveAwards: (front: Element) => void;
@@ -1 +1 @@
1
- export declare const VERSION = "3.0.24";
1
+ export declare const VERSION = "3.0.25";
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": "3.0.24",
4
+ "version": "3.0.25",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",