@manuscripts/transform 4.3.52 → 4.4.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.
Files changed (175) hide show
  1. package/dist/cjs/jats/__tests__/jats-roundtrip.test.js +3 -3
  2. package/dist/cjs/schema/types.js +18 -0
  3. package/dist/cjs/version.js +1 -1
  4. package/dist/es/jats/__tests__/jats-roundtrip.test.js +3 -3
  5. package/dist/es/schema/types.js +17 -0
  6. package/dist/es/version.js +1 -1
  7. package/dist/types/jats/__tests__/utils.d.ts +1 -1
  8. package/dist/types/schema/types.d.ts +16 -0
  9. package/dist/types/version.d.ts +1 -1
  10. package/package.json +22 -21
  11. package/src/errors.ts +28 -0
  12. package/src/getVersion.ts +21 -0
  13. package/src/index.ts +28 -0
  14. package/src/jats/__tests__/__fixtures__/debug-example.xml +136 -0
  15. package/src/jats/__tests__/__fixtures__/jats-abstract-no-body.xml +163 -0
  16. package/src/jats/__tests__/__fixtures__/jats-citations.xml +472 -0
  17. package/src/jats/__tests__/__fixtures__/jats-comments.xml +46 -0
  18. package/src/jats/__tests__/__fixtures__/jats-document.xml +134 -0
  19. package/src/jats/__tests__/__fixtures__/jats-example-doc.xml +1235 -0
  20. package/src/jats/__tests__/__fixtures__/jats-example-front-only.xml +26 -0
  21. package/src/jats/__tests__/__fixtures__/jats-example-full.xml +209 -0
  22. package/src/jats/__tests__/__fixtures__/jats-example-no-back.xml +156 -0
  23. package/src/jats/__tests__/__fixtures__/jats-example-no-body.xml +91 -0
  24. package/src/jats/__tests__/__fixtures__/jats-example.xml +221 -0
  25. package/src/jats/__tests__/__fixtures__/jats-fn-group.xml +60 -0
  26. package/src/jats/__tests__/__fixtures__/jats-import-no-refs.xml +1077 -0
  27. package/src/jats/__tests__/__fixtures__/jats-import.xml +1561 -0
  28. package/src/jats/__tests__/__fixtures__/jats-roundtrip.xml +133 -0
  29. package/src/jats/__tests__/__fixtures__/jats-tables-example.xml +2043 -0
  30. package/src/jats/__tests__/__fixtures__/math-fragment.xml +12 -0
  31. package/src/jats/__tests__/__snapshots__/citeproc.test.ts.snap +57 -0
  32. package/src/jats/__tests__/__snapshots__/create-article-node.test.ts.snap +65 -0
  33. package/src/jats/__tests__/__snapshots__/jats-exporter.test.ts.snap +7 -0
  34. package/src/jats/__tests__/__snapshots__/jats-importer.test.ts.snap +59605 -0
  35. package/src/jats/__tests__/__snapshots__/jats-roundtrip.test.ts.snap +18 -0
  36. package/src/jats/__tests__/citations.ts +25 -0
  37. package/src/jats/__tests__/citeproc.test.ts +195 -0
  38. package/src/jats/__tests__/create-article-node.test.ts +29 -0
  39. package/src/jats/__tests__/data/section-categories.ts +212 -0
  40. package/src/jats/__tests__/files.ts +24 -0
  41. package/src/jats/__tests__/jats-exporter.test.ts +223 -0
  42. package/src/jats/__tests__/jats-importer.test.ts +567 -0
  43. package/src/jats/__tests__/jats-roundtrip.test.ts +66 -0
  44. package/src/jats/__tests__/utils.ts +90 -0
  45. package/src/jats/exporter/citeproc.ts +265 -0
  46. package/src/jats/exporter/jats-exporter.ts +2090 -0
  47. package/src/jats/exporter/jats-versions.ts +50 -0
  48. package/src/jats/exporter/labels.ts +101 -0
  49. package/src/jats/importer/create-article-node.ts +52 -0
  50. package/src/jats/importer/jats-comments.ts +111 -0
  51. package/src/jats/importer/jats-dom-parser.ts +1260 -0
  52. package/src/jats/importer/jats-parser-utils.ts +234 -0
  53. package/src/jats/importer/jats-transformations.ts +591 -0
  54. package/src/jats/importer/parse-jats-article.ts +106 -0
  55. package/src/jats/index.ts +21 -0
  56. package/src/jats/types.ts +16 -0
  57. package/src/lib/__tests__/footnotes.test.ts +36 -0
  58. package/src/lib/citeproc.ts +30 -0
  59. package/src/lib/credit-roles.ts +91 -0
  60. package/src/lib/deafults.ts +17 -0
  61. package/src/lib/footnotes.ts +85 -0
  62. package/src/lib/html.ts +56 -0
  63. package/src/lib/section-categories.ts +27 -0
  64. package/src/lib/utils.ts +145 -0
  65. package/src/lib/xml.ts +28 -0
  66. package/src/schema/__tests__/docs.ts +1911 -0
  67. package/src/schema/__tests__/groups.test.ts +61 -0
  68. package/src/schema/__tests__/migration.test.ts +23 -0
  69. package/src/schema/groups.ts +36 -0
  70. package/src/schema/index.ts +286 -0
  71. package/src/schema/marks.ts +254 -0
  72. package/src/schema/migration/migrate.ts +77 -0
  73. package/src/schema/migration/migration-script.ts +26 -0
  74. package/src/schema/migration/migration-scripts/1.2.5.ts +44 -0
  75. package/src/schema/migration/migration-scripts/2.3.22.ts +52 -0
  76. package/src/schema/migration/migration-scripts/3.0.12.ts +33 -0
  77. package/src/schema/migration/migration-scripts/3.0.21.ts +50 -0
  78. package/src/schema/migration/migration-scripts/3.0.30.ts +65 -0
  79. package/src/schema/migration/migration-scripts/3.0.31.ts +40 -0
  80. package/src/schema/migration/migration-scripts/3.0.41.ts +37 -0
  81. package/src/schema/migration/migration-scripts/3.0.55.ts +42 -0
  82. package/src/schema/migration/migration-scripts/3.0.56.ts +114 -0
  83. package/src/schema/migration/migration-scripts/4.2.13.ts +37 -0
  84. package/src/schema/migration/migration-scripts/4.2.15.ts +48 -0
  85. package/src/schema/migration/migration-scripts/4.3.23.ts +55 -0
  86. package/src/schema/migration/migration-scripts/4.3.34.ts +132 -0
  87. package/src/schema/migration/migration-scripts/4.3.35.ts +41 -0
  88. package/src/schema/migration/migration-scripts/index.ts +49 -0
  89. package/src/schema/nodes/abstracts.ts +29 -0
  90. package/src/schema/nodes/affiliation.ts +88 -0
  91. package/src/schema/nodes/affiliations.ts +30 -0
  92. package/src/schema/nodes/alt_text.ts +36 -0
  93. package/src/schema/nodes/alt_title.ts +40 -0
  94. package/src/schema/nodes/alt_titles_section.ts +58 -0
  95. package/src/schema/nodes/attachment.ts +46 -0
  96. package/src/schema/nodes/attachments.ts +45 -0
  97. package/src/schema/nodes/attribution.ts +38 -0
  98. package/src/schema/nodes/author_notes.ts +44 -0
  99. package/src/schema/nodes/award.ts +52 -0
  100. package/src/schema/nodes/awards.ts +45 -0
  101. package/src/schema/nodes/backmatter.ts +31 -0
  102. package/src/schema/nodes/bibliography_element.ts +58 -0
  103. package/src/schema/nodes/bibliography_item.ts +108 -0
  104. package/src/schema/nodes/bibliography_section.ts +60 -0
  105. package/src/schema/nodes/blockquote_element.ts +79 -0
  106. package/src/schema/nodes/body.ts +29 -0
  107. package/src/schema/nodes/box_element.ts +67 -0
  108. package/src/schema/nodes/caption.ts +67 -0
  109. package/src/schema/nodes/caption_title.ts +67 -0
  110. package/src/schema/nodes/citation.ts +70 -0
  111. package/src/schema/nodes/comment.ts +50 -0
  112. package/src/schema/nodes/comments.ts +28 -0
  113. package/src/schema/nodes/contributor.ts +87 -0
  114. package/src/schema/nodes/contributors.ts +40 -0
  115. package/src/schema/nodes/core_section.ts +27 -0
  116. package/src/schema/nodes/corresp.ts +49 -0
  117. package/src/schema/nodes/cross_reference.ts +64 -0
  118. package/src/schema/nodes/doc.ts +21 -0
  119. package/src/schema/nodes/embed.ts +55 -0
  120. package/src/schema/nodes/equation.ts +65 -0
  121. package/src/schema/nodes/equation_element.ts +61 -0
  122. package/src/schema/nodes/figure.ts +65 -0
  123. package/src/schema/nodes/figure_element.ts +73 -0
  124. package/src/schema/nodes/footnote.ts +95 -0
  125. package/src/schema/nodes/footnotes_element.ts +69 -0
  126. package/src/schema/nodes/footnotes_section.ts +61 -0
  127. package/src/schema/nodes/general_table_footnote.ts +42 -0
  128. package/src/schema/nodes/graphical_abstract_section.ts +62 -0
  129. package/src/schema/nodes/hard_break.ts +36 -0
  130. package/src/schema/nodes/hero_image.ts +46 -0
  131. package/src/schema/nodes/highlight_marker.ts +68 -0
  132. package/src/schema/nodes/image_element.ts +49 -0
  133. package/src/schema/nodes/inline_equation.ts +68 -0
  134. package/src/schema/nodes/inline_footnote.ts +66 -0
  135. package/src/schema/nodes/keyword.ts +61 -0
  136. package/src/schema/nodes/keyword_group.ts +63 -0
  137. package/src/schema/nodes/keywords.ts +59 -0
  138. package/src/schema/nodes/keywords_element.ts +64 -0
  139. package/src/schema/nodes/link.ts +79 -0
  140. package/src/schema/nodes/list.ts +134 -0
  141. package/src/schema/nodes/listing.ts +91 -0
  142. package/src/schema/nodes/listing_element.ts +61 -0
  143. package/src/schema/nodes/long_desc.ts +36 -0
  144. package/src/schema/nodes/manuscript.ts +86 -0
  145. package/src/schema/nodes/missing_figure.ts +59 -0
  146. package/src/schema/nodes/paragraph.ts +77 -0
  147. package/src/schema/nodes/placeholder.ts +62 -0
  148. package/src/schema/nodes/placeholder_element.ts +60 -0
  149. package/src/schema/nodes/pullquote_element.ts +81 -0
  150. package/src/schema/nodes/quote_image.ts +64 -0
  151. package/src/schema/nodes/section.ts +69 -0
  152. package/src/schema/nodes/section_label.ts +39 -0
  153. package/src/schema/nodes/section_title.ts +58 -0
  154. package/src/schema/nodes/subtitle.ts +40 -0
  155. package/src/schema/nodes/subtitles.ts +51 -0
  156. package/src/schema/nodes/supplement.ts +77 -0
  157. package/src/schema/nodes/supplements.ts +60 -0
  158. package/src/schema/nodes/table.ts +144 -0
  159. package/src/schema/nodes/table_col.ts +76 -0
  160. package/src/schema/nodes/table_element.ts +67 -0
  161. package/src/schema/nodes/table_element_footer.ts +42 -0
  162. package/src/schema/nodes/text.ts +31 -0
  163. package/src/schema/nodes/title.ts +43 -0
  164. package/src/schema/nodes/trans_abstract.ts +58 -0
  165. package/src/schema/nodes/trans_graphical_abstract.ts +67 -0
  166. package/src/schema/types.ts +240 -0
  167. package/src/tests.ts +33 -0
  168. package/src/transformer/id.ts +23 -0
  169. package/src/transformer/index.ts +21 -0
  170. package/src/transformer/node-names.ts +73 -0
  171. package/src/transformer/node-title.ts +111 -0
  172. package/src/transformer/node-types.ts +39 -0
  173. package/src/transformer/node-validator.ts +82 -0
  174. package/src/types.ts +25 -0
  175. package/src/version.ts +1 -0
@@ -0,0 +1,61 @@
1
+ /*!
2
+ * © 2024 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
+
17
+ import { GROUP_EXECUTABLE, ManuscriptNodeType, schema } from '../'
18
+ import { GROUP_BLOCK, GROUP_ELEMENT, GROUP_SECTION, hasGroup } from '../groups'
19
+
20
+ const sectionNodeTypes: ManuscriptNodeType[] = [
21
+ schema.nodes.section,
22
+ schema.nodes.bibliography_section,
23
+ ]
24
+
25
+ const elementNodeTypes: ManuscriptNodeType[] = [
26
+ schema.nodes.bibliography_element,
27
+ schema.nodes.blockquote_element,
28
+ schema.nodes.equation_element,
29
+ schema.nodes.figure_element,
30
+ schema.nodes.keywords_element,
31
+ schema.nodes.listing_element,
32
+ schema.nodes.list,
33
+ schema.nodes.paragraph,
34
+ schema.nodes.pullquote_element,
35
+ schema.nodes.table_element,
36
+ ]
37
+
38
+ const executableNodeTypes: ManuscriptNodeType[] = [
39
+ schema.nodes.figure_element,
40
+ schema.nodes.table_element,
41
+ ]
42
+
43
+ describe('groups', () => {
44
+ test('has group', () => {
45
+ for (const nodeType of sectionNodeTypes) {
46
+ expect(hasGroup(nodeType, GROUP_BLOCK)).toBe(true)
47
+ expect(hasGroup(nodeType, GROUP_ELEMENT)).toBe(false)
48
+ expect(hasGroup(nodeType, GROUP_SECTION)).toBe(true)
49
+ }
50
+
51
+ for (const nodeType of elementNodeTypes) {
52
+ expect(hasGroup(nodeType, GROUP_BLOCK)).toBe(true)
53
+ expect(hasGroup(nodeType, GROUP_ELEMENT)).toBe(true)
54
+ expect(hasGroup(nodeType, GROUP_SECTION)).toBe(false)
55
+ }
56
+
57
+ for (const nodeType of executableNodeTypes) {
58
+ expect(hasGroup(nodeType, GROUP_EXECUTABLE)).toBe(true)
59
+ }
60
+ })
61
+ })
@@ -0,0 +1,23 @@
1
+ /*!
2
+ * © 2024 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 { migrateFor } from '../migration/migrate'
17
+ import { v2_3_20 } from './docs'
18
+
19
+ describe('Prosemirror migration schema', () => {
20
+ test('Migrating doc from version 2.3.20 to the current', () => {
21
+ expect(() => migrateFor(v2_3_20, '2.3.20')).not.toThrow()
22
+ })
23
+ })
@@ -0,0 +1,36 @@
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
+
17
+ import { ManuscriptNodeType } from './types'
18
+
19
+ export const GROUP_BLOCK = 'block'
20
+ export const GROUP_ELEMENT = 'element'
21
+ export const GROUP_EXECUTABLE = 'executable'
22
+ export const GROUP_LIST = 'list'
23
+ export const GROUP_SECTION = 'sections'
24
+
25
+ export const hasGroup = (
26
+ nodeType: ManuscriptNodeType,
27
+ groupName: string
28
+ ): boolean => {
29
+ const { group } = nodeType.spec
30
+
31
+ if (!group) {
32
+ return false
33
+ }
34
+
35
+ return group.split(/\s+/).includes(groupName)
36
+ }
@@ -0,0 +1,286 @@
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
+ */
17
+
18
+ import { Schema } from 'prosemirror-model'
19
+
20
+ import {
21
+ bold,
22
+ code,
23
+ italic,
24
+ smallcaps,
25
+ strikethrough,
26
+ styled,
27
+ subscript,
28
+ superscript,
29
+ tracked_delete,
30
+ tracked_insert,
31
+ underline,
32
+ } from './marks'
33
+ import { abstracts } from './nodes/abstracts'
34
+ import { affiliation } from './nodes/affiliation'
35
+ import { affiliations } from './nodes/affiliations'
36
+ import { altText } from './nodes/alt_text'
37
+ import { altTitle } from './nodes/alt_title'
38
+ import { altTitlesSection } from './nodes/alt_titles_section'
39
+ import { attachment } from './nodes/attachment'
40
+ import { attachments } from './nodes/attachments'
41
+ import { attribution } from './nodes/attribution'
42
+ import { authorNotes } from './nodes/author_notes'
43
+ import { award } from './nodes/award'
44
+ import { awards } from './nodes/awards'
45
+ import { backmatter } from './nodes/backmatter'
46
+ import { bibliographyElement } from './nodes/bibliography_element'
47
+ import { bibliographyItem } from './nodes/bibliography_item'
48
+ import { bibliographySection } from './nodes/bibliography_section'
49
+ import { blockquoteElement } from './nodes/blockquote_element'
50
+ import { body } from './nodes/body'
51
+ import { box_element } from './nodes/box_element'
52
+ import { caption } from './nodes/caption'
53
+ import { captionTitle } from './nodes/caption_title'
54
+ import { citation } from './nodes/citation'
55
+ import { comment } from './nodes/comment'
56
+ import { comments } from './nodes/comments'
57
+ import { contributor } from './nodes/contributor'
58
+ import { contributors } from './nodes/contributors'
59
+ import { corresp } from './nodes/corresp'
60
+ import { crossReference } from './nodes/cross_reference'
61
+ import { doc } from './nodes/doc'
62
+ import { embed } from './nodes/embed'
63
+ import { equation } from './nodes/equation'
64
+ import { equationElement } from './nodes/equation_element'
65
+ import { figure } from './nodes/figure'
66
+ import { figureElement } from './nodes/figure_element'
67
+ import { footnote } from './nodes/footnote'
68
+ import { footnotesElement } from './nodes/footnotes_element'
69
+ import { footnotesSection } from './nodes/footnotes_section'
70
+ import { generalTableFootnote } from './nodes/general_table_footnote'
71
+ import { graphicalAbstractSection } from './nodes/graphical_abstract_section'
72
+ import { hardBreak } from './nodes/hard_break'
73
+ import { heroImage } from './nodes/hero_image'
74
+ import { highlightMarker } from './nodes/highlight_marker'
75
+ import { imageElement } from './nodes/image_element'
76
+ import { inlineEquation } from './nodes/inline_equation'
77
+ import { inlineFootnote } from './nodes/inline_footnote'
78
+ import { keyword } from './nodes/keyword'
79
+ import { keywordGroup } from './nodes/keyword_group'
80
+ import { keywords } from './nodes/keywords'
81
+ import { keywordsElement } from './nodes/keywords_element'
82
+ import { link } from './nodes/link'
83
+ import { list, listItem } from './nodes/list'
84
+ import { listing } from './nodes/listing'
85
+ import { listingElement } from './nodes/listing_element'
86
+ import { longDesc } from './nodes/long_desc'
87
+ import { manuscript } from './nodes/manuscript'
88
+ import { missingFigure } from './nodes/missing_figure'
89
+ import { paragraph } from './nodes/paragraph'
90
+ import { placeholder } from './nodes/placeholder'
91
+ import { placeholderElement } from './nodes/placeholder_element'
92
+ import { pullquoteElement } from './nodes/pullquote_element'
93
+ import { quoteImage } from './nodes/quote_image'
94
+ import { section } from './nodes/section'
95
+ import { sectionLabel } from './nodes/section_label'
96
+ import { sectionTitle } from './nodes/section_title'
97
+ import { subtitle } from './nodes/subtitle'
98
+ import { subtitles } from './nodes/subtitles'
99
+ import { supplement } from './nodes/supplement'
100
+ import { supplements } from './nodes/supplements'
101
+ import { table, tableCell, tableHeader, tableRow } from './nodes/table'
102
+ import { tableCol, tableColGroup } from './nodes/table_col'
103
+ import { tableElement } from './nodes/table_element'
104
+ import { tableElementFooter } from './nodes/table_element_footer'
105
+ import { text, textBlock } from './nodes/text'
106
+ import { title } from './nodes/title'
107
+ import { transAbstract } from './nodes/trans_abstract'
108
+ import { transGraphicalAbstract } from './nodes/trans_graphical_abstract'
109
+ import { Marks, Nodes } from './types'
110
+
111
+ export * from './groups'
112
+ export * from './nodes/affiliation'
113
+ export * from './nodes/affiliations'
114
+ export * from './nodes/alt_text'
115
+ export * from './nodes/alt_title'
116
+ export * from './nodes/alt_titles_section'
117
+ export * from './nodes/attachment'
118
+ export * from './nodes/attachments'
119
+ export * from './nodes/attribution'
120
+ export * from './nodes/author_notes'
121
+ export * from './nodes/award'
122
+ export * from './nodes/awards'
123
+ export * from './nodes/bibliography_element'
124
+ export * from './nodes/bibliography_item'
125
+ export * from './nodes/bibliography_section'
126
+ export * from './nodes/blockquote_element'
127
+ export * from './nodes/box_element'
128
+ export * from './nodes/caption'
129
+ export * from './nodes/caption_title'
130
+ export * from './nodes/citation'
131
+ export * from './nodes/comment'
132
+ export * from './nodes/comments'
133
+ export * from './nodes/contributor'
134
+ export * from './nodes/contributors'
135
+ export * from './nodes/corresp'
136
+ export * from './nodes/cross_reference'
137
+ export * from './nodes/doc'
138
+ export * from './nodes/embed'
139
+ export * from './nodes/equation'
140
+ export * from './nodes/equation_element'
141
+ export * from './nodes/figure'
142
+ export * from './nodes/figure_element'
143
+ export * from './nodes/footnote'
144
+ export * from './nodes/footnotes_element'
145
+ export * from './nodes/footnotes_section'
146
+ export * from './nodes/general_table_footnote'
147
+ export * from './nodes/graphical_abstract_section'
148
+ export * from './nodes/hard_break'
149
+ export * from './nodes/hero_image'
150
+ export * from './nodes/highlight_marker'
151
+ export * from './nodes/image_element'
152
+ export * from './nodes/inline_equation'
153
+ export * from './nodes/inline_footnote'
154
+ export * from './nodes/keyword'
155
+ export * from './nodes/keyword_group'
156
+ export * from './nodes/keywords'
157
+ export * from './nodes/keywords_element'
158
+ export * from './nodes/link'
159
+ export * from './nodes/list'
160
+ export * from './nodes/listing'
161
+ export * from './nodes/listing_element'
162
+ export * from './nodes/long_desc'
163
+ export * from './nodes/manuscript'
164
+ export * from './nodes/missing_figure'
165
+ export * from './nodes/paragraph'
166
+ export * from './nodes/placeholder'
167
+ export * from './nodes/placeholder_element'
168
+ export * from './nodes/pullquote_element'
169
+ export * from './nodes/quote_image'
170
+ export * from './nodes/section'
171
+ export * from './nodes/section_label'
172
+ export * from './nodes/section_title'
173
+ export * from './nodes/subtitle'
174
+ export * from './nodes/subtitles'
175
+ export * from './nodes/supplement'
176
+ export * from './nodes/supplements'
177
+ export * from './nodes/table'
178
+ export * from './nodes/table_col'
179
+ export * from './nodes/table_element'
180
+ export * from './nodes/table_element_footer'
181
+ export * from './nodes/text'
182
+ export * from './nodes/title'
183
+ export * from './nodes/trans_abstract'
184
+ export * from './nodes/trans_graphical_abstract'
185
+ export * from './types'
186
+ export const schema = new Schema<Nodes, Marks>({
187
+ marks: {
188
+ bold,
189
+ code,
190
+ italic,
191
+ smallcaps,
192
+ strikethrough,
193
+ styled,
194
+ subscript,
195
+ superscript,
196
+ underline,
197
+ tracked_insert,
198
+ tracked_delete,
199
+ },
200
+ nodes: {
201
+ comment,
202
+ comments,
203
+ attribution,
204
+ bibliography_item: bibliographyItem,
205
+ bibliography_element: bibliographyElement,
206
+ bibliography_section: bibliographySection,
207
+ blockquote_element: blockquoteElement,
208
+ list: list,
209
+ caption,
210
+ caption_title: captionTitle,
211
+ citation,
212
+ abstracts,
213
+ body,
214
+ backmatter,
215
+ cross_reference: crossReference,
216
+ doc,
217
+ equation,
218
+ equation_element: equationElement,
219
+ figure,
220
+ figure_element: figureElement,
221
+ footnote,
222
+ footnotes_element: footnotesElement,
223
+ footnotes_section: footnotesSection,
224
+ general_table_footnote: generalTableFootnote,
225
+ graphical_abstract_section: graphicalAbstractSection,
226
+ hard_break: hardBreak,
227
+ highlight_marker: highlightMarker,
228
+ inline_equation: inlineEquation,
229
+ inline_footnote: inlineFootnote,
230
+ keyword,
231
+ keywords_element: keywordsElement,
232
+ keywords: keywords,
233
+ keyword_group: keywordGroup,
234
+ link,
235
+ list_item: listItem,
236
+ listing,
237
+ listing_element: listingElement,
238
+ manuscript,
239
+ missing_figure: missingFigure,
240
+ paragraph,
241
+ placeholder,
242
+ placeholder_element: placeholderElement,
243
+ pullquote_element: pullquoteElement,
244
+ section,
245
+ section_label: sectionLabel,
246
+ section_title: sectionTitle,
247
+ section_title_plain: sectionTitle, // used for non-editable titles
248
+ table,
249
+ table_cell: tableCell,
250
+ table_element: tableElement,
251
+ table_row: tableRow,
252
+ table_col: tableCol,
253
+ table_colgroup: tableColGroup,
254
+ table_header: tableHeader,
255
+ text,
256
+ text_block: textBlock,
257
+ affiliation,
258
+ contributor: contributor,
259
+ table_element_footer: tableElementFooter,
260
+ title,
261
+ affiliations,
262
+ contributors,
263
+ supplements,
264
+ supplement,
265
+ author_notes: authorNotes,
266
+ corresp,
267
+ box_element,
268
+ awards,
269
+ award,
270
+ embed,
271
+ image_element: imageElement,
272
+ attachment,
273
+ attachments,
274
+ alt_title: altTitle,
275
+ alt_titles: altTitlesSection,
276
+ alt_text: altText,
277
+ long_desc: longDesc,
278
+ quote_image: quoteImage,
279
+ hero_image: heroImage,
280
+ trans_abstract: transAbstract,
281
+ trans_graphical_abstract: transGraphicalAbstract,
282
+ subtitle: subtitle,
283
+ subtitles: subtitles,
284
+ },
285
+ })
286
+ /**/
@@ -0,0 +1,254 @@
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
+
17
+ import { Mark, MarkSpec } from 'prosemirror-model'
18
+
19
+ import { DataTrackedAttrs } from './types'
20
+
21
+ function getTrackedMarkAttrs(el: Mark) {
22
+ const dataTracked: Partial<DataTrackedAttrs> = Array.isArray(
23
+ el.attrs.dataTracked
24
+ )
25
+ ? el.attrs.dataTracked[0]
26
+ : null
27
+ return dataTracked
28
+ ? {
29
+ 'data-track-status': dataTracked.status,
30
+ 'data-track-op': dataTracked.operation,
31
+ }
32
+ : {}
33
+ }
34
+
35
+ export const bold: MarkSpec = {
36
+ attrs: {
37
+ dataTracked: { default: null },
38
+ },
39
+ parseDOM: [
40
+ {
41
+ // Google Docs can produce content wrapped in <b style="fontWeight:normal">, which isn't actually bold. This workaround is copied from prosemirror-schema-basic.
42
+ getAttrs: (dom) =>
43
+ (dom as HTMLElement).style.fontWeight !== 'normal' && null,
44
+ tag: 'b',
45
+ },
46
+ { tag: 'strong' },
47
+ {
48
+ // this is to support article-title parsing which is done by creating htmlNode first and putting it through the parser
49
+ tag: 'bold',
50
+ },
51
+ {
52
+ // This regex, copied from prosemirror-schema-basic, matches all the possible "font-weight" values that can mean "bold".
53
+ getAttrs: (value) =>
54
+ /^(bold(er)?|[5-9]\d{2,})$/.test(value as string) && null,
55
+ style: 'font-weight',
56
+ },
57
+ ],
58
+ toDOM: (el) => {
59
+ const attrs = {
60
+ ...getTrackedMarkAttrs(el),
61
+ }
62
+ return ['b', attrs]
63
+ },
64
+ }
65
+
66
+ export const code: MarkSpec = {
67
+ parseDOM: [{ tag: 'code' }],
68
+ toDOM: () => ['code'],
69
+ }
70
+
71
+ export const italic: MarkSpec = {
72
+ attrs: {
73
+ dataTracked: { default: null },
74
+ },
75
+ parseDOM: [{ tag: 'i' }, { tag: 'em' }, { style: 'font-style=italic' }],
76
+ toDOM: (el) => {
77
+ const attrs = {
78
+ ...getTrackedMarkAttrs(el),
79
+ }
80
+ return ['i', attrs]
81
+ },
82
+ }
83
+
84
+ export const smallcaps: MarkSpec = {
85
+ parseDOM: [
86
+ { style: 'font-variant=small-caps' },
87
+ { style: 'font-variant-caps=small-caps' }, // TODO: all the other font-variant-caps options?
88
+ ],
89
+ toDOM: () => [
90
+ 'span',
91
+ {
92
+ style: 'font-variant:small-caps',
93
+ },
94
+ ],
95
+ }
96
+
97
+ export const strikethrough: MarkSpec = {
98
+ attrs: {
99
+ dataTracked: { default: null },
100
+ },
101
+ parseDOM: [
102
+ { tag: 's' },
103
+ { tag: 'strike' },
104
+ { style: 'text-decoration=line-through' },
105
+ { style: 'text-decoration-line=line-through' },
106
+ ],
107
+ toDOM: (el) => {
108
+ const attrs = {
109
+ ...getTrackedMarkAttrs(el),
110
+ }
111
+ return ['s', attrs]
112
+ },
113
+ }
114
+
115
+ export const styled: MarkSpec = {
116
+ attrs: {
117
+ rid: { default: '' },
118
+ },
119
+ spanning: false,
120
+ parseDOM: [
121
+ {
122
+ tag: 'span.styled-content',
123
+ getAttrs: (dom) => {
124
+ const element = dom as HTMLSpanElement
125
+ return {
126
+ rid: element.getAttribute('data-inline-style'),
127
+ }
128
+ },
129
+ },
130
+ ],
131
+ toDOM: (mark) => {
132
+ return [
133
+ 'span',
134
+ { class: 'styled-content', 'data-inline-style': mark.attrs.rid },
135
+ ]
136
+ },
137
+ }
138
+
139
+ export const subscript: MarkSpec = {
140
+ attrs: {
141
+ dataTracked: { default: null },
142
+ },
143
+ excludes: 'superscript',
144
+ group: 'position',
145
+ parseDOM: [{ tag: 'sub' }, { style: 'vertical-align=sub' }],
146
+ toDOM: (el) => {
147
+ const attrs = {
148
+ ...getTrackedMarkAttrs(el),
149
+ }
150
+ return ['sub', attrs]
151
+ },
152
+ }
153
+
154
+ export const superscript: MarkSpec = {
155
+ attrs: {
156
+ dataTracked: { default: null },
157
+ },
158
+ excludes: 'subscript',
159
+ group: 'position',
160
+ parseDOM: [{ tag: 'sup' }, { style: 'vertical-align=super' }],
161
+ toDOM: (el) => {
162
+ const attrs = {
163
+ ...getTrackedMarkAttrs(el),
164
+ }
165
+ return ['sup', attrs]
166
+ },
167
+ }
168
+
169
+ export const underline: MarkSpec = {
170
+ attrs: {
171
+ dataTracked: { default: null },
172
+ },
173
+ parseDOM: [{ tag: 'u' }, { style: 'text-decoration=underline' }],
174
+ toDOM: (el) => {
175
+ const attrs = {
176
+ ...getTrackedMarkAttrs(el),
177
+ }
178
+ return ['u', attrs]
179
+ },
180
+ }
181
+
182
+ export const tracked_insert: MarkSpec = {
183
+ excludes: 'tracked_insert tracked_delete',
184
+ attrs: {
185
+ dataTracked: { default: null },
186
+ },
187
+ parseDOM: [
188
+ {
189
+ tag: 'ins',
190
+ getAttrs: (ins) => {
191
+ const dom = ins as HTMLElement
192
+ return {
193
+ dataTracked: {
194
+ id: dom.getAttribute('data-track-id'),
195
+ userID: dom.getAttribute('data-user-id'),
196
+ status: dom.getAttribute('data-track-status'),
197
+ createdAt: parseInt(
198
+ dom.getAttribute('data-track-created-at') || ''
199
+ ),
200
+ },
201
+ }
202
+ },
203
+ },
204
+ ],
205
+ toDOM: (el) => {
206
+ const dataTracked: Partial<DataTrackedAttrs> = el.attrs.dataTracked || {}
207
+ const { status = 'pending', id, userID, createdAt } = dataTracked
208
+ const attrs = {
209
+ class: `inserted ${status}`,
210
+ 'data-track-status': status,
211
+ ...(id && { 'data-track-id': id }),
212
+ ...(userID && { 'data-user-id': userID }),
213
+ ...(createdAt && { 'data-track-created-at': createdAt.toString() }),
214
+ }
215
+ return ['ins', attrs]
216
+ },
217
+ }
218
+
219
+ export const tracked_delete: MarkSpec = {
220
+ excludes: 'tracked_insert tracked_delete',
221
+ attrs: {
222
+ dataTracked: { default: null },
223
+ },
224
+ parseDOM: [
225
+ {
226
+ tag: 'del',
227
+ getAttrs: (del) => {
228
+ const dom = del as HTMLElement
229
+ return {
230
+ dataTracked: {
231
+ id: dom.getAttribute('data-track-id'),
232
+ userID: dom.getAttribute('data-user-id'),
233
+ status: dom.getAttribute('data-track-status'),
234
+ createdAt: parseInt(
235
+ dom.getAttribute('data-track-created-at') || ''
236
+ ),
237
+ },
238
+ }
239
+ },
240
+ },
241
+ ],
242
+ toDOM: (el) => {
243
+ const dataTracked: Partial<DataTrackedAttrs> = el.attrs.dataTracked || {}
244
+ const { status = 'pending', id, userID, createdAt } = dataTracked
245
+ const attrs = {
246
+ class: `deleted ${status}`,
247
+ 'data-track-status': status,
248
+ ...(id && { 'data-track-id': id }),
249
+ ...(userID && { 'data-user-id': userID }),
250
+ ...(createdAt && { 'data-track-created-at': createdAt.toString() }),
251
+ }
252
+ return ['del', attrs]
253
+ },
254
+ }