docrev 0.11.2 → 0.12.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 (205) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/LICENSE +21 -0
  3. package/dist/bin/rev.js +29 -21
  4. package/dist/bin/rev.js.map +1 -1
  5. package/dist/lib/annotations.d.ts.map +1 -1
  6. package/dist/lib/annotations.js +28 -0
  7. package/dist/lib/annotations.js.map +1 -1
  8. package/dist/lib/build.d.ts +43 -0
  9. package/dist/lib/build.d.ts.map +1 -1
  10. package/dist/lib/build.js +175 -5
  11. package/dist/lib/build.js.map +1 -1
  12. package/dist/lib/commands/build.d.ts.map +1 -1
  13. package/dist/lib/commands/build.js +39 -125
  14. package/dist/lib/commands/build.js.map +1 -1
  15. package/dist/lib/commands/comments.d.ts.map +1 -1
  16. package/dist/lib/commands/comments.js +61 -31
  17. package/dist/lib/commands/comments.js.map +1 -1
  18. package/dist/lib/commands/context.d.ts +12 -0
  19. package/dist/lib/commands/context.d.ts.map +1 -1
  20. package/dist/lib/commands/context.js +34 -0
  21. package/dist/lib/commands/context.js.map +1 -1
  22. package/dist/lib/commands/core.d.ts.map +1 -1
  23. package/dist/lib/commands/core.js +25 -8
  24. package/dist/lib/commands/core.js.map +1 -1
  25. package/dist/lib/commands/merge-resolve.js +1 -1
  26. package/dist/lib/commands/merge-resolve.js.map +1 -1
  27. package/dist/lib/commands/quality.js +2 -2
  28. package/dist/lib/commands/quality.js.map +1 -1
  29. package/dist/lib/commands/response.js +1 -1
  30. package/dist/lib/commands/response.js.map +1 -1
  31. package/dist/lib/commands/sections.js +1 -1
  32. package/dist/lib/commands/sections.js.map +1 -1
  33. package/dist/lib/commands/text-ops.js +1 -1
  34. package/dist/lib/commands/text-ops.js.map +1 -1
  35. package/dist/lib/commands/utilities.d.ts.map +1 -1
  36. package/dist/lib/commands/utilities.js +5 -2
  37. package/dist/lib/commands/utilities.js.map +1 -1
  38. package/dist/lib/commands/word-tools.js +2 -2
  39. package/dist/lib/commands/word-tools.js.map +1 -1
  40. package/dist/lib/crossref.d.ts.map +1 -1
  41. package/dist/lib/crossref.js +12 -41
  42. package/dist/lib/crossref.js.map +1 -1
  43. package/dist/lib/csl.d.ts.map +1 -1
  44. package/dist/lib/csl.js +14 -22
  45. package/dist/lib/csl.js.map +1 -1
  46. package/dist/lib/diff-engine.js +1 -1
  47. package/dist/lib/diff-engine.js.map +1 -1
  48. package/dist/lib/equations.d.ts.map +1 -1
  49. package/dist/lib/equations.js +12 -3
  50. package/dist/lib/equations.js.map +1 -1
  51. package/dist/lib/errors.d.ts.map +1 -1
  52. package/dist/lib/errors.js +1 -30
  53. package/dist/lib/errors.js.map +1 -1
  54. package/dist/lib/image-registry.d.ts.map +1 -1
  55. package/dist/lib/image-registry.js +4 -0
  56. package/dist/lib/image-registry.js.map +1 -1
  57. package/dist/lib/import.d.ts +15 -1
  58. package/dist/lib/import.d.ts.map +1 -1
  59. package/dist/lib/import.js +24 -1
  60. package/dist/lib/import.js.map +1 -1
  61. package/dist/lib/input.d.ts +56 -0
  62. package/dist/lib/input.d.ts.map +1 -0
  63. package/dist/lib/input.js +129 -0
  64. package/dist/lib/input.js.map +1 -0
  65. package/dist/lib/merge.d.ts.map +1 -1
  66. package/dist/lib/merge.js +9 -1
  67. package/dist/lib/merge.js.map +1 -1
  68. package/dist/lib/ooxml.d.ts +22 -0
  69. package/dist/lib/ooxml.d.ts.map +1 -1
  70. package/dist/lib/ooxml.js +130 -0
  71. package/dist/lib/ooxml.js.map +1 -1
  72. package/dist/lib/orcid.d.ts.map +1 -1
  73. package/dist/lib/orcid.js +16 -7
  74. package/dist/lib/orcid.js.map +1 -1
  75. package/dist/lib/plugins.d.ts.map +1 -1
  76. package/dist/lib/plugins.js +8 -4
  77. package/dist/lib/plugins.js.map +1 -1
  78. package/dist/lib/protect-restore.d.ts.map +1 -1
  79. package/dist/lib/protect-restore.js +7 -5
  80. package/dist/lib/protect-restore.js.map +1 -1
  81. package/dist/lib/response.d.ts +1 -1
  82. package/dist/lib/response.d.ts.map +1 -1
  83. package/dist/lib/response.js +5 -2
  84. package/dist/lib/response.js.map +1 -1
  85. package/dist/lib/restore-references.d.ts.map +1 -1
  86. package/dist/lib/restore-references.js +25 -3
  87. package/dist/lib/restore-references.js.map +1 -1
  88. package/dist/lib/schema.d.ts.map +1 -1
  89. package/dist/lib/schema.js +1 -19
  90. package/dist/lib/schema.js.map +1 -1
  91. package/dist/lib/slides.js +1 -1
  92. package/dist/lib/slides.js.map +1 -1
  93. package/dist/lib/spelling.js +1 -1
  94. package/dist/lib/spelling.js.map +1 -1
  95. package/dist/lib/tui.js +0 -1
  96. package/dist/lib/tui.js.map +1 -1
  97. package/dist/lib/utils.d.ts +14 -0
  98. package/dist/lib/utils.d.ts.map +1 -1
  99. package/dist/lib/utils.js +41 -0
  100. package/dist/lib/utils.js.map +1 -1
  101. package/dist/lib/word-extraction.d.ts +5 -5
  102. package/dist/lib/word-extraction.d.ts.map +1 -1
  103. package/dist/lib/word-extraction.js +25 -106
  104. package/dist/lib/word-extraction.js.map +1 -1
  105. package/dist/lib/word.d.ts +14 -38
  106. package/dist/lib/word.d.ts.map +1 -1
  107. package/dist/lib/word.js +24 -179
  108. package/dist/lib/word.js.map +1 -1
  109. package/dist/lib/wordcomments.d.ts.map +1 -1
  110. package/dist/lib/wordcomments.js +9 -7
  111. package/dist/lib/wordcomments.js.map +1 -1
  112. package/package.json +17 -6
  113. package/.gitattributes +0 -1
  114. package/PLAN-tables-and-postprocess.md +0 -850
  115. package/bin/rev.ts +0 -145
  116. package/docs-src/build.py +0 -113
  117. package/docs-src/extra.css +0 -208
  118. package/docs-src/md-to-html.lua +0 -6
  119. package/docs-src/template.html +0 -116
  120. package/eslint.config.js +0 -27
  121. package/lib/anchor-match.ts +0 -307
  122. package/lib/annotations.ts +0 -664
  123. package/lib/build.ts +0 -2047
  124. package/lib/citations.ts +0 -160
  125. package/lib/commands/build.ts +0 -885
  126. package/lib/commands/citations.ts +0 -515
  127. package/lib/commands/comments.ts +0 -1050
  128. package/lib/commands/context.ts +0 -176
  129. package/lib/commands/core.ts +0 -309
  130. package/lib/commands/doi.ts +0 -451
  131. package/lib/commands/file-ops.ts +0 -372
  132. package/lib/commands/history.ts +0 -320
  133. package/lib/commands/index.ts +0 -87
  134. package/lib/commands/init.ts +0 -259
  135. package/lib/commands/merge-resolve.ts +0 -378
  136. package/lib/commands/preview.ts +0 -178
  137. package/lib/commands/project-info.ts +0 -244
  138. package/lib/commands/quality.ts +0 -517
  139. package/lib/commands/response.ts +0 -454
  140. package/lib/commands/section-boundaries.ts +0 -82
  141. package/lib/commands/sections.ts +0 -451
  142. package/lib/commands/sync.ts +0 -689
  143. package/lib/commands/text-ops.ts +0 -449
  144. package/lib/commands/utilities.ts +0 -448
  145. package/lib/commands/verify-anchors.ts +0 -272
  146. package/lib/commands/word-tools.ts +0 -340
  147. package/lib/comment-realign.ts +0 -99
  148. package/lib/config.ts +0 -84
  149. package/lib/crossref.ts +0 -781
  150. package/lib/csl.ts +0 -191
  151. package/lib/dependencies.ts +0 -132
  152. package/lib/diff-engine.ts +0 -465
  153. package/lib/doi-cache.ts +0 -115
  154. package/lib/doi.ts +0 -879
  155. package/lib/equations.ts +0 -506
  156. package/lib/errors.ts +0 -350
  157. package/lib/format.ts +0 -541
  158. package/lib/git.ts +0 -326
  159. package/lib/grammar.ts +0 -303
  160. package/lib/image-registry.ts +0 -180
  161. package/lib/import.ts +0 -906
  162. package/lib/journals.ts +0 -543
  163. package/lib/macro-filter.lua +0 -201
  164. package/lib/macros.ts +0 -273
  165. package/lib/merge.ts +0 -633
  166. package/lib/ooxml.ts +0 -768
  167. package/lib/orcid.ts +0 -144
  168. package/lib/pdf-comments.ts +0 -263
  169. package/lib/pdf-import.ts +0 -524
  170. package/lib/plugins.ts +0 -362
  171. package/lib/postprocess.ts +0 -188
  172. package/lib/pptx-color-filter.lua +0 -37
  173. package/lib/pptx-template.ts +0 -469
  174. package/lib/pptx-themes/academic.pptx +0 -0
  175. package/lib/pptx-themes/corporate.pptx +0 -0
  176. package/lib/pptx-themes/dark.pptx +0 -0
  177. package/lib/pptx-themes/default.pptx +0 -0
  178. package/lib/pptx-themes/minimal.pptx +0 -0
  179. package/lib/pptx-themes/plant.pptx +0 -0
  180. package/lib/pptx-themes.ts +0 -483
  181. package/lib/protect-restore.ts +0 -520
  182. package/lib/rate-limiter.ts +0 -127
  183. package/lib/response.ts +0 -197
  184. package/lib/restore-references.ts +0 -240
  185. package/lib/review.ts +0 -327
  186. package/lib/schema.ts +0 -494
  187. package/lib/scientific-words.ts +0 -73
  188. package/lib/sections.ts +0 -428
  189. package/lib/slides.ts +0 -756
  190. package/lib/spelling.ts +0 -334
  191. package/lib/templates.ts +0 -526
  192. package/lib/themes.ts +0 -742
  193. package/lib/trackchanges.ts +0 -166
  194. package/lib/tui.ts +0 -450
  195. package/lib/types.ts +0 -546
  196. package/lib/undo.ts +0 -250
  197. package/lib/utils.ts +0 -69
  198. package/lib/variables.ts +0 -179
  199. package/lib/word-extraction.ts +0 -525
  200. package/lib/word.ts +0 -526
  201. package/lib/wordcomments.ts +0 -789
  202. package/mkdocs.yml +0 -64
  203. package/scripts/postbuild.js +0 -47
  204. package/tsconfig.json +0 -26
  205. package/types/index.d.ts +0 -531
package/lib/journals.ts DELETED
@@ -1,543 +0,0 @@
1
- /**
2
- * Journal validation profiles
3
- * Check manuscripts against journal-specific requirements
4
- */
5
-
6
- import * as fs from 'fs';
7
- import * as path from 'path';
8
- import type { JournalProfile, JournalRequirements, JournalFormatting, ValidationResult } from './types.js';
9
- import { loadCustomProfiles } from './plugins.js';
10
- import { countWords } from './utils.js';
11
-
12
- /**
13
- * Journal requirement profiles
14
- * Based on publicly available author guidelines
15
- */
16
- export const JOURNAL_PROFILES: Record<string, JournalProfile> = {
17
- nature: {
18
- name: 'Nature',
19
- url: 'https://www.nature.com/nature/for-authors',
20
- requirements: {
21
- wordLimit: { main: 3000, abstract: 150 },
22
- references: { max: 50, doiRequired: true },
23
- figures: { max: 6 },
24
- sections: ['Abstract', 'Introduction', 'Results', 'Discussion', 'Methods'],
25
- },
26
- formatting: {
27
- csl: 'nature',
28
- pdf: { fontsize: '11pt', geometry: 'margin=2.5cm', linestretch: 2 },
29
- },
30
- },
31
-
32
- science: {
33
- name: 'Science',
34
- url: 'https://www.science.org/content/page/instructions-preparing-initial-manuscript',
35
- requirements: {
36
- wordLimit: { main: 2500, abstract: 125 },
37
- references: { max: 40, doiRequired: true },
38
- figures: { max: 4 },
39
- sections: ['Abstract', 'Introduction', 'Results', 'Discussion'],
40
- },
41
- formatting: {
42
- csl: 'science',
43
- pdf: { fontsize: '12pt', geometry: 'margin=1in', linestretch: 2 },
44
- },
45
- },
46
-
47
- 'plos-one': {
48
- name: 'PLOS ONE',
49
- url: 'https://journals.plos.org/plosone/s/submission-guidelines',
50
- requirements: {
51
- wordLimit: { abstract: 300 },
52
- references: { doiRequired: false },
53
- sections: ['Abstract', 'Introduction', 'Methods', 'Results', 'Discussion'],
54
- },
55
- formatting: {
56
- csl: 'plos',
57
- pdf: { fontsize: '12pt', geometry: 'margin=1in', linestretch: 2 },
58
- },
59
- },
60
-
61
- 'pnas': {
62
- name: 'PNAS',
63
- url: 'https://www.pnas.org/author-center/submitting-your-manuscript',
64
- requirements: {
65
- wordLimit: { main: 4500, abstract: 250 },
66
- references: { max: 50, doiRequired: true },
67
- figures: { max: 6 },
68
- sections: ['Abstract', 'Introduction', 'Results', 'Discussion'],
69
- },
70
- formatting: {
71
- csl: 'pnas',
72
- pdf: { documentclass: 'article', fontsize: '9pt', geometry: 'margin=2cm', linestretch: 1.2, numbersections: false },
73
- },
74
- },
75
-
76
- 'ecology-letters': {
77
- name: 'Ecology Letters',
78
- url: 'https://onlinelibrary.wiley.com/page/journal/14610248/homepage/forauthors.html',
79
- requirements: {
80
- wordLimit: { main: 5000, abstract: 150 },
81
- references: { max: 50, doiRequired: true },
82
- figures: { max: 6 },
83
- sections: ['Abstract', 'Introduction', 'Methods', 'Results', 'Discussion'],
84
- },
85
- },
86
-
87
- 'ecological-applications': {
88
- name: 'Ecological Applications',
89
- url: 'https://esajournals.onlinelibrary.wiley.com/hub/journal/19395582/author-guidelines',
90
- requirements: {
91
- wordLimit: { main: 7000, abstract: 350 },
92
- references: { doiRequired: true },
93
- sections: ['Abstract', 'Introduction', 'Methods', 'Results', 'Discussion'],
94
- },
95
- },
96
-
97
- 'molecular-ecology': {
98
- name: 'Molecular Ecology',
99
- url: 'https://onlinelibrary.wiley.com/page/journal/1365294x/homepage/forauthors.html',
100
- requirements: {
101
- wordLimit: { main: 8000, abstract: 250 },
102
- references: { doiRequired: true },
103
- figures: { max: 8 },
104
- sections: ['Abstract', 'Introduction', 'Methods', 'Results', 'Discussion'],
105
- },
106
- },
107
-
108
- 'elife': {
109
- name: 'eLife',
110
- url: 'https://reviewer.elifesciences.org/author-guide/full',
111
- requirements: {
112
- wordLimit: { abstract: 150 },
113
- references: { doiRequired: true },
114
- sections: ['Abstract', 'Introduction', 'Results', 'Discussion', 'Methods'],
115
- },
116
- formatting: {
117
- csl: 'elife',
118
- pdf: { fontsize: '11pt', geometry: 'margin=2.5cm', linestretch: 1.5 },
119
- },
120
- },
121
-
122
- 'cell': {
123
- name: 'Cell',
124
- url: 'https://www.cell.com/cell/authors',
125
- requirements: {
126
- wordLimit: { main: 7000, abstract: 150 },
127
- references: { max: 100, doiRequired: true },
128
- figures: { max: 7 },
129
- sections: ['Abstract', 'Introduction', 'Results', 'Discussion'],
130
- },
131
- formatting: {
132
- csl: 'cell',
133
- pdf: { fontsize: '12pt', geometry: 'margin=2.5cm', linestretch: 2 },
134
- },
135
- },
136
-
137
- 'current-biology': {
138
- name: 'Current Biology',
139
- url: 'https://www.cell.com/current-biology/authors',
140
- requirements: {
141
- wordLimit: { main: 5000, abstract: 150 },
142
- references: { max: 60, doiRequired: true },
143
- figures: { max: 4 },
144
- sections: ['Summary', 'Results', 'Discussion'],
145
- },
146
- },
147
-
148
- 'conservation-biology': {
149
- name: 'Conservation Biology',
150
- url: 'https://conbio.onlinelibrary.wiley.com/hub/journal/15231739/homepage/forauthors.html',
151
- requirements: {
152
- wordLimit: { main: 7000, abstract: 300 },
153
- references: { doiRequired: true },
154
- figures: { max: 6 },
155
- sections: ['Abstract', 'Introduction', 'Methods', 'Results', 'Discussion'],
156
- },
157
- },
158
-
159
- 'biological-conservation': {
160
- name: 'Biological Conservation',
161
- url: 'https://www.elsevier.com/journals/biological-conservation/0006-3207/guide-for-authors',
162
- requirements: {
163
- wordLimit: { main: 8000, abstract: 400 },
164
- references: { doiRequired: true },
165
- sections: ['Abstract', 'Introduction', 'Methods', 'Results', 'Discussion'],
166
- },
167
- },
168
-
169
- 'journal-of-ecology': {
170
- name: 'Journal of Ecology',
171
- url: 'https://besjournals.onlinelibrary.wiley.com/hub/journal/13652745/author-guidelines',
172
- requirements: {
173
- wordLimit: { main: 7000, abstract: 350 },
174
- references: { doiRequired: true },
175
- sections: ['Abstract', 'Introduction', 'Methods', 'Results', 'Discussion'],
176
- },
177
- },
178
-
179
- 'functional-ecology': {
180
- name: 'Functional Ecology',
181
- url: 'https://besjournals.onlinelibrary.wiley.com/hub/journal/13652435/author-guidelines',
182
- requirements: {
183
- wordLimit: { main: 7000, abstract: 350 },
184
- references: { doiRequired: true },
185
- sections: ['Abstract', 'Introduction', 'Methods', 'Results', 'Discussion'],
186
- },
187
- },
188
-
189
- 'global-change-biology': {
190
- name: 'Global Change Biology',
191
- url: 'https://onlinelibrary.wiley.com/page/journal/13652486/homepage/forauthors.html',
192
- requirements: {
193
- wordLimit: { main: 7000, abstract: 300 },
194
- references: { doiRequired: true },
195
- figures: { max: 8 },
196
- sections: ['Abstract', 'Introduction', 'Methods', 'Results', 'Discussion'],
197
- },
198
- },
199
-
200
- 'oikos': {
201
- name: 'Oikos',
202
- url: 'https://nsojournals.onlinelibrary.wiley.com/hub/journal/16000706/author-guidelines',
203
- requirements: {
204
- wordLimit: { main: 8000, abstract: 350 },
205
- references: { doiRequired: true },
206
- sections: ['Abstract', 'Introduction', 'Methods', 'Results', 'Discussion'],
207
- },
208
- },
209
-
210
- 'oecologia': {
211
- name: 'Oecologia',
212
- url: 'https://www.springer.com/journal/442/submission-guidelines',
213
- requirements: {
214
- wordLimit: { main: 8000, abstract: 250 },
215
- references: { doiRequired: true },
216
- sections: ['Abstract', 'Introduction', 'Methods', 'Results', 'Discussion'],
217
- },
218
- },
219
-
220
- 'biological-invasions': {
221
- name: 'Biological Invasions',
222
- url: 'https://www.springer.com/journal/10530/submission-guidelines',
223
- requirements: {
224
- wordLimit: { abstract: 250 },
225
- references: { doiRequired: true },
226
- sections: ['Abstract', 'Introduction', 'Methods', 'Results', 'Discussion'],
227
- },
228
- },
229
-
230
- 'diversity-distributions': {
231
- name: 'Diversity and Distributions',
232
- url: 'https://onlinelibrary.wiley.com/page/journal/14724642/homepage/forauthors.html',
233
- requirements: {
234
- wordLimit: { main: 6000, abstract: 300 },
235
- references: { doiRequired: true },
236
- figures: { max: 6 },
237
- sections: ['Abstract', 'Introduction', 'Methods', 'Results', 'Discussion'],
238
- },
239
- },
240
-
241
- 'neobiota': {
242
- name: 'NeoBiota',
243
- url: 'https://neobiota.pensoft.net/about#Author_Guidelines',
244
- requirements: {
245
- wordLimit: { abstract: 350 },
246
- references: { doiRequired: true },
247
- sections: ['Abstract', 'Introduction', 'Methods', 'Results', 'Discussion'],
248
- },
249
- },
250
-
251
- 'peerj': {
252
- name: 'PeerJ',
253
- url: 'https://peerj.com/about/author-instructions/',
254
- requirements: {
255
- wordLimit: { abstract: 500 },
256
- references: { doiRequired: false },
257
- sections: ['Abstract', 'Introduction', 'Methods', 'Results', 'Discussion'],
258
- },
259
- },
260
-
261
- 'methods-ecology-evolution': {
262
- name: 'Methods in Ecology and Evolution',
263
- url: 'https://besjournals.onlinelibrary.wiley.com/hub/journal/2041210x/author-guidelines',
264
- requirements: {
265
- wordLimit: { main: 7000, abstract: 350 },
266
- references: { doiRequired: true },
267
- sections: ['Abstract', 'Introduction', 'Methods', 'Results', 'Discussion'],
268
- },
269
- formatting: {
270
- csl: 'methods-in-ecology-and-evolution',
271
- pdf: { fontsize: '12pt', geometry: 'margin=2.5cm', linestretch: 2 },
272
- },
273
- },
274
- };
275
-
276
- /**
277
- * Get all profiles (built-in + custom)
278
- * Custom profiles override built-in ones with the same ID
279
- */
280
- function getAllProfiles(): Record<string, JournalProfile> {
281
- const customProfiles = loadCustomProfiles() as Record<string, JournalProfile>;
282
- return { ...JOURNAL_PROFILES, ...customProfiles };
283
- }
284
-
285
- interface ListJournalsOptions {
286
- includeCustom?: boolean;
287
- customOnly?: boolean;
288
- }
289
-
290
- interface JournalListItem {
291
- id: string;
292
- name: string;
293
- url: string;
294
- custom?: boolean;
295
- }
296
-
297
- /**
298
- * List all available journal profiles
299
- */
300
- export function listJournals(options: ListJournalsOptions = {}): JournalListItem[] {
301
- const { includeCustom = true, customOnly = false } = options;
302
-
303
- const profiles = customOnly
304
- ? (loadCustomProfiles() as Record<string, JournalProfile>)
305
- : includeCustom
306
- ? getAllProfiles()
307
- : JOURNAL_PROFILES;
308
-
309
- return Object.entries(profiles).map(([id, profile]) => ({
310
- id,
311
- name: profile.name,
312
- url: profile.url,
313
- custom: (profile as any).custom || false,
314
- }));
315
- }
316
-
317
- /**
318
- * Get a specific journal profile
319
- */
320
- export function getJournalProfile(journalId: string): JournalProfile | null {
321
- const normalized = journalId.toLowerCase().replace(/\s+/g, '-');
322
- const profiles = getAllProfiles();
323
- return profiles[normalized] || null;
324
- }
325
-
326
-
327
- /**
328
- * Extract abstract from markdown
329
- */
330
- function extractAbstract(text: string): string | null {
331
- // Try to find abstract section
332
- const patterns = [
333
- /^#+\s*Abstract\s*\n([\s\S]*?)(?=^#+|\Z)/mi,
334
- /^Abstract[:\s]*\n([\s\S]*?)(?=^#+|\n\n)/mi,
335
- ];
336
-
337
- for (const pattern of patterns) {
338
- const match = text.match(pattern);
339
- if (match && match[1]) {
340
- return match[1].trim();
341
- }
342
- }
343
-
344
- return null;
345
- }
346
-
347
- /**
348
- * Extract title from markdown
349
- */
350
- function extractTitle(text: string): string | null {
351
- // Try YAML frontmatter
352
- const yamlMatch = text.match(/^---\n[\s\S]*?title:\s*["']?([^"'\n]+)["']?[\s\S]*?\n---/m);
353
- if (yamlMatch && yamlMatch[1]) {
354
- return yamlMatch[1].trim();
355
- }
356
-
357
- // Try first H1
358
- const h1Match = text.match(/^#\s+(.+)$/m);
359
- if (h1Match && h1Match[1]) {
360
- return h1Match[1].trim();
361
- }
362
-
363
- return null;
364
- }
365
-
366
- /**
367
- * Extract sections from markdown
368
- */
369
- function extractSections(text: string): string[] {
370
- const sections: string[] = [];
371
- const headerPattern = /^#+\s+(.+)$/gm;
372
- let match: RegExpExecArray | null;
373
-
374
- while ((match = headerPattern.exec(text)) !== null) {
375
- if (match[1]) {
376
- sections.push(match[1].trim());
377
- }
378
- }
379
-
380
- return sections;
381
- }
382
-
383
- /**
384
- * Count figures in markdown
385
- */
386
- function countFigures(text: string): number {
387
- // Count images with figure captions
388
- const figurePattern = /!\[.*?\]\(.*?\)(\{#fig:[^}]+\})?/g;
389
- const matches = text.match(figurePattern) || [];
390
- return matches.length;
391
- }
392
-
393
- /**
394
- * Count tables in markdown
395
- */
396
- function countTables(text: string): number {
397
- // Count tables (lines starting with |)
398
- const tablePattern = /^\|[^|]+\|/gm;
399
- const matches = text.match(tablePattern) || [];
400
- // Divide by approximate rows per table
401
- return Math.ceil(matches.length / 5);
402
- }
403
-
404
- /**
405
- * Count references/citations in markdown
406
- */
407
- function countReferences(text: string): number {
408
- // Count unique citation keys
409
- const citationPattern = /@(\w+)/g;
410
- const citations = new Set<string>();
411
- let match: RegExpExecArray | null;
412
-
413
- while ((match = citationPattern.exec(text)) !== null) {
414
- // Exclude cross-refs like @fig:label
415
- if (match[1] && !match[0].includes(':')) {
416
- citations.add(match[1]);
417
- }
418
- }
419
-
420
- return citations.size;
421
- }
422
-
423
- interface ManuscriptStats {
424
- wordCount: number;
425
- abstractWords: number;
426
- titleChars: number;
427
- figures: number;
428
- tables: number;
429
- references: number;
430
- sections: number;
431
- }
432
-
433
- interface ManuscriptValidationResult {
434
- valid: boolean;
435
- errors: string[];
436
- warnings: string[];
437
- stats: ManuscriptStats | null;
438
- journal?: string;
439
- url?: string;
440
- }
441
-
442
- /**
443
- * Validate manuscript against journal requirements
444
- */
445
- export function validateManuscript(text: string, journalId: string): ManuscriptValidationResult {
446
- const profile = getJournalProfile(journalId);
447
-
448
- if (!profile) {
449
- return {
450
- valid: false,
451
- errors: [`Unknown journal: ${journalId}`],
452
- warnings: [],
453
- stats: null,
454
- };
455
- }
456
-
457
- const req = profile.requirements;
458
- const errors: string[] = [];
459
- const warnings: string[] = [];
460
-
461
- // Extract content
462
- const abstract = extractAbstract(text);
463
- const title = extractTitle(text);
464
- const sections = extractSections(text);
465
- const mainWordCount = countWords(text);
466
- const figureCount = countFigures(text);
467
- const tableCount = countTables(text);
468
- const refCount = countReferences(text);
469
-
470
- const stats: ManuscriptStats = {
471
- wordCount: mainWordCount,
472
- abstractWords: abstract ? countWords(abstract) : 0,
473
- titleChars: title ? title.length : 0,
474
- figures: figureCount,
475
- tables: tableCount,
476
- references: refCount,
477
- sections: sections.length,
478
- };
479
-
480
- // Word limits
481
- if (req.wordLimit) {
482
- if (req.wordLimit.main && mainWordCount > req.wordLimit.main) {
483
- errors.push(`Main text exceeds ${req.wordLimit.main} words (current: ${mainWordCount})`);
484
- }
485
- if (req.wordLimit.abstract && abstract) {
486
- const absWords = countWords(abstract);
487
- if (absWords > req.wordLimit.abstract) {
488
- errors.push(`Abstract exceeds ${req.wordLimit.abstract} words (current: ${absWords})`);
489
- }
490
- }
491
- }
492
-
493
- // References
494
- if (req.references) {
495
- if (req.references.max && refCount > req.references.max) {
496
- errors.push(`References exceed ${req.references.max} (current: ${refCount})`);
497
- }
498
- if (req.references.doiRequired) {
499
- warnings.push('DOI required for all references - run "rev doi check" to verify');
500
- }
501
- }
502
-
503
- // Figures/tables
504
- if (req.figures) {
505
- if (req.figures.max && figureCount > req.figures.max) {
506
- errors.push(`Figures exceed ${req.figures.max} (current: ${figureCount})`);
507
- }
508
- }
509
-
510
- // Required sections
511
- if (req.sections) {
512
- for (const reqSection of req.sections) {
513
- const found = sections.some(s =>
514
- s.toLowerCase().includes(reqSection.toLowerCase())
515
- );
516
- if (!found) {
517
- warnings.push(`Missing required section: ${reqSection}`);
518
- }
519
- }
520
- }
521
-
522
- return {
523
- valid: errors.length === 0,
524
- errors,
525
- warnings,
526
- stats,
527
- journal: profile.name,
528
- url: profile.url,
529
- };
530
- }
531
-
532
- /**
533
- * Validate multiple files against journal requirements
534
- */
535
- export function validateProject(files: string[], journalId: string): ManuscriptValidationResult {
536
- // Combine all file contents
537
- const combined = files
538
- .filter(f => fs.existsSync(f))
539
- .map(f => fs.readFileSync(f, 'utf-8'))
540
- .join('\n\n');
541
-
542
- return validateManuscript(combined, journalId);
543
- }