docrev 0.11.3 → 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 (193) hide show
  1. package/CHANGELOG.md +22 -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/build.d.ts +43 -0
  6. package/dist/lib/build.d.ts.map +1 -1
  7. package/dist/lib/build.js +175 -5
  8. package/dist/lib/build.js.map +1 -1
  9. package/dist/lib/commands/build.d.ts.map +1 -1
  10. package/dist/lib/commands/build.js +39 -125
  11. package/dist/lib/commands/build.js.map +1 -1
  12. package/dist/lib/commands/comments.js +3 -3
  13. package/dist/lib/commands/comments.js.map +1 -1
  14. package/dist/lib/commands/context.d.ts +12 -1
  15. package/dist/lib/commands/context.d.ts.map +1 -1
  16. package/dist/lib/commands/context.js +34 -1
  17. package/dist/lib/commands/context.js.map +1 -1
  18. package/dist/lib/commands/merge-resolve.js +1 -1
  19. package/dist/lib/commands/merge-resolve.js.map +1 -1
  20. package/dist/lib/commands/quality.js +2 -2
  21. package/dist/lib/commands/quality.js.map +1 -1
  22. package/dist/lib/commands/sections.js +1 -1
  23. package/dist/lib/commands/sections.js.map +1 -1
  24. package/dist/lib/commands/text-ops.js +1 -1
  25. package/dist/lib/commands/text-ops.js.map +1 -1
  26. package/dist/lib/commands/utilities.d.ts.map +1 -1
  27. package/dist/lib/commands/utilities.js +5 -2
  28. package/dist/lib/commands/utilities.js.map +1 -1
  29. package/dist/lib/commands/word-tools.js +2 -2
  30. package/dist/lib/commands/word-tools.js.map +1 -1
  31. package/dist/lib/crossref.d.ts.map +1 -1
  32. package/dist/lib/crossref.js +12 -41
  33. package/dist/lib/crossref.js.map +1 -1
  34. package/dist/lib/csl.d.ts.map +1 -1
  35. package/dist/lib/csl.js +14 -22
  36. package/dist/lib/csl.js.map +1 -1
  37. package/dist/lib/diff-engine.js +1 -1
  38. package/dist/lib/diff-engine.js.map +1 -1
  39. package/dist/lib/equations.d.ts.map +1 -1
  40. package/dist/lib/equations.js +12 -3
  41. package/dist/lib/equations.js.map +1 -1
  42. package/dist/lib/errors.d.ts.map +1 -1
  43. package/dist/lib/errors.js +1 -30
  44. package/dist/lib/errors.js.map +1 -1
  45. package/dist/lib/image-registry.d.ts.map +1 -1
  46. package/dist/lib/image-registry.js +4 -0
  47. package/dist/lib/image-registry.js.map +1 -1
  48. package/dist/lib/import.d.ts +1 -1
  49. package/dist/lib/import.d.ts.map +1 -1
  50. package/dist/lib/import.js +1 -1
  51. package/dist/lib/import.js.map +1 -1
  52. package/dist/lib/input.d.ts +0 -11
  53. package/dist/lib/input.d.ts.map +1 -1
  54. package/dist/lib/input.js +0 -35
  55. package/dist/lib/input.js.map +1 -1
  56. package/dist/lib/merge.d.ts.map +1 -1
  57. package/dist/lib/merge.js +9 -1
  58. package/dist/lib/merge.js.map +1 -1
  59. package/dist/lib/ooxml.d.ts +22 -0
  60. package/dist/lib/ooxml.d.ts.map +1 -1
  61. package/dist/lib/ooxml.js +130 -0
  62. package/dist/lib/ooxml.js.map +1 -1
  63. package/dist/lib/orcid.d.ts.map +1 -1
  64. package/dist/lib/orcid.js +16 -7
  65. package/dist/lib/orcid.js.map +1 -1
  66. package/dist/lib/plugins.d.ts.map +1 -1
  67. package/dist/lib/plugins.js +8 -4
  68. package/dist/lib/plugins.js.map +1 -1
  69. package/dist/lib/protect-restore.d.ts.map +1 -1
  70. package/dist/lib/protect-restore.js +7 -5
  71. package/dist/lib/protect-restore.js.map +1 -1
  72. package/dist/lib/restore-references.d.ts.map +1 -1
  73. package/dist/lib/restore-references.js +25 -3
  74. package/dist/lib/restore-references.js.map +1 -1
  75. package/dist/lib/schema.d.ts.map +1 -1
  76. package/dist/lib/schema.js +1 -19
  77. package/dist/lib/schema.js.map +1 -1
  78. package/dist/lib/slides.js +1 -1
  79. package/dist/lib/slides.js.map +1 -1
  80. package/dist/lib/spelling.js +1 -1
  81. package/dist/lib/spelling.js.map +1 -1
  82. package/dist/lib/tui.js +0 -1
  83. package/dist/lib/tui.js.map +1 -1
  84. package/dist/lib/utils.d.ts +14 -0
  85. package/dist/lib/utils.d.ts.map +1 -1
  86. package/dist/lib/utils.js +41 -0
  87. package/dist/lib/utils.js.map +1 -1
  88. package/dist/lib/word-extraction.d.ts +5 -5
  89. package/dist/lib/word-extraction.d.ts.map +1 -1
  90. package/dist/lib/word-extraction.js +25 -106
  91. package/dist/lib/word-extraction.js.map +1 -1
  92. package/dist/lib/word.d.ts +14 -38
  93. package/dist/lib/word.d.ts.map +1 -1
  94. package/dist/lib/word.js +24 -179
  95. package/dist/lib/word.js.map +1 -1
  96. package/dist/lib/wordcomments.d.ts.map +1 -1
  97. package/dist/lib/wordcomments.js +9 -7
  98. package/dist/lib/wordcomments.js.map +1 -1
  99. package/package.json +17 -6
  100. package/.gitattributes +0 -1
  101. package/PLAN-tables-and-postprocess.md +0 -850
  102. package/bin/rev.ts +0 -145
  103. package/docs-src/build.py +0 -113
  104. package/docs-src/extra.css +0 -208
  105. package/docs-src/md-to-html.lua +0 -6
  106. package/docs-src/template.html +0 -116
  107. package/eslint.config.js +0 -27
  108. package/lib/anchor-match.ts +0 -307
  109. package/lib/annotations.ts +0 -695
  110. package/lib/build.ts +0 -2047
  111. package/lib/citations.ts +0 -160
  112. package/lib/commands/build.ts +0 -885
  113. package/lib/commands/citations.ts +0 -515
  114. package/lib/commands/comments.ts +0 -1077
  115. package/lib/commands/context.ts +0 -185
  116. package/lib/commands/core.ts +0 -328
  117. package/lib/commands/doi.ts +0 -451
  118. package/lib/commands/file-ops.ts +0 -372
  119. package/lib/commands/history.ts +0 -320
  120. package/lib/commands/index.ts +0 -87
  121. package/lib/commands/init.ts +0 -259
  122. package/lib/commands/merge-resolve.ts +0 -378
  123. package/lib/commands/preview.ts +0 -178
  124. package/lib/commands/project-info.ts +0 -244
  125. package/lib/commands/quality.ts +0 -517
  126. package/lib/commands/response.ts +0 -454
  127. package/lib/commands/section-boundaries.ts +0 -82
  128. package/lib/commands/sections.ts +0 -451
  129. package/lib/commands/sync.ts +0 -689
  130. package/lib/commands/text-ops.ts +0 -449
  131. package/lib/commands/utilities.ts +0 -448
  132. package/lib/commands/verify-anchors.ts +0 -272
  133. package/lib/commands/word-tools.ts +0 -340
  134. package/lib/comment-realign.ts +0 -99
  135. package/lib/config.ts +0 -84
  136. package/lib/crossref.ts +0 -781
  137. package/lib/csl.ts +0 -191
  138. package/lib/dependencies.ts +0 -132
  139. package/lib/diff-engine.ts +0 -465
  140. package/lib/doi-cache.ts +0 -115
  141. package/lib/doi.ts +0 -879
  142. package/lib/equations.ts +0 -506
  143. package/lib/errors.ts +0 -350
  144. package/lib/format.ts +0 -541
  145. package/lib/git.ts +0 -326
  146. package/lib/grammar.ts +0 -303
  147. package/lib/image-registry.ts +0 -180
  148. package/lib/import.ts +0 -932
  149. package/lib/input.ts +0 -174
  150. package/lib/journals.ts +0 -543
  151. package/lib/macro-filter.lua +0 -201
  152. package/lib/macros.ts +0 -273
  153. package/lib/merge.ts +0 -633
  154. package/lib/ooxml.ts +0 -768
  155. package/lib/orcid.ts +0 -144
  156. package/lib/pdf-comments.ts +0 -263
  157. package/lib/pdf-import.ts +0 -524
  158. package/lib/plugins.ts +0 -362
  159. package/lib/postprocess.ts +0 -188
  160. package/lib/pptx-color-filter.lua +0 -37
  161. package/lib/pptx-template.ts +0 -469
  162. package/lib/pptx-themes/academic.pptx +0 -0
  163. package/lib/pptx-themes/corporate.pptx +0 -0
  164. package/lib/pptx-themes/dark.pptx +0 -0
  165. package/lib/pptx-themes/default.pptx +0 -0
  166. package/lib/pptx-themes/minimal.pptx +0 -0
  167. package/lib/pptx-themes/plant.pptx +0 -0
  168. package/lib/pptx-themes.ts +0 -483
  169. package/lib/protect-restore.ts +0 -520
  170. package/lib/rate-limiter.ts +0 -127
  171. package/lib/response.ts +0 -200
  172. package/lib/restore-references.ts +0 -240
  173. package/lib/review.ts +0 -327
  174. package/lib/schema.ts +0 -494
  175. package/lib/scientific-words.ts +0 -73
  176. package/lib/sections.ts +0 -428
  177. package/lib/slides.ts +0 -756
  178. package/lib/spelling.ts +0 -334
  179. package/lib/templates.ts +0 -526
  180. package/lib/themes.ts +0 -742
  181. package/lib/trackchanges.ts +0 -166
  182. package/lib/tui.ts +0 -450
  183. package/lib/types.ts +0 -546
  184. package/lib/undo.ts +0 -250
  185. package/lib/utils.ts +0 -69
  186. package/lib/variables.ts +0 -179
  187. package/lib/word-extraction.ts +0 -525
  188. package/lib/word.ts +0 -526
  189. package/lib/wordcomments.ts +0 -789
  190. package/mkdocs.yml +0 -64
  191. package/scripts/postbuild.js +0 -47
  192. package/tsconfig.json +0 -26
  193. package/types/index.d.ts +0 -531
@@ -1,454 +0,0 @@
1
- /**
2
- * Response commands: response, validate, profiles, anonymize
3
- *
4
- * Commands for generating reviewer responses and validating manuscripts.
5
- */
6
-
7
- import type { Command } from 'commander';
8
- import {
9
- chalk,
10
- fs,
11
- path,
12
- fmt,
13
- collectComments,
14
- generateResponseLetter,
15
- groupByReviewer,
16
- getUserName,
17
- } from './context.js';
18
-
19
- interface ResponseOptions {
20
- output?: string;
21
- author?: string;
22
- context?: boolean;
23
- location?: boolean;
24
- }
25
-
26
- interface ValidateOptions {
27
- journal?: string;
28
- list?: boolean;
29
- }
30
-
31
- interface ProfilesOptions {
32
- list?: boolean;
33
- new?: string;
34
- project?: boolean;
35
- dirs?: boolean;
36
- fetchCsl?: string;
37
- listCsl?: boolean;
38
- }
39
-
40
- interface AnonymizeOptions {
41
- output?: string;
42
- authors?: string;
43
- dryRun?: boolean;
44
- }
45
-
46
- /**
47
- * Register response commands with the program
48
- */
49
- export function register(program: Command): void {
50
- // ==========================================================================
51
- // RESPONSE command - Generate response letter for reviewers
52
- // ==========================================================================
53
-
54
- program
55
- .command('response')
56
- .description('Generate response letter from reviewer comments')
57
- .argument('[files...]', 'Markdown files to process (default: all section files)')
58
- .option('-o, --output <file>', 'Output file (default: response-letter.md)')
59
- .option('-a, --author <name>', 'Author name for identifying replies')
60
- .option('--no-context', 'Omit context snippets')
61
- .option('--no-location', 'Omit file:line references')
62
- .action(async (files: string[] | undefined, options: ResponseOptions) => {
63
- let mdFiles = files;
64
- if (!mdFiles || mdFiles.length === 0) {
65
- const allFiles = fs.readdirSync('.').filter(f =>
66
- f.endsWith('.md') && !['README.md', 'CLAUDE.md', 'paper.md'].includes(f)
67
- );
68
- mdFiles = allFiles;
69
- }
70
-
71
- if (mdFiles.length === 0) {
72
- console.error(fmt.status('error', 'No markdown files found'));
73
- process.exit(1);
74
- }
75
-
76
- const spin = fmt.spinner('Collecting comments...').start();
77
-
78
- const comments = await collectComments(mdFiles);
79
- spin.stop();
80
-
81
- if (comments.length === 0) {
82
- console.log(fmt.status('info', 'No comments found in files'));
83
- return;
84
- }
85
-
86
- const letter = generateResponseLetter(comments, {
87
- authorName: options.author || getUserName() || 'Author',
88
- includeContext: options.context !== false,
89
- includeLocation: options.location !== false,
90
- });
91
-
92
- const outputPath = options.output || 'response-letter.md';
93
- fs.writeFileSync(outputPath, letter, 'utf-8');
94
-
95
- const grouped = groupByReviewer(comments);
96
- const reviewers = [...grouped.keys()].filter(r =>
97
- !r.toLowerCase().includes('claude') &&
98
- r.toLowerCase() !== (options.author || '').toLowerCase()
99
- );
100
-
101
- console.log(fmt.header('Response Letter Generated'));
102
- console.log();
103
-
104
- const rows = reviewers.map(r => [r, grouped.get(r)!.length.toString()]);
105
- console.log(fmt.table(['Reviewer', 'Comments'], rows));
106
- console.log();
107
- console.log(fmt.status('success', `Created ${outputPath}`));
108
- });
109
-
110
- // ==========================================================================
111
- // VALIDATE command - Check manuscript against journal requirements
112
- // ==========================================================================
113
-
114
- program
115
- .command('validate')
116
- .description('Validate manuscript against journal requirements')
117
- .argument('[files...]', 'Markdown files to validate (default: all section files)')
118
- .option('-j, --journal <name>', 'Journal profile (e.g., nature, plos-one, science)')
119
- .option('--list', 'List available journal profiles')
120
- .action(async (files: string[] | undefined, options: ValidateOptions) => {
121
- const { listJournals, validateProject, getJournalProfile } = await import('../journals.js');
122
-
123
- if (options.list) {
124
- console.log(fmt.header('Available Journal Profiles'));
125
- console.log();
126
- const journals = listJournals();
127
- const builtIn = journals.filter(j => !j.custom);
128
- const custom = journals.filter(j => j.custom);
129
-
130
- for (const j of builtIn) {
131
- const profile = getJournalProfile(j.id);
132
- const fmtTag = profile?.formatting ? chalk.green(' [formatting]') : '';
133
- console.log(` ${chalk.bold(j.id)} - ${j.name}${fmtTag}`);
134
- if (j.url) console.log(chalk.dim(` ${j.url}`));
135
- }
136
-
137
- if (custom.length > 0) {
138
- console.log();
139
- console.log(chalk.cyan(' Custom Profiles:'));
140
- for (const j of custom) {
141
- const profile = getJournalProfile(j.id);
142
- const fmtTag = profile?.formatting ? chalk.green(' [formatting]') : '';
143
- console.log(` ${chalk.bold(j.id)} - ${j.name} ${chalk.cyan('[custom]')}${fmtTag}`);
144
- if (j.url) console.log(chalk.dim(` ${j.url}`));
145
- }
146
- }
147
-
148
- console.log();
149
- console.log(chalk.dim('Usage: rev validate --journal <name>'));
150
- console.log(chalk.dim('Profiles with [formatting] can also be used with: rev build -j <name>'));
151
- console.log(chalk.dim('Manage custom profiles: rev profiles'));
152
- return;
153
- }
154
-
155
- if (!options.journal) {
156
- console.error(fmt.status('error', 'Please specify a journal with --journal <name>'));
157
- console.error(chalk.dim('Use --list to see available profiles'));
158
- process.exit(1);
159
- }
160
-
161
- const profile = getJournalProfile(options.journal);
162
- if (!profile) {
163
- console.error(fmt.status('error', `Unknown journal: ${options.journal}`));
164
- console.error(chalk.dim('Use --list to see available profiles'));
165
- process.exit(1);
166
- }
167
-
168
- let mdFiles = files;
169
- if (!mdFiles || mdFiles.length === 0) {
170
- mdFiles = fs.readdirSync('.').filter(f =>
171
- f.endsWith('.md') && !['README.md', 'CLAUDE.md', 'paper.md'].includes(f)
172
- );
173
- }
174
-
175
- if (mdFiles.length === 0) {
176
- console.error(fmt.status('error', 'No markdown files found'));
177
- process.exit(1);
178
- }
179
-
180
- console.log(fmt.header(`Validating for ${profile.name}`));
181
- console.log(chalk.dim(` ${profile.url}`));
182
- console.log();
183
-
184
- const result = validateProject(mdFiles, options.journal);
185
-
186
- if (result.stats) {
187
- console.log(chalk.cyan('Manuscript Stats:'));
188
- console.log(fmt.table(['Metric', 'Value'], [
189
- ['Word count', result.stats.wordCount.toString()],
190
- ['Abstract', `${result.stats.abstractWords} words`],
191
- ['Title', `${result.stats.titleChars} chars`],
192
- ['Figures', result.stats.figures.toString()],
193
- ['Tables', result.stats.tables.toString()],
194
- ['References', result.stats.references.toString()],
195
- ]));
196
- console.log();
197
- }
198
-
199
- if (result.errors.length > 0) {
200
- console.log(chalk.red('Errors:'));
201
- for (const err of result.errors) {
202
- console.log(chalk.red(` ✗ ${err}`));
203
- }
204
- console.log();
205
- }
206
-
207
- if (result.warnings.length > 0) {
208
- console.log(chalk.yellow('Warnings:'));
209
- for (const warn of result.warnings) {
210
- console.log(chalk.yellow(` ⚠ ${warn}`));
211
- }
212
- console.log();
213
- }
214
-
215
- if (result.valid) {
216
- console.log(fmt.status('success', `Manuscript meets ${profile.name} requirements`));
217
- } else {
218
- console.log(fmt.status('error', `Manuscript has ${result.errors.length} error(s)`));
219
- process.exit(1);
220
- }
221
- });
222
-
223
- // ==========================================================================
224
- // PROFILES command - Manage custom journal profiles
225
- // ==========================================================================
226
-
227
- program
228
- .command('profiles')
229
- .description('Manage custom journal profiles')
230
- .option('--list', 'List all custom profiles')
231
- .option('--new <name>', 'Create a new profile template')
232
- .option('--project', 'Create profile in project directory (with --new)')
233
- .option('--dirs', 'Show profile directory locations')
234
- .option('--fetch-csl <name>', 'Download a CSL citation style to cache')
235
- .option('--list-csl', 'List cached CSL citation styles')
236
- .action(async (options: ProfilesOptions) => {
237
- const {
238
- listCustomProfiles,
239
- saveProfileTemplate,
240
- getPluginDirs,
241
- } = await import('../plugins.js');
242
- const { listJournals } = await import('../journals.js');
243
-
244
- if (options.listCsl) {
245
- const { listCachedCSL, getCSLCacheDir } = await import('../csl.js');
246
- const cached = listCachedCSL();
247
- console.log(fmt.header('Cached CSL Styles'));
248
- console.log(chalk.dim(` ${getCSLCacheDir()}`));
249
- console.log();
250
- if (cached.length === 0) {
251
- console.log(chalk.dim(' No cached styles. Download with: rev profiles --fetch-csl <name>'));
252
- } else {
253
- for (const c of cached) {
254
- console.log(` ${chalk.bold(c.name)}`);
255
- }
256
- console.log();
257
- console.log(chalk.dim(` ${cached.length} cached style(s)`));
258
- }
259
- return;
260
- }
261
-
262
- if (options.fetchCsl) {
263
- const { fetchCSL, resolveCSL, getCSLAliases } = await import('../csl.js');
264
-
265
- // Check if already cached
266
- const existing = resolveCSL(options.fetchCsl);
267
- if (existing) {
268
- console.log(fmt.status('info', `Already cached: ${existing}`));
269
- return;
270
- }
271
-
272
- const spin = fmt.spinner(`Downloading CSL style "${options.fetchCsl}"...`).start();
273
- const result = await fetchCSL(options.fetchCsl);
274
- spin.stop();
275
-
276
- if (result) {
277
- console.log(fmt.status('success', `Downloaded: ${result}`));
278
- } else {
279
- console.error(fmt.status('error', `Could not download CSL style "${options.fetchCsl}"`));
280
- const aliases = getCSLAliases();
281
- const names = Object.keys(aliases).sort().join(', ');
282
- console.error(chalk.dim(` Known short names: ${names}`));
283
- process.exit(1);
284
- }
285
- return;
286
- }
287
-
288
- if (options.dirs) {
289
- const dirs = getPluginDirs();
290
- console.log(fmt.header('Profile Directories'));
291
- console.log();
292
- console.log(` User: ${dirs.user}`);
293
- console.log(chalk.dim(` ${dirs.userExists ? 'exists' : 'not created'}`));
294
- console.log();
295
- console.log(` Project: ${dirs.project}`);
296
- console.log(chalk.dim(` ${dirs.projectExists ? 'exists' : 'not created'}`));
297
- console.log();
298
- console.log(chalk.dim('Use --new <name> to create a profile template'));
299
- return;
300
- }
301
-
302
- if (options.new) {
303
- try {
304
- const filePath = saveProfileTemplate(options.new, options.project);
305
- console.log(fmt.status('success', `Created profile template: ${filePath}`));
306
- console.log(chalk.dim('Edit the file to customize journal requirements'));
307
- } catch (err) {
308
- console.error(fmt.status('error', (err as Error).message));
309
- process.exit(1);
310
- }
311
- return;
312
- }
313
-
314
- console.log(fmt.header('Custom Journal Profiles'));
315
- console.log();
316
-
317
- const customProfiles = listCustomProfiles();
318
-
319
- if (customProfiles.length === 0) {
320
- console.log(chalk.dim(' No custom profiles found'));
321
- console.log();
322
- console.log(chalk.dim(' Create one with: rev profiles --new "Journal Name"'));
323
- console.log();
324
- const dirs = getPluginDirs();
325
- console.log(chalk.dim(` User profiles: ${dirs.user}`));
326
- console.log(chalk.dim(` Project profiles: ${dirs.project}`));
327
- } else {
328
- for (const p of customProfiles) {
329
- const source = p.source === 'project' ? chalk.cyan('[project]') : chalk.dim('[user]');
330
- console.log(` ${chalk.bold(p.id)} - ${p.name} ${source}`);
331
- console.log(chalk.dim(` ${p.path}`));
332
- }
333
- console.log();
334
- console.log(chalk.dim(` ${customProfiles.length} custom profile(s)`));
335
- }
336
-
337
- console.log();
338
-
339
- const allJournals = listJournals();
340
- const builtIn = allJournals.filter(j => !j.custom).length;
341
- console.log(chalk.dim(` ${builtIn} built-in profiles available (rev validate --list)`));
342
- });
343
-
344
- // ==========================================================================
345
- // ANONYMIZE command - Prepare document for blind review
346
- // ==========================================================================
347
-
348
- program
349
- .command('anonymize')
350
- .description('Prepare document for blind review')
351
- .argument('<input>', 'Input markdown file or directory')
352
- .option('-o, --output <file>', 'Output file (default: input-anonymous.md)')
353
- .option('--authors <names>', 'Author names to redact (comma-separated)')
354
- .option('--dry-run', 'Show what would be changed without writing')
355
- .action(async (input: string, options: AnonymizeOptions) => {
356
- const { default: YAML } = await import('yaml');
357
-
358
- const isDir = fs.existsSync(input) && fs.statSync(input).isDirectory();
359
- const files = isDir
360
- ? fs.readdirSync(input)
361
- .filter(f => f.endsWith('.md') && !['README.md', 'CLAUDE.md'].includes(f))
362
- .map(f => path.join(input, f))
363
- : [input];
364
-
365
- if (files.length === 0) {
366
- console.error(fmt.status('error', 'No markdown files found'));
367
- process.exit(1);
368
- }
369
-
370
- let authorNames: string[] = [];
371
- if (options.authors) {
372
- authorNames = options.authors.split(',').map(n => n.trim());
373
- } else {
374
- const configPath = isDir ? path.join(input, 'rev.yaml') : 'rev.yaml';
375
- if (fs.existsSync(configPath)) {
376
- try {
377
- const config = YAML.parse(fs.readFileSync(configPath, 'utf-8'));
378
- if (config.authors) {
379
- authorNames = config.authors.map((a: string | { name: string }) => typeof a === 'string' ? a : a.name).filter(Boolean);
380
- }
381
- } catch { /* ignore */ }
382
- }
383
- }
384
-
385
- console.log(fmt.header('Anonymizing Document'));
386
- console.log();
387
-
388
- let totalChanges = 0;
389
-
390
- for (const file of files) {
391
- if (!fs.existsSync(file)) {
392
- console.error(chalk.yellow(` Skipping: ${file} (not found)`));
393
- continue;
394
- }
395
-
396
- let text = fs.readFileSync(file, 'utf-8');
397
- let changes = 0;
398
-
399
- text = text.replace(/^---\n([\s\S]*?)\n---/, (match, fm) => {
400
- let modified = fm;
401
- modified = modified.replace(/^author:.*(?:\n(?: |\t).*)*$/m, '');
402
- modified = modified.replace(/^authors:.*(?:\n(?: |\t|-\s+).*)*$/m, '');
403
- modified = modified.replace(/^affiliation:.*$/m, '');
404
- modified = modified.replace(/^email:.*$/m, '');
405
- if (modified !== fm) changes++;
406
- return '---\n' + modified.replace(/\n{3,}/g, '\n\n').trim() + '\n---';
407
- });
408
-
409
- const ackPatterns = [
410
- /^#+\s*Acknowledgments?[\s\S]*?(?=^#|\Z)/gmi,
411
- /^#+\s*Funding[\s\S]*?(?=^#|\Z)/gmi,
412
- ];
413
- for (const pattern of ackPatterns) {
414
- const before = text;
415
- text = text.replace(pattern, '');
416
- if (text !== before) changes++;
417
- }
418
-
419
- for (const name of authorNames) {
420
- const namePattern = new RegExp(`\\b${name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, 'gi');
421
- const before = text;
422
- text = text.replace(namePattern, '[AUTHOR]');
423
- if (text !== before) changes++;
424
- }
425
-
426
- for (const name of authorNames) {
427
- const lastName = name.split(/\s+/).pop();
428
- if (lastName && lastName.length > 2) {
429
- const citePat = new RegExp(`@${lastName}(\\d{4})`, 'gi');
430
- const before = text;
431
- text = text.replace(citePat, '@AUTHOR$1');
432
- if (text !== before) changes++;
433
- }
434
- }
435
-
436
- totalChanges += changes;
437
-
438
- if (options.dryRun) {
439
- console.log(chalk.dim(` ${path.basename(file)}: ${changes} change(s)`));
440
- } else {
441
- const outPath = options.output || file.replace(/\.md$/, '-anonymous.md');
442
- fs.writeFileSync(outPath, text, 'utf-8');
443
- console.log(fmt.status('success', `${path.basename(file)} → ${path.basename(outPath)} (${changes} changes)`));
444
- }
445
- }
446
-
447
- console.log();
448
- if (options.dryRun) {
449
- console.log(chalk.dim(` Total: ${totalChanges} change(s) would be made`));
450
- } else {
451
- console.log(fmt.status('success', `Anonymized ${files.length} file(s)`));
452
- }
453
- });
454
- }
@@ -1,82 +0,0 @@
1
- /**
2
- * Compute section boundaries in a DOCX from its real heading paragraphs.
3
- *
4
- * Given the configured `sections.yaml` and the headings extracted via
5
- * `extractHeadings()`, return one boundary per section file with text
6
- * positions in the same coordinate system as `CommentAnchorData.docPosition`.
7
- *
8
- * Matching is by heading text (primary header + aliases, case-insensitive).
9
- * This replaces the older keyword-search-in-body-text approach which would
10
- * pick up section names that happen to appear inside prose ("results across
11
- * countries") or in structured-abstract labels where paragraph boundaries
12
- * are lost in concatenation.
13
- */
14
-
15
- import type { DocxHeading } from '../word-extraction.js';
16
- import type { SectionConfig } from '../types.js';
17
-
18
- export interface SectionBoundary {
19
- file: string;
20
- start: number;
21
- end: number;
22
- }
23
-
24
- export function computeSectionBoundaries(
25
- sections: Record<string, SectionConfig>,
26
- headings: DocxHeading[],
27
- docLength?: number,
28
- ): SectionBoundary[] {
29
- const matched: SectionBoundary[] = [];
30
-
31
- // Only consider top-level (Heading1-style) when level info is available;
32
- // when level==0 (unparseable style), fall back to all headings.
33
- const haveLevels = headings.some(h => h.level > 0);
34
- const candidates = haveLevels ? headings.filter(h => h.level === 1) : headings;
35
-
36
- for (const [file, cfg] of Object.entries(sections)) {
37
- const targets = [cfg.header, ...(cfg.aliases || [])]
38
- .filter(Boolean)
39
- .map(s => s.toLowerCase().trim());
40
-
41
- let firstMatch = -1;
42
- for (const h of candidates) {
43
- const text = h.text.toLowerCase().trim();
44
- if (targets.includes(text)) {
45
- firstMatch = h.docPosition;
46
- break;
47
- }
48
- }
49
-
50
- // Fallback: if no level-1 hit, allow any-level match (handles single-level docs)
51
- if (firstMatch < 0 && haveLevels) {
52
- for (const h of headings) {
53
- const text = h.text.toLowerCase().trim();
54
- if (targets.includes(text)) {
55
- firstMatch = h.docPosition;
56
- break;
57
- }
58
- }
59
- }
60
-
61
- if (firstMatch >= 0) {
62
- matched.push({ file, start: firstMatch, end: Number.MAX_SAFE_INTEGER });
63
- }
64
- }
65
-
66
- // Sort by start position and tighten each end to the next start.
67
- // The last section's end is capped at docLength when known, otherwise
68
- // left at MAX_SAFE_INTEGER. Without the cap, single-section configs
69
- // produce a sectionLength of ~9e15, collapsing proportional-position
70
- // math in insertCommentsIntoMarkdown to 0 and stacking every comment
71
- // at the document start.
72
- matched.sort((a, b) => a.start - b.start);
73
- for (let i = 0; i < matched.length - 1; i++) {
74
- matched[i].end = matched[i + 1].start;
75
- }
76
- if (matched.length > 0 && docLength !== undefined) {
77
- const last = matched[matched.length - 1];
78
- if (last.end > docLength) last.end = docLength;
79
- }
80
-
81
- return matched;
82
- }