@manuscripts/transform 2.6.0 → 2.6.1-LEAN-3966.1

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.
Files changed (126) hide show
  1. package/dist/cjs/index.js +6 -6
  2. package/dist/cjs/jats/{jats-exporter.js → exporter/jats-exporter.js} +305 -416
  3. package/dist/cjs/jats/{jats-versions.js → exporter/jats-versions.js} +1 -3
  4. package/dist/cjs/{transformer → jats/exporter}/labels.js +4 -4
  5. package/dist/cjs/{transformer/filename.js → jats/importer/create-article-node.js} +10 -9
  6. package/dist/cjs/jats/importer/jats-comments.js +32 -111
  7. package/dist/cjs/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +350 -10
  8. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +11 -1
  9. package/dist/cjs/jats/importer/jats-parser-utils.js +76 -9
  10. package/dist/cjs/jats/importer/jats-transformations.js +397 -0
  11. package/dist/cjs/jats/importer/parse-jats-article.js +44 -101
  12. package/dist/cjs/jats/index.js +7 -7
  13. package/dist/cjs/{transformer/models.js → lib/deafults.js} +3 -1
  14. package/dist/cjs/lib/utils.js +3 -1
  15. package/dist/cjs/schema/nodes/highlight_marker.js +0 -4
  16. package/dist/cjs/transformer/id.js +1 -5
  17. package/dist/cjs/transformer/index.js +0 -18
  18. package/dist/cjs/version.js +1 -1
  19. package/dist/es/index.js +5 -5
  20. package/dist/es/jats/{jats-exporter.js → exporter/jats-exporter.js} +300 -411
  21. package/dist/es/jats/{jats-versions.js → exporter/jats-versions.js} +0 -1
  22. package/dist/es/{transformer → jats/exporter}/labels.js +4 -4
  23. package/dist/{cjs/transformer/model-map.js → es/jats/importer/create-article-node.js} +8 -10
  24. package/dist/es/jats/importer/jats-comments.js +32 -107
  25. package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +350 -10
  26. package/dist/es/jats/importer/jats-journal-meta-parser.js +9 -0
  27. package/dist/es/jats/importer/jats-parser-utils.js +78 -11
  28. package/dist/es/jats/importer/jats-transformations.js +377 -0
  29. package/dist/es/jats/importer/parse-jats-article.js +44 -99
  30. package/dist/es/jats/index.js +5 -3
  31. package/dist/{types/transformer/timestamp.d.ts → es/lib/deafults.js} +2 -2
  32. package/dist/es/lib/utils.js +1 -0
  33. package/dist/es/schema/nodes/highlight_marker.js +0 -4
  34. package/dist/es/transformer/id.js +0 -3
  35. package/dist/es/transformer/index.js +0 -16
  36. package/dist/es/version.js +1 -1
  37. package/dist/types/index.d.ts +6 -6
  38. package/dist/types/jats/{jats-exporter.d.ts → exporter/jats-exporter.d.ts} +16 -29
  39. package/dist/types/jats/{jats-versions.d.ts → exporter/jats-versions.d.ts} +0 -1
  40. package/dist/types/{transformer → jats/exporter}/labels.d.ts +2 -2
  41. package/dist/{es/transformer/footnote-category.js → types/jats/importer/create-article-node.d.ts} +3 -2
  42. package/dist/types/jats/importer/jats-comments.d.ts +2 -15
  43. package/dist/types/jats/importer/{jats-body-dom-parser.d.ts → jats-dom-parser.d.ts} +1 -1
  44. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +9 -0
  45. package/dist/types/jats/importer/jats-parser-utils.d.ts +2 -2
  46. package/dist/types/jats/importer/jats-transformations.d.ts +33 -0
  47. package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
  48. package/dist/types/jats/index.d.ts +5 -3
  49. package/dist/types/jats/types.d.ts +1 -0
  50. package/dist/{es/transformer/models.js → types/lib/deafults.d.ts} +2 -2
  51. package/dist/types/lib/utils.d.ts +1 -0
  52. package/dist/types/schema/nodes/bibliography_item.d.ts +3 -3
  53. package/dist/types/schema/nodes/contributor.d.ts +10 -0
  54. package/dist/types/schema/nodes/highlight_marker.d.ts +0 -2
  55. package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
  56. package/dist/types/schema/nodes/manuscript.d.ts +8 -7
  57. package/dist/types/schema/nodes/title.d.ts +0 -3
  58. package/dist/types/transformer/id.d.ts +0 -3
  59. package/dist/types/transformer/index.d.ts +0 -16
  60. package/dist/types/version.d.ts +1 -1
  61. package/package.json +2 -1
  62. package/dist/cjs/__tests__/data/project-dump.json +0 -825
  63. package/dist/cjs/jats/importer/index.js +0 -22
  64. package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
  65. package/dist/cjs/jats/importer/jats-reference-parser.js +0 -130
  66. package/dist/cjs/jats/importer/jats-references.js +0 -34
  67. package/dist/cjs/transformer/__tests__/__helpers__/doc.js +0 -37
  68. package/dist/cjs/transformer/builders.js +0 -219
  69. package/dist/cjs/transformer/decode.js +0 -898
  70. package/dist/cjs/transformer/document-object-types.js +0 -31
  71. package/dist/cjs/transformer/encode.js +0 -674
  72. package/dist/cjs/transformer/footnote-category.js +0 -20
  73. package/dist/cjs/transformer/footnotes-order.js +0 -60
  74. package/dist/cjs/transformer/highlight-markers.js +0 -138
  75. package/dist/cjs/transformer/html.js +0 -400
  76. package/dist/cjs/transformer/manuscript-dependencies.js +0 -21
  77. package/dist/cjs/transformer/object-types.js +0 -57
  78. package/dist/cjs/transformer/project-bundle.js +0 -94
  79. package/dist/cjs/transformer/serializer.js +0 -23
  80. package/dist/cjs/transformer/timestamp.js +0 -20
  81. package/dist/cjs/transformer/update-identifiers.js +0 -93
  82. package/dist/es/__tests__/data/project-dump.json +0 -825
  83. package/dist/es/jats/importer/index.js +0 -16
  84. package/dist/es/jats/importer/jats-front-parser.js +0 -315
  85. package/dist/es/jats/importer/jats-reference-parser.js +0 -127
  86. package/dist/es/jats/importer/jats-references.js +0 -30
  87. package/dist/es/transformer/__tests__/__helpers__/doc.js +0 -29
  88. package/dist/es/transformer/builders.js +0 -186
  89. package/dist/es/transformer/decode.js +0 -888
  90. package/dist/es/transformer/document-object-types.js +0 -28
  91. package/dist/es/transformer/encode.js +0 -664
  92. package/dist/es/transformer/filename.js +0 -23
  93. package/dist/es/transformer/footnotes-order.js +0 -55
  94. package/dist/es/transformer/highlight-markers.js +0 -132
  95. package/dist/es/transformer/html.js +0 -393
  96. package/dist/es/transformer/manuscript-dependencies.js +0 -17
  97. package/dist/es/transformer/model-map.js +0 -22
  98. package/dist/es/transformer/object-types.js +0 -52
  99. package/dist/es/transformer/project-bundle.js +0 -85
  100. package/dist/es/transformer/serializer.js +0 -17
  101. package/dist/es/transformer/timestamp.js +0 -16
  102. package/dist/es/transformer/update-identifiers.js +0 -87
  103. package/dist/types/jats/importer/index.d.ts +0 -16
  104. package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
  105. package/dist/types/jats/importer/jats-reference-parser.d.ts +0 -19
  106. package/dist/types/jats/importer/jats-references.d.ts +0 -12
  107. package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +0 -18
  108. package/dist/types/transformer/builders.d.ts +0 -61
  109. package/dist/types/transformer/decode.d.ts +0 -52
  110. package/dist/types/transformer/document-object-types.d.ts +0 -17
  111. package/dist/types/transformer/encode.d.ts +0 -29
  112. package/dist/types/transformer/filename.d.ts +0 -16
  113. package/dist/types/transformer/footnote-category.d.ts +0 -17
  114. package/dist/types/transformer/footnotes-order.d.ts +0 -22
  115. package/dist/types/transformer/highlight-markers.d.ts +0 -31
  116. package/dist/types/transformer/html.d.ts +0 -36
  117. package/dist/types/transformer/manuscript-dependencies.d.ts +0 -4
  118. package/dist/types/transformer/model-map.d.ts +0 -19
  119. package/dist/types/transformer/models.d.ts +0 -48
  120. package/dist/types/transformer/object-types.d.ts +0 -30
  121. package/dist/types/transformer/project-bundle.d.ts +0 -30
  122. package/dist/types/transformer/serializer.d.ts +0 -19
  123. package/dist/types/transformer/update-identifiers.d.ts +0 -23
  124. package/dist/types/types.d.ts +0 -2
  125. /package/dist/cjs/{types.js → jats/types.js} +0 -0
  126. /package/dist/es/{types.js → jats/types.js} +0 -0
@@ -1,23 +0,0 @@
1
- /*!
2
- * © 2019 Atypon Systems LLC
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- export const generateAttachmentFilename = (id, contentType) => {
17
- const basename = id.replace(':', '_');
18
- if (!contentType) {
19
- return basename;
20
- }
21
- const [, mimeSubType] = contentType.split('/');
22
- return `${basename}.${mimeSubType}`;
23
- };
@@ -1,55 +0,0 @@
1
- /*!
2
- * © 2022 Atypon Systems LLC
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- export const createOrderedFootnotesIDs = (doc) => {
17
- const footnotesRefs = [...doc.querySelectorAll('xref[ref-type="fn"][rid]')];
18
- const footnotes = [...doc.querySelectorAll('fn:not([fn-type])')];
19
- const authorNotesIDs = [...doc.querySelectorAll('author-notes > fn')].map((an) => an.getAttribute('id'));
20
- const tableElementFooters = [
21
- ...doc.querySelectorAll('table-wrap-foot > fn'),
22
- ].map((footer) => footer.getAttribute('id'));
23
- const orderedFootnotesIDs = [];
24
- footnotesRefs.forEach((ref) => {
25
- const refID = ref.getAttribute('rid');
26
- if (refID) {
27
- orderedFootnotesIDs.push(refID);
28
- }
29
- });
30
- footnotes.forEach((footnote) => {
31
- const id = footnote.getAttribute('id');
32
- if (id &&
33
- !authorNotesIDs.includes(id) &&
34
- !orderedFootnotesIDs.includes(id) &&
35
- !tableElementFooters.includes(id)) {
36
- orderedFootnotesIDs.push(id);
37
- }
38
- });
39
- return orderedFootnotesIDs;
40
- };
41
- export const handleFootnotesOrder = (orderedFootnotesIDs, replacements, footnotesOrder) => {
42
- const footnotesList = [];
43
- let index = 0;
44
- orderedFootnotesIDs.forEach((refID) => {
45
- const fnID = replacements.get(refID);
46
- if (fnID) {
47
- footnotesList.push({
48
- index,
49
- id: fnID,
50
- });
51
- index++;
52
- }
53
- });
54
- footnotesOrder.footnotesList = footnotesList;
55
- };
@@ -1,132 +0,0 @@
1
- /*!
2
- * © 2019 Atypon Systems LLC
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- export const highlightableFields = [
17
- 'caption',
18
- 'contents',
19
- 'title',
20
- ];
21
- export const isHighlightableModel = (model) => {
22
- for (const field of highlightableFields) {
23
- if (field in model) {
24
- return true;
25
- }
26
- }
27
- return false;
28
- };
29
- export const extractCommentMarkers = (model) => {
30
- if (!isHighlightableModel(model)) {
31
- return [];
32
- }
33
- const comments = new Map();
34
- for (const field of highlightableFields) {
35
- let html = model[field];
36
- if (!html || !html.includes('highlight-marker')) {
37
- continue;
38
- }
39
- const template = document.createElement('template');
40
- template.innerHTML = `<div>${html}</div>`;
41
- const element = template.content.firstChild;
42
- if (!element) {
43
- continue;
44
- }
45
- const markers = element.querySelectorAll('span.highlight-marker');
46
- if (!markers.length) {
47
- continue;
48
- }
49
- for (const marker of markers) {
50
- const markerHTML = marker.outerHTML;
51
- const offset = html.indexOf(markerHTML);
52
- if (offset === -1) {
53
- continue;
54
- }
55
- const id = marker.getAttribute('id');
56
- const target = marker.getAttribute('data-target-id');
57
- if (id && target) {
58
- const position = marker.getAttribute('data-position');
59
- if (position === 'start') {
60
- const comment = {
61
- _id: id,
62
- from: offset,
63
- to: -1,
64
- };
65
- comments.set(id, comment);
66
- }
67
- else if (position === 'end') {
68
- const comment = comments.get(id);
69
- if (comment) {
70
- comment.to = offset;
71
- }
72
- }
73
- else if (position === 'point') {
74
- const comment = {
75
- _id: id,
76
- from: offset,
77
- to: offset,
78
- };
79
- comments.set(id, comment);
80
- }
81
- }
82
- html =
83
- html.substring(0, offset) + html.substring(offset + markerHTML.length);
84
- }
85
- model[field] = html;
86
- }
87
- return Array.from(comments.values());
88
- };
89
- export const insertHighlightMarkers = (contents, commentAnnotations) => {
90
- let output = contents;
91
- const sortedComments = commentAnnotations.sort((a, b) => {
92
- if (a.selector && b.selector) {
93
- return b.selector.from - a.selector.from;
94
- }
95
- else {
96
- return 0;
97
- }
98
- });
99
- for (const comment of sortedComments) {
100
- let element;
101
- if (comment.selector) {
102
- if (comment.selector.from === comment.selector.to) {
103
- element = createHighlightElement(comment, 'point');
104
- output = injectHighlightMarker(element, comment.selector.from, output);
105
- }
106
- else {
107
- element = createHighlightElement(comment, 'start');
108
- output = injectHighlightMarker(element, comment.selector.from, output);
109
- const updatedEndOffset = element.outerHTML.length + comment.selector.to;
110
- element = createHighlightElement(comment, 'end');
111
- output = injectHighlightMarker(element, updatedEndOffset, output);
112
- }
113
- }
114
- }
115
- return output;
116
- };
117
- function injectHighlightMarker(element, offset, contents) {
118
- const parts = [
119
- contents.substring(0, offset),
120
- element.outerHTML,
121
- contents.substring(offset),
122
- ];
123
- return parts.join('');
124
- }
125
- const createHighlightElement = (comment, position) => {
126
- const element = document.createElement('span');
127
- element.className = 'highlight-marker';
128
- element.setAttribute('id', comment._id);
129
- element.setAttribute('data-target-id', comment.target);
130
- element.setAttribute('data-position', position);
131
- return element;
132
- };
@@ -1,393 +0,0 @@
1
- /*!
2
- * © 2019 Atypon Systems LLC
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { ObjectTypes, } from '@manuscripts/json-schema';
17
- import { DOMSerializer } from 'prosemirror-model';
18
- import serializeToXML from 'w3c-xmlserializer';
19
- import { createCounter } from '../jats/jats-exporter';
20
- import { buildStyledContentClass } from '../lib/styled-content';
21
- import { schema, } from '../schema';
22
- import { generateAttachmentFilename } from './filename';
23
- import { buildTargets } from './labels';
24
- import { isNodeType } from './node-types';
25
- import { hasObjectType } from './object-types';
26
- import { findJournal, findManuscript, findTitles } from './project-bundle';
27
- import { chooseSecType } from './section-category';
28
- const chooseNodeName = (element) => {
29
- const nodeName = element.nodeName.toLowerCase();
30
- if (nodeName === 'figure') {
31
- if (element.classList.contains('table')) {
32
- return 'figure-table';
33
- }
34
- if (element.classList.contains('listing')) {
35
- return 'figure-listing';
36
- }
37
- if (element.classList.contains('equation')) {
38
- return 'figure-equation';
39
- }
40
- return 'figure';
41
- }
42
- else if (nodeName === 'section') {
43
- const sectionCategory = element.getAttribute('data-category');
44
- if (sectionCategory) {
45
- const secType = chooseSecType(sectionCategory);
46
- if (secType) {
47
- return secType;
48
- }
49
- }
50
- }
51
- else if (element.classList.length === 1) {
52
- const className = element.classList.item(0);
53
- if (className && !className.startsWith('MP')) {
54
- return className;
55
- }
56
- }
57
- return nodeName;
58
- };
59
- const createDefaultIdGenerator = () => {
60
- const counter = createCounter();
61
- return async (element) => {
62
- const nodeName = chooseNodeName(element);
63
- const index = counter.increment(nodeName);
64
- return `${nodeName}-${index}`;
65
- };
66
- };
67
- export class HTMLTransformer {
68
- constructor() {
69
- this.serializeToHTML = async (fragment, modelMap, options = {}) => {
70
- const { idGenerator, mediaPathGenerator } = options;
71
- this.modelMap = modelMap;
72
- this.labelTargets = buildTargets(fragment);
73
- this.document = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', document.implementation.createDocumentType('html', '', ''));
74
- const article = this.document.createElement('article');
75
- this.document.documentElement.appendChild(article);
76
- article.appendChild(this.buildFront());
77
- article.appendChild(this.buildBody(fragment));
78
- this.fixBody(fragment);
79
- await this.rewriteIDs(idGenerator);
80
- if (mediaPathGenerator) {
81
- await this.rewriteMediaPaths(mediaPathGenerator);
82
- }
83
- return serializeToXML(this.document);
84
- };
85
- this.rewriteMediaPaths = async (mediaPathGenerator) => {
86
- for (const image of this.document.querySelectorAll('figure > img')) {
87
- const parentFigure = image.parentNode;
88
- if (parentFigure) {
89
- const parentID = parentFigure.getAttribute('data-uuid');
90
- if (parentID) {
91
- const newSrc = await mediaPathGenerator(image, parentID);
92
- image.setAttribute('src', newSrc);
93
- }
94
- }
95
- }
96
- };
97
- this.rewriteIDs = async (idGenerator = createDefaultIdGenerator()) => {
98
- const idMap = new Map();
99
- for (const element of this.document.querySelectorAll('[id]')) {
100
- const previousID = element.getAttribute('id');
101
- if (previousID && !previousID.match(/^MP[a-z]+:[a-z0-9-]+$/i)) {
102
- continue;
103
- }
104
- const newID = await idGenerator(element);
105
- if (newID) {
106
- element.setAttribute('id', newID);
107
- if (previousID) {
108
- const ancores = [
109
- ...this.document.querySelectorAll(`a[href="#${previousID}"]`),
110
- ];
111
- ancores.map((a) => a.setAttribute('href', `#${newID}`));
112
- element.setAttribute('data-uuid', previousID);
113
- }
114
- }
115
- else {
116
- element.removeAttribute('id');
117
- }
118
- if (previousID) {
119
- idMap.set(previousID, newID);
120
- }
121
- }
122
- for (const node of this.document.querySelectorAll('[data-reference-ids]')) {
123
- const rids = node.getAttribute('data-reference-ids');
124
- if (rids) {
125
- const newRIDs = rids
126
- .split(/\s+/)
127
- .filter(Boolean)
128
- .map((previousRID) => idMap.get(previousRID))
129
- .filter(Boolean);
130
- if (newRIDs.length) {
131
- node.setAttribute('data-reference-ids', newRIDs.join(' '));
132
- }
133
- }
134
- }
135
- for (const node of this.document.querySelectorAll('[data-reference-id]')) {
136
- const rid = node.getAttribute('data-reference-id');
137
- if (rid) {
138
- const newRID = idMap.get(rid);
139
- if (newRID) {
140
- node.setAttribute('data-reference-id', newRID);
141
- }
142
- }
143
- }
144
- };
145
- this.buildFront = () => {
146
- const manuscript = findManuscript(this.modelMap);
147
- const journal = findJournal(this.modelMap);
148
- const titles = findTitles(this.modelMap);
149
- if (!manuscript) {
150
- throw new Error('Manuscript not found in project modelMap');
151
- }
152
- const front = this.document.createElement('header');
153
- if (manuscript.headerFigure) {
154
- const figure = this.modelMap.get(manuscript.headerFigure);
155
- if (figure) {
156
- const headerFigure = document.createElement('figure');
157
- headerFigure.setAttribute('id', figure._id);
158
- front.appendChild(headerFigure);
159
- const filename = generateAttachmentFilename(figure._id, figure.contentType);
160
- const img = this.document.createElement('img');
161
- img.setAttribute('src', filename);
162
- headerFigure.appendChild(img);
163
- }
164
- }
165
- const articleMeta = this.document.createElement('div');
166
- front.appendChild(articleMeta);
167
- const title = this.document.createElement('h1');
168
- if (titles.title) {
169
- title.innerHTML = titles.title;
170
- }
171
- if (journal === null || journal === void 0 ? void 0 : journal.title) {
172
- title.setAttribute('data-journal', journal.title);
173
- }
174
- articleMeta.appendChild(title);
175
- if (manuscript.DOI) {
176
- const articleID = this.document.createElement('article-id');
177
- articleID.setAttribute('pub-id-type', 'doi');
178
- articleID.innerHTML = manuscript.DOI;
179
- articleMeta.append(articleID);
180
- }
181
- this.buildContributors(articleMeta);
182
- return front;
183
- };
184
- this.buildBody = (fragment) => {
185
- const getModel = (id) => id ? this.modelMap.get(id) : undefined;
186
- const nodes = {};
187
- for (const [name, node] of Object.entries(schema.nodes)) {
188
- if (node.spec.toDOM) {
189
- nodes[name] = node.spec.toDOM;
190
- }
191
- }
192
- nodes.citation = (node) => {
193
- const citationNode = node;
194
- const element = this.document.createElement('span');
195
- element.setAttribute('class', 'citation');
196
- const rids = citationNode.attrs.rids;
197
- if (rids.length) {
198
- element.setAttribute('data-reference-ids', rids.join(' '));
199
- }
200
- if (citationNode.attrs.contents) {
201
- element.innerHTML = citationNode.attrs.contents;
202
- }
203
- return element;
204
- };
205
- nodes.cross_reference = (node) => {
206
- const xref = node;
207
- const element = this.document.createElement('a');
208
- element.classList.add('cross-reference');
209
- element.setAttribute('data-reference-ids', xref.attrs.rids.join(' '));
210
- element.textContent = xref.attrs.customLabel || xref.attrs.label;
211
- return element;
212
- };
213
- nodes.listing = (node) => {
214
- const listingNode = node;
215
- const pre = this.document.createElement('pre');
216
- if (listingNode.attrs.id) {
217
- pre.setAttribute('id', listingNode.attrs.id);
218
- }
219
- pre.classList.add('listing');
220
- const code = this.document.createElement('code');
221
- if (listingNode.attrs.languageKey) {
222
- code.setAttribute('data-language', listingNode.attrs.languageKey);
223
- }
224
- code.textContent = listingNode.attrs.contents;
225
- pre.appendChild(code);
226
- return pre;
227
- };
228
- nodes.text = (node) => node.text;
229
- const marks = {};
230
- for (const [name, mark] of Object.entries(schema.marks)) {
231
- if (mark.spec.toDOM) {
232
- marks[name] = mark.spec.toDOM;
233
- }
234
- }
235
- marks.styled = (mark) => {
236
- const inlineStyle = getModel(mark.attrs.rid);
237
- const attrs = {
238
- class: buildStyledContentClass(mark.attrs, inlineStyle),
239
- };
240
- return ['span', attrs];
241
- };
242
- nodes.comments = () => '';
243
- const serializer = new DOMSerializer(nodes, marks);
244
- return serializer.serializeFragment(fragment, { document });
245
- };
246
- this.idSelector = (id) => '#' + id.replace(/:/g, '\\:');
247
- this.fixFigure = (node) => {
248
- const figure = this.document.querySelector(`[id="${node.attrs.id}"]`);
249
- if (figure) {
250
- const filename = generateAttachmentFilename(node.attrs.id, node.attrs.contentType);
251
- const img = this.document.createElement('img');
252
- img.setAttribute('src', filename);
253
- figure.insertBefore(img, figure.firstChild);
254
- }
255
- };
256
- this.fixBody = (fragment) => {
257
- fragment.descendants((node) => {
258
- if (node.attrs.id) {
259
- const selector = this.idSelector(node.attrs.id);
260
- const element = this.document.querySelector(`${selector}`);
261
- if (element && this.labelTargets) {
262
- const target = this.labelTargets.get(node.attrs.id);
263
- if (target) {
264
- const label = this.document.createElement('label');
265
- label.textContent = target.label;
266
- element.appendChild(label);
267
- }
268
- }
269
- if (node.attrs.titleSuppressed) {
270
- const title = this.document.querySelector(`${selector} > h1`);
271
- if (title && title.parentNode) {
272
- title.parentNode.removeChild(title);
273
- }
274
- }
275
- if (node.attrs.suppressCaption) {
276
- const caption = this.document.querySelector(`${selector} > figcaption`);
277
- if (caption && caption.parentNode) {
278
- caption.parentNode.removeChild(caption);
279
- }
280
- }
281
- if (isNodeType(node, 'figure')) {
282
- this.fixFigure(node);
283
- }
284
- if (isNodeType(node, 'figure_element')) {
285
- const figureGroup = this.document.querySelector(`${selector}`);
286
- if (figureGroup) {
287
- const figures = this.document.querySelectorAll(`${selector} > figure`);
288
- const caption = this.document.querySelector(`${selector} > figcaption`);
289
- const listing = this.document.querySelector(`${selector} > pre.listing`);
290
- if (listing && !listing.textContent) {
291
- listing.remove();
292
- }
293
- if (figures.length === 1) {
294
- const [figure] = figures;
295
- figure.setAttribute('data-fig-type', 'figure');
296
- if (caption) {
297
- figure.insertBefore(caption, figure.firstChild);
298
- }
299
- const label = this.document.querySelector(`${selector} > label`);
300
- if (label) {
301
- figure.insertBefore(label, figure.firstChild);
302
- }
303
- if (figureGroup.parentElement) {
304
- figureGroup.parentElement.replaceChild(figure, figureGroup);
305
- }
306
- }
307
- if (figures.length === 0 && !caption) {
308
- figureGroup.remove();
309
- }
310
- }
311
- }
312
- }
313
- });
314
- };
315
- }
316
- buildContributors(articleMeta) {
317
- const contributors = Array.from(this.modelMap.values()).filter(hasObjectType(ObjectTypes.Contributor));
318
- const affiliationIDs = [];
319
- if (contributors && contributors.length) {
320
- const contribGroup = this.document.createElement('div');
321
- contribGroup.classList.add('contrib-group');
322
- articleMeta.appendChild(contribGroup);
323
- contributors.sort((a, b) => Number(a.priority) - Number(b.priority));
324
- contributors.forEach((contributor) => {
325
- const contrib = this.document.createElement('span');
326
- contrib.classList.add('contrib');
327
- contrib.setAttribute('id', contributor._id);
328
- if (contributor.isCorresponding) {
329
- contrib.setAttribute('data-corresp', 'yes');
330
- }
331
- const name = this.document.createElement('span');
332
- name.classList.add('contrib-name');
333
- contrib.appendChild(name);
334
- const { given, family } = contributor.bibliographicName;
335
- if (given) {
336
- const givenNames = this.document.createElement('span');
337
- givenNames.classList.add('contrib-given-names');
338
- givenNames.textContent = given;
339
- name.appendChild(givenNames);
340
- }
341
- if (family) {
342
- if (given) {
343
- const separator = document.createTextNode(' ');
344
- name.appendChild(separator);
345
- }
346
- const surname = this.document.createElement('span');
347
- surname.classList.add('contrib-surname');
348
- surname.textContent = family;
349
- name.appendChild(surname);
350
- }
351
- if (contributor.email) {
352
- const link = this.document.createElement('a');
353
- link.href = `mailto:${contributor.email}`;
354
- contrib.appendChild(link);
355
- }
356
- if (contributor.affiliations) {
357
- contributor.affiliations.forEach((rid) => {
358
- const link = this.document.createElement('a');
359
- link.setAttribute('data-ref-type', 'aff');
360
- link.setAttribute('href', '#' + rid);
361
- const affiliationIndex = affiliationIDs.indexOf(rid);
362
- if (affiliationIndex > -1) {
363
- link.textContent = String(affiliationIndex + 1);
364
- }
365
- else {
366
- affiliationIDs.push(rid);
367
- link.textContent = String(affiliationIDs.length);
368
- }
369
- contrib.appendChild(link);
370
- });
371
- }
372
- contribGroup.appendChild(contrib);
373
- });
374
- }
375
- if (affiliationIDs.length) {
376
- const affiliationList = this.document.createElement('ol');
377
- affiliationList.classList.add('affiliations-list');
378
- articleMeta.appendChild(affiliationList);
379
- for (const affiliationID of affiliationIDs) {
380
- const affiliation = this.modelMap.get(affiliationID);
381
- if (affiliation) {
382
- const affiliationItem = this.document.createElement('li');
383
- affiliationItem.classList.add('affiliation');
384
- affiliationItem.setAttribute('id', affiliation._id);
385
- if (affiliation.institution) {
386
- affiliationItem.textContent = affiliation.institution;
387
- }
388
- affiliationList.appendChild(affiliationItem);
389
- }
390
- }
391
- }
392
- }
393
- }
@@ -1,17 +0,0 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import { generateID } from './id';
13
- export const fromPrototype = (model) => {
14
- const { _id } = model, data = __rest(model, ["_id"]);
15
- const output = Object.assign(Object.assign({}, data), { prototype: _id, _id: generateID(model.objectType) });
16
- return output;
17
- };
@@ -1,22 +0,0 @@
1
- /*!
2
- * © 2020 Atypon Systems LLC
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { generateID } from './id';
17
- export const addModelToMap = (modelMap) => (data) => {
18
- if (!data._id) {
19
- data._id = generateID(data.objectType);
20
- }
21
- modelMap.set(data._id, data);
22
- };