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/sections.ts DELETED
@@ -1,428 +0,0 @@
1
- /**
2
- * Section handling - map between section .md files and combined documents
3
- */
4
-
5
- import * as fs from 'fs';
6
- import * as path from 'path';
7
- import YAML from 'yaml';
8
- import type { SectionConfig, SectionsConfig, ExtractedSection } from './types.js';
9
-
10
- /**
11
- * Default section order (common academic paper structure)
12
- */
13
- const DEFAULT_ORDER = [
14
- 'abstract',
15
- 'introduction',
16
- 'background',
17
- 'literature',
18
- 'theory',
19
- 'methods',
20
- 'materials',
21
- 'data',
22
- 'results',
23
- 'analysis',
24
- 'discussion',
25
- 'conclusion',
26
- 'references',
27
- 'appendix',
28
- 'supplementary',
29
- ];
30
-
31
- /**
32
- * Extract header from a markdown file
33
- */
34
- export function extractHeader(filePath: string): string | null {
35
- if (!fs.existsSync(filePath)) return null;
36
-
37
- const content = fs.readFileSync(filePath, 'utf-8');
38
- const lines = content.split('\n');
39
-
40
- for (const line of lines) {
41
- const match = line.match(/^#\s+(.+)$/);
42
- if (match && match[1]) {
43
- return match[1].trim();
44
- }
45
- }
46
-
47
- return null;
48
- }
49
-
50
- /**
51
- * Extract the first markdown heading of ANY level (`#`–`######`) from a file.
52
- *
53
- * Unlike {@link extractHeader} (which is H1-only by contract), this is used to
54
- * derive a section's header from files that lead with a subsection — e.g.
55
- * `02_objectives.md` starting with `## 1.2 Objectives`. Using the real first
56
- * heading lets the derived header match the corresponding docx heading.
57
- */
58
- export function extractFirstHeading(filePath: string): string | null {
59
- if (!fs.existsSync(filePath)) return null;
60
-
61
- const content = fs.readFileSync(filePath, 'utf-8');
62
- for (const line of content.split('\n')) {
63
- const match = line.match(/^#{1,6}\s+(.+)$/);
64
- if (match && match[1]) {
65
- return match[1].trim();
66
- }
67
- }
68
-
69
- return null;
70
- }
71
-
72
- /**
73
- * Generate sections.yaml from existing .md files
74
- */
75
- export function generateConfig(
76
- directory: string,
77
- excludePatterns: string[] = ['paper.md', 'README.md', 'CLAUDE.md']
78
- ): SectionsConfig {
79
- const files = fs.readdirSync(directory).filter((f) => {
80
- if (!f.endsWith('.md')) return false;
81
- if (excludePatterns.some((p) => f.toLowerCase().includes(p.toLowerCase()))) return false;
82
- return true;
83
- });
84
-
85
- const sections: Record<string, SectionConfig> = {};
86
-
87
- for (const file of files) {
88
- const filePath = path.join(directory, file);
89
- // Use the first heading at any level: a section file may be headed by a
90
- // subsection (## 1.2 Objectives). H1-only extraction left such files with a
91
- // filename-derived header that never matched the reviewed document.
92
- const header = extractFirstHeading(filePath);
93
- const baseName = path.basename(file, '.md').toLowerCase();
94
-
95
- // Determine order based on common patterns
96
- let order = DEFAULT_ORDER.findIndex((s) => baseName.includes(s));
97
- if (order === -1) order = 999;
98
-
99
- sections[file] = {
100
- header: header || titleCase(baseName),
101
- aliases: [],
102
- order: order,
103
- };
104
- }
105
-
106
- // Sort by order
107
- const sorted = Object.entries(sections)
108
- .sort((a, b) => (a[1].order ?? 999) - (b[1].order ?? 999))
109
- .reduce((acc, [k, v]) => {
110
- acc[k] = v;
111
- return acc;
112
- }, {} as Record<string, SectionConfig>);
113
-
114
- return {
115
- version: 1,
116
- description: 'Section configuration for rev import/split',
117
- sections: sorted,
118
- };
119
- }
120
-
121
- /**
122
- * Convert string to title case
123
- */
124
- function titleCase(str: string): string {
125
- return str
126
- .split(/[-_\s]+/)
127
- .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
128
- .join(' ');
129
- }
130
-
131
- /**
132
- * Load sections config from yaml file
133
- */
134
- export function loadConfig(configPath: string): SectionsConfig {
135
- const content = fs.readFileSync(configPath, 'utf-8');
136
- const config = YAML.parse(content);
137
-
138
- // Normalize: convert string values to full config objects
139
- const normalized: SectionsConfig = {
140
- version: config.version || 1,
141
- description: config.description,
142
- sections: {},
143
- };
144
-
145
- for (const [file, value] of Object.entries(config.sections || {})) {
146
- if (typeof value === 'string') {
147
- normalized.sections[file] = {
148
- header: value,
149
- aliases: [],
150
- };
151
- } else {
152
- const typedValue = value as SectionConfig;
153
- normalized.sections[file] = {
154
- header: typedValue.header,
155
- aliases: typedValue.aliases || [],
156
- order: typedValue.order,
157
- };
158
- }
159
- }
160
-
161
- return normalized;
162
- }
163
-
164
- /**
165
- * Save sections config to yaml file
166
- */
167
- export function saveConfig(configPath: string, config: SectionsConfig): void {
168
- const yamlStr = YAML.stringify(config, { indent: 2, lineWidth: 100 });
169
- fs.writeFileSync(configPath, yamlStr, 'utf-8');
170
- }
171
-
172
- /**
173
- * Derive a SectionsConfig from the `sections:` list in rev.yaml.
174
- *
175
- * Each listed file's header is its first markdown H1 (falling back to a
176
- * title-cased file name); order follows the list order in rev.yaml. This is
177
- * the same section list that `build` consumes, so a project that only has a
178
- * `rev.yaml` needs no separate `sections.yaml`.
179
- *
180
- * Returns null when rev.yaml is absent, unparseable, or has no `sections` list.
181
- */
182
- export function deriveSectionsFromRev(directory: string): SectionsConfig | null {
183
- const revPath = path.join(directory, 'rev.yaml');
184
- if (!fs.existsSync(revPath)) return null;
185
-
186
- let parsed: { sections?: unknown };
187
- try {
188
- parsed = YAML.parse(fs.readFileSync(revPath, 'utf-8')) || {};
189
- } catch {
190
- return null;
191
- }
192
-
193
- const list = parsed.sections;
194
- if (!Array.isArray(list) || list.length === 0) return null;
195
-
196
- const sections: Record<string, SectionConfig> = {};
197
- list.forEach((entry, index) => {
198
- if (typeof entry !== 'string') return;
199
- const header = extractFirstHeading(path.join(directory, entry)) || titleCase(path.basename(entry, '.md'));
200
- sections[entry] = { header, aliases: [], order: index };
201
- });
202
-
203
- if (Object.keys(sections).length === 0) return null;
204
-
205
- return {
206
- version: 1,
207
- description: 'Derived from rev.yaml sections list',
208
- sections,
209
- };
210
- }
211
-
212
- /**
213
- * Resolve the effective sections config for a project directory.
214
- *
215
- * Precedence (single source of truth, with optional override):
216
- * 1. An explicit sections config file (default `sections.yaml`) when it
217
- * exists — lets users override headers/aliases/order.
218
- * 2. Otherwise the `sections:` list in `rev.yaml`, via {@link deriveSectionsFromRev}.
219
- *
220
- * Returns null only when neither source yields any sections; callers turn that
221
- * into a user-facing error.
222
- */
223
- export function resolveSectionsConfig(
224
- directory: string,
225
- configFileName = 'sections.yaml'
226
- ): { config: SectionsConfig; source: string } | null {
227
- const explicitPath = path.resolve(directory, configFileName);
228
- if (fs.existsSync(explicitPath)) {
229
- return { config: loadConfig(explicitPath), source: explicitPath };
230
- }
231
-
232
- const derived = deriveSectionsFromRev(directory);
233
- if (derived) {
234
- return { config: derived, source: path.resolve(directory, 'rev.yaml') };
235
- }
236
-
237
- return null;
238
- }
239
-
240
- /**
241
- * Match a heading to a section file
242
- */
243
- export function matchHeading(
244
- heading: string,
245
- sections: Record<string, SectionConfig>
246
- ): { file: string; config: SectionConfig } | null {
247
- // Strip markdown header prefix (# or ##, etc.) before matching
248
- const normalizedHeading = heading.replace(/^#{1,6}\s+/, '').toLowerCase().trim();
249
-
250
- for (const [file, config] of Object.entries(sections)) {
251
- // Check primary header
252
- if (config.header.toLowerCase().trim() === normalizedHeading) {
253
- return { file, config };
254
- }
255
-
256
- // Check aliases
257
- if (config.aliases) {
258
- for (const alias of config.aliases) {
259
- if (alias.toLowerCase().trim() === normalizedHeading) {
260
- return { file, config };
261
- }
262
- }
263
- }
264
-
265
- // Fuzzy match: check if heading contains the key words
266
- const headerWords = config.header.toLowerCase().split(/\s+/);
267
- const headingWords = normalizedHeading.split(/\s+/);
268
- const matchCount = headerWords.filter((w) => headingWords.includes(w)).length;
269
- if (matchCount >= headerWords.length * 0.7) {
270
- return { file, config };
271
- }
272
- }
273
-
274
- return null;
275
- }
276
-
277
- /**
278
- * Extract sections from Word document text
279
- */
280
- export function extractSectionsFromText(
281
- text: string,
282
- sections: Record<string, SectionConfig>
283
- ): ExtractedSection[] {
284
- const result: ExtractedSection[] = [];
285
-
286
- // Process line by line to detect markdown headers
287
- const lines = text.split('\n');
288
- let currentSection: { file: string; header: string } | null = null;
289
- let currentContent: string[] = [];
290
-
291
- for (let i = 0; i < lines.length; i++) {
292
- const line = lines[i];
293
- if (!line) continue;
294
- const trimmed = line.trim();
295
-
296
- // Explicitly check for markdown headers (# Header)
297
- const headerMatch = trimmed.match(/^(#{1,6})\s+(.+)$/);
298
-
299
- let matchedSection: { file: string; config: SectionConfig } | null = null;
300
- if (headerMatch) {
301
- // This is a markdown header - try to match it to a section
302
- matchedSection = matchHeading(trimmed, sections);
303
- } else if (trimmed.length > 0 && trimmed.length < 100 && !trimmed.includes('.')) {
304
- // Fallback: check if short text without periods matches a section (for plain text headings)
305
- matchedSection = matchHeading(trimmed, sections);
306
- }
307
-
308
- if (matchedSection) {
309
- // Save previous section
310
- if (currentSection) {
311
- // Include header in content for proper diffing
312
- const fullContent = currentSection.header + '\n\n' + currentContent.join('\n').trim();
313
- result.push({
314
- file: currentSection.file,
315
- header: currentSection.header,
316
- content: fullContent.trim(),
317
- matched: true,
318
- });
319
- }
320
-
321
- currentSection = {
322
- file: matchedSection.file,
323
- header: trimmed,
324
- };
325
- currentContent = [];
326
- } else {
327
- currentContent.push(line);
328
- }
329
- }
330
-
331
- // Save last section
332
- if (currentSection) {
333
- // Include header in content for proper diffing
334
- const fullContent = currentSection.header + '\n\n' + currentContent.join('\n').trim();
335
- result.push({
336
- file: currentSection.file,
337
- header: currentSection.header,
338
- content: fullContent.trim(),
339
- matched: true,
340
- });
341
- }
342
-
343
- return result;
344
- }
345
-
346
- /**
347
- * Parse annotated paper.md and split back to section files
348
- */
349
- export function splitAnnotatedPaper(
350
- paperContent: string,
351
- sections: Record<string, SectionConfig>
352
- ): Map<string, string> {
353
- const result = new Map<string, string>();
354
-
355
- // Look for section markers: <!-- @section:filename.md -->
356
- const markerPattern = /<!--\s*@section:(\S+\.md)\s*-->/g;
357
- const markers = [...paperContent.matchAll(markerPattern)];
358
-
359
- if (markers.length > 0) {
360
- // Use markers
361
- for (let i = 0; i < markers.length; i++) {
362
- const marker = markers[i];
363
- if (!marker || !marker[1]) continue;
364
- const file = marker[1];
365
- const start = (marker.index || 0) + marker[0].length;
366
- const end = markers[i + 1]?.index || paperContent.length;
367
-
368
- let content = paperContent.slice(start, end).trim();
369
-
370
- // Remove trailing marker if present
371
- content = content.replace(/<!--\s*@section:\S+\.md\s*-->$/, '').trim();
372
-
373
- result.set(file, content);
374
- }
375
- } else {
376
- // Fall back to header detection
377
- const lines = paperContent.split('\n');
378
- let currentFile: string | null = null;
379
- let currentContent: string[] = [];
380
-
381
- for (const line of lines) {
382
- const headerMatch = line.match(/^#{1,6}\s+(.+)$/);
383
-
384
- if (headerMatch && headerMatch[1]) {
385
- // Save previous section
386
- if (currentFile) {
387
- result.set(currentFile, currentContent.join('\n').trim());
388
- }
389
-
390
- // Find matching section file
391
- const heading = headerMatch[1].trim();
392
- const match = matchHeading(heading, sections);
393
-
394
- if (match) {
395
- currentFile = match.file;
396
- currentContent = [line];
397
- } else {
398
- // Unknown section - keep accumulating to previous
399
- currentContent.push(line);
400
- }
401
- } else {
402
- currentContent.push(line);
403
- }
404
- }
405
-
406
- // Save last section
407
- if (currentFile) {
408
- result.set(currentFile, currentContent.join('\n').trim());
409
- }
410
- }
411
-
412
- return result;
413
- }
414
-
415
- /**
416
- * Get ordered list of section files from config
417
- */
418
- export function getOrderedSections(config: SectionsConfig): string[] {
419
- const entries = Object.entries(config.sections || {});
420
-
421
- return entries
422
- .sort((a, b) => {
423
- const orderA = a[1].order ?? 999;
424
- const orderB = b[1].order ?? 999;
425
- return orderA - orderB;
426
- })
427
- .map(([file]) => file);
428
- }