docrev 0.11.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +2 -0
- package/dist/lib/build.d.ts +52 -0
- package/dist/lib/build.d.ts.map +1 -1
- package/dist/lib/build.js +126 -0
- package/dist/lib/build.js.map +1 -1
- package/dist/lib/commands/build.d.ts.map +1 -1
- package/dist/lib/commands/build.js +34 -12
- package/dist/lib/commands/build.js.map +1 -1
- package/dist/lib/trackchanges.d.ts +41 -25
- package/dist/lib/trackchanges.d.ts.map +1 -1
- package/dist/lib/trackchanges.js +90 -151
- package/dist/lib/trackchanges.js.map +1 -1
- package/dist/lib/types.d.ts +0 -7
- package/dist/lib/types.d.ts.map +1 -1
- package/docs-src/build.py +113 -113
- package/docs-src/extra.css +208 -208
- package/docs-src/md-to-html.lua +6 -6
- package/docs-src/template.html +116 -116
- package/issues.md +180 -0
- package/lib/build.ts +186 -0
- package/lib/commands/build.ts +37 -12
- package/lib/trackchanges.ts +102 -183
- package/lib/types.ts +0 -12
- package/mkdocs.yml +64 -64
- package/package.json +137 -137
- package/site/assets/extra.css +208 -0
- package/site/commands.html +926 -0
- package/site/configuration.html +469 -0
- package/site/index.html +288 -0
- package/site/troubleshooting.html +461 -0
- package/site/workflow.html +518 -0
- package/skill/REFERENCE.md +14 -3
- package/skill/SKILL.md +12 -5
- package/types/index.d.ts +16 -10
package/lib/commands/build.ts
CHANGED
|
@@ -484,8 +484,8 @@ export function register(program: Command, pkg?: { version?: string }): void {
|
|
|
484
484
|
.option('-j, --journal <name>', 'Use journal profile for build formatting defaults')
|
|
485
485
|
.option('--no-crossref', 'Skip pandoc-crossref filter')
|
|
486
486
|
.option('--toc', 'Include table of contents')
|
|
487
|
-
.option('--show-changes', 'Export DOCX with visible track changes
|
|
488
|
-
.option('--dual', 'Output both clean version and annotated version (with comments)')
|
|
487
|
+
.option('--show-changes', 'Export DOCX with visible track changes. Add --dual to thread comments into the same file.')
|
|
488
|
+
.option('--dual', 'Output both clean version and annotated version (with comments). With --show-changes, emits one DOCX with tracked changes AND threaded comments.')
|
|
489
489
|
.option('--reference <docx>', 'Reference DOCX for comment position alignment (use with --dual)')
|
|
490
490
|
.option('--theme <name>', 'Beamer theme (default, metropolis, etc.)')
|
|
491
491
|
.option('--colortheme <name>', 'Beamer color theme')
|
|
@@ -551,8 +551,13 @@ export function register(program: Command, pkg?: { version?: string }): void {
|
|
|
551
551
|
console.log(chalk.dim(` Formats: ${targetFormats.join(', ')}`));
|
|
552
552
|
console.log(chalk.dim(` Crossref: ${hasPandocCrossref() && options.crossref !== false ? 'enabled' : 'disabled'}`));
|
|
553
553
|
if (tocEnabled) console.log(chalk.dim(` TOC: enabled`));
|
|
554
|
-
if (options.showChanges
|
|
555
|
-
|
|
554
|
+
if (options.showChanges && options.dual) {
|
|
555
|
+
console.log(chalk.dim(` Reviewed output: tracked changes + threaded comments (one file)`));
|
|
556
|
+
} else if (options.showChanges) {
|
|
557
|
+
console.log(chalk.dim(` Track changes: visible`));
|
|
558
|
+
} else if (options.dual) {
|
|
559
|
+
console.log(chalk.dim(` Dual output: clean + with comments`));
|
|
560
|
+
}
|
|
556
561
|
console.log('');
|
|
557
562
|
|
|
558
563
|
if (options.toc) {
|
|
@@ -587,8 +592,13 @@ export function register(program: Command, pkg?: { version?: string }): void {
|
|
|
587
592
|
process.exit(1);
|
|
588
593
|
}
|
|
589
594
|
|
|
590
|
-
|
|
591
|
-
|
|
595
|
+
// --show-changes → tracked changes only.
|
|
596
|
+
// --show-changes --dual → tracked changes AND threaded comments in
|
|
597
|
+
// the one file (issue #6). Both write the
|
|
598
|
+
// `<name>-changes.docx` deliverable.
|
|
599
|
+
const includeComments = !!options.dual;
|
|
600
|
+
|
|
601
|
+
const { combineSections, resolveOutputPath, buildReviewedDocx } = await import('../build.js');
|
|
592
602
|
|
|
593
603
|
const spin = fmt.spinner('Building with track changes...').start();
|
|
594
604
|
|
|
@@ -605,21 +615,36 @@ export function register(program: Command, pkg?: { version?: string }): void {
|
|
|
605
615
|
const outDir = path.dirname(outputPath);
|
|
606
616
|
if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true });
|
|
607
617
|
|
|
608
|
-
const spinTc = fmt.spinner(
|
|
609
|
-
|
|
618
|
+
const spinTc = fmt.spinner(
|
|
619
|
+
includeComments ? 'Applying track changes and comments...' : 'Applying track changes...'
|
|
620
|
+
).start();
|
|
621
|
+
const result = await buildReviewedDocx(dir, paperPath, config, {
|
|
622
|
+
outputPath,
|
|
610
623
|
author: getUserName() || 'Author',
|
|
624
|
+
includeComments,
|
|
625
|
+
referencePath: options.reference ? path.resolve(dir, options.reference) : null,
|
|
626
|
+
pandocArgs: options.pandocArg,
|
|
627
|
+
verbose: options.verbose,
|
|
611
628
|
});
|
|
612
629
|
spinTc.stop();
|
|
613
630
|
|
|
614
631
|
if (result.success) {
|
|
615
|
-
|
|
632
|
+
const label = includeComments ? 'track changes + comments' : 'track changes';
|
|
633
|
+
console.log(chalk.cyan(`Output (${label}):`));
|
|
616
634
|
console.log(` DOCX: ${path.basename(outputPath)}`);
|
|
617
|
-
|
|
618
|
-
|
|
635
|
+
console.log(chalk.dim(` ${result.stats.insertions} insertions, ${result.stats.deletions} deletions, ${result.stats.substitutions} substitutions`));
|
|
636
|
+
if (includeComments) {
|
|
637
|
+
console.log(chalk.dim(` ${result.commentCount} comments, ${result.replyCount} replies`));
|
|
638
|
+
if (result.realigned !== undefined) {
|
|
639
|
+
console.log(chalk.dim(` ${result.realigned} comments realigned from reference`));
|
|
640
|
+
}
|
|
641
|
+
if (result.skippedComments > 0) {
|
|
642
|
+
console.log(chalk.yellow(` Warning: ${result.skippedComments} comments could not be anchored`));
|
|
643
|
+
}
|
|
619
644
|
}
|
|
620
645
|
console.log(chalk.green('\nBuild complete!'));
|
|
621
646
|
} else {
|
|
622
|
-
console.error(fmt.status('error', result.
|
|
647
|
+
console.error(fmt.status('error', result.error || 'Build failed'));
|
|
623
648
|
process.exit(1);
|
|
624
649
|
}
|
|
625
650
|
} catch (err) {
|
package/lib/trackchanges.ts
CHANGED
|
@@ -1,247 +1,166 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Track changes module - Apply markdown annotations as Word track changes
|
|
3
3
|
*
|
|
4
|
-
* Converts CriticMarkup
|
|
4
|
+
* Converts CriticMarkup insertions/deletions/substitutions to pandoc-native
|
|
5
|
+
* track-change spans (`[text]{.insertion}` / `[text]{.deletion}`). Pandoc's
|
|
6
|
+
* docx writer emits well-formed `w:ins`/`w:del` run-level revisions from these
|
|
7
|
+
* spans in a single pass, so the output is valid OOXML that Word accepts and
|
|
8
|
+
* that composes with comment injection (see lib/wordcomments.ts).
|
|
5
9
|
*/
|
|
6
10
|
|
|
7
11
|
import * as fs from 'fs';
|
|
8
12
|
import * as path from 'path';
|
|
9
13
|
import { execSync } from 'child_process';
|
|
10
14
|
import AdmZip from 'adm-zip';
|
|
11
|
-
import type { TrackChangeMarker } from './types.js';
|
|
12
|
-
import { escapeXml } from './utils.js';
|
|
13
15
|
|
|
14
|
-
interface
|
|
16
|
+
interface NativeTrackChangeOptions {
|
|
15
17
|
author?: string;
|
|
18
|
+
/** ISO-8601 timestamp for the revisions. Defaults to now (no milliseconds). */
|
|
19
|
+
date?: string;
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
interface
|
|
22
|
+
export interface NativeTrackChangeStats {
|
|
23
|
+
insertions: number;
|
|
24
|
+
deletions: number;
|
|
25
|
+
substitutions: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface ConvertResult {
|
|
19
29
|
text: string;
|
|
20
|
-
|
|
30
|
+
stats: NativeTrackChangeStats;
|
|
21
31
|
}
|
|
22
32
|
|
|
23
33
|
interface ApplyResult {
|
|
24
34
|
success: boolean;
|
|
25
35
|
message: string;
|
|
26
|
-
stats?:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
stats?: NativeTrackChangeStats;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Word/pandoc want revision dates without milliseconds: 2026-07-05T08:33:00Z */
|
|
40
|
+
function isoDateNoMillis(): string {
|
|
41
|
+
return new Date().toISOString().replace(/\.\d{3}Z$/, 'Z');
|
|
31
42
|
}
|
|
32
43
|
|
|
33
44
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* @param text - Text with CriticMarkup annotations
|
|
38
|
-
* @param options - Options
|
|
39
|
-
* @returns Processed text and marker info
|
|
45
|
+
* Escape a value for use inside a pandoc span attribute (`author="..."`).
|
|
46
|
+
* Pandoc attribute values are double-quoted; a literal `"` or `\` would break
|
|
47
|
+
* the attribute, so both are backslash-escaped.
|
|
40
48
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
let markerId = 0;
|
|
49
|
+
function escapeSpanAttr(value: string): string {
|
|
50
|
+
return value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
51
|
+
}
|
|
45
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Convert CriticMarkup insertions/deletions/substitutions to pandoc-native
|
|
55
|
+
* track-change spans. Comments (`{>>...<<}`) and highlights (`{==...==}`) are
|
|
56
|
+
* left untouched — the caller decides how to handle those (strip, or thread
|
|
57
|
+
* them via wordcomments.ts).
|
|
58
|
+
*
|
|
59
|
+
* A single pandoc pass over the result emits valid `w:ins`/`w:del` revisions,
|
|
60
|
+
* so this composes with the full rev filter chain (crossref, citeproc,
|
|
61
|
+
* reference-doc, macros) instead of post-processing document.xml by hand.
|
|
62
|
+
*
|
|
63
|
+
* @param text - Markdown with CriticMarkup annotations
|
|
64
|
+
* @param options - Author/date for the revisions
|
|
65
|
+
* @returns Converted markdown plus per-type counts
|
|
66
|
+
*/
|
|
67
|
+
export function criticToNativeTrackChanges(
|
|
68
|
+
text: string,
|
|
69
|
+
options: NativeTrackChangeOptions = {}
|
|
70
|
+
): ConvertResult {
|
|
71
|
+
const author = escapeSpanAttr(options.author ?? 'Author');
|
|
72
|
+
const date = escapeSpanAttr(options.date ?? isoDateNoMillis());
|
|
73
|
+
const insAttr = `{.insertion author="${author}" date="${date}"}`;
|
|
74
|
+
const delAttr = `{.deletion author="${author}" date="${date}"}`;
|
|
75
|
+
|
|
76
|
+
const stats: NativeTrackChangeStats = { insertions: 0, deletions: 0, substitutions: 0 };
|
|
46
77
|
let result = text;
|
|
47
78
|
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
content,
|
|
55
|
-
author,
|
|
56
|
-
});
|
|
57
|
-
return `{{TC_${id}}}`;
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// Process deletions: {--text--}
|
|
61
|
-
result = result.replace(/\{--(.+?)--\}/gs, (match, content) => {
|
|
62
|
-
const id = markerId++;
|
|
63
|
-
markers.push({
|
|
64
|
-
id,
|
|
65
|
-
type: 'delete',
|
|
66
|
-
content,
|
|
67
|
-
author,
|
|
68
|
-
});
|
|
69
|
-
return `{{TC_${id}}}`;
|
|
79
|
+
// Substitutions first so `{~~old~>new~~}` is consumed before the insertion/
|
|
80
|
+
// deletion passes could see its inner delimiters. Emit delete-then-insert so
|
|
81
|
+
// Word shows the struck-through original followed by the replacement.
|
|
82
|
+
result = result.replace(/\{~~([\s\S]+?)~>([\s\S]+?)~~\}/g, (_m, oldText, newText) => {
|
|
83
|
+
stats.substitutions++;
|
|
84
|
+
return `[${oldText}]${delAttr}[${newText}]${insAttr}`;
|
|
70
85
|
});
|
|
71
86
|
|
|
72
|
-
//
|
|
73
|
-
result = result.replace(/\{
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
id,
|
|
77
|
-
type: 'substitute',
|
|
78
|
-
content: old,
|
|
79
|
-
replacement,
|
|
80
|
-
author,
|
|
81
|
-
});
|
|
82
|
-
return `{{TC_${id}}}`;
|
|
87
|
+
// Insertions: {++text++}
|
|
88
|
+
result = result.replace(/\{\+\+([\s\S]+?)\+\+\}/g, (_m, content) => {
|
|
89
|
+
stats.insertions++;
|
|
90
|
+
return `[${content}]${insAttr}`;
|
|
83
91
|
});
|
|
84
92
|
|
|
85
|
-
//
|
|
86
|
-
result = result.replace(/\{
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const colonIdx = content.indexOf(':');
|
|
90
|
-
let commentAuthor = author;
|
|
91
|
-
let commentText = content;
|
|
92
|
-
if (colonIdx > 0 && colonIdx < 30) {
|
|
93
|
-
commentAuthor = content.slice(0, colonIdx).trim();
|
|
94
|
-
commentText = content.slice(colonIdx + 1).trim();
|
|
95
|
-
}
|
|
96
|
-
markers.push({
|
|
97
|
-
id,
|
|
98
|
-
type: 'comment',
|
|
99
|
-
content: commentText,
|
|
100
|
-
author: commentAuthor,
|
|
101
|
-
});
|
|
102
|
-
return `{{TC_${id}}}`;
|
|
93
|
+
// Deletions: {--text--}
|
|
94
|
+
result = result.replace(/\{--([\s\S]+?)--\}/g, (_m, content) => {
|
|
95
|
+
stats.deletions++;
|
|
96
|
+
return `[${content}]${delAttr}`;
|
|
103
97
|
});
|
|
104
98
|
|
|
105
|
-
return { text: result,
|
|
99
|
+
return { text: result, stats };
|
|
106
100
|
}
|
|
107
101
|
|
|
108
102
|
/**
|
|
109
|
-
*
|
|
103
|
+
* Enable tracked-revision display in a docx's settings.xml (in place).
|
|
110
104
|
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
* @returns Result with success status and message
|
|
105
|
+
* The `w:ins`/`w:del` elements already render as tracked changes without this,
|
|
106
|
+
* but `w:trackRevisions` tells Word to keep tracking the author's further
|
|
107
|
+
* edits — the expected state for a "return to author" review document.
|
|
115
108
|
*/
|
|
116
|
-
export
|
|
117
|
-
docxPath
|
|
118
|
-
markers: TrackChangeMarker[],
|
|
119
|
-
outputPath: string
|
|
120
|
-
): Promise<ApplyResult> {
|
|
121
|
-
if (!fs.existsSync(docxPath)) {
|
|
122
|
-
return { success: false, message: `File not found: ${docxPath}` };
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
let zip: AdmZip;
|
|
126
|
-
try {
|
|
127
|
-
zip = new AdmZip(docxPath);
|
|
128
|
-
} catch (err) {
|
|
129
|
-
const error = err as Error;
|
|
130
|
-
return { success: false, message: `Invalid DOCX file: ${error.message}` };
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Read document.xml
|
|
134
|
-
const docEntry = zip.getEntry('word/document.xml');
|
|
135
|
-
if (!docEntry) {
|
|
136
|
-
return { success: false, message: 'Invalid DOCX: no document.xml' };
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
let documentXml = zip.readAsText(docEntry);
|
|
140
|
-
|
|
141
|
-
// Generate ISO date for track changes
|
|
142
|
-
const now = new Date().toISOString();
|
|
143
|
-
|
|
144
|
-
// Replace markers with track change XML
|
|
145
|
-
for (const marker of markers) {
|
|
146
|
-
const placeholder = `{{TC_${marker.id}}}`;
|
|
147
|
-
let replacement = '';
|
|
148
|
-
|
|
149
|
-
const escapedContent = escapeXml(marker.content);
|
|
150
|
-
const escapedAuthor = escapeXml(marker.author);
|
|
151
|
-
|
|
152
|
-
if (marker.type === 'insert') {
|
|
153
|
-
replacement = `<w:ins w:id="${marker.id}" w:author="${escapedAuthor}" w:date="${now}"><w:r><w:t>${escapedContent}</w:t></w:r></w:ins>`;
|
|
154
|
-
} else if (marker.type === 'delete') {
|
|
155
|
-
replacement = `<w:del w:id="${marker.id}" w:author="${escapedAuthor}" w:date="${now}"><w:r><w:delText>${escapedContent}</w:delText></w:r></w:del>`;
|
|
156
|
-
} else if (marker.type === 'substitute') {
|
|
157
|
-
const escapedReplacement = escapeXml(marker.replacement || '');
|
|
158
|
-
replacement = `<w:del w:id="${marker.id}" w:author="${escapedAuthor}" w:date="${now}"><w:r><w:delText>${escapedContent}</w:delText></w:r></w:del><w:ins w:id="${marker.id + 1000}" w:author="${escapedAuthor}" w:date="${now}"><w:r><w:t>${escapedReplacement}</w:t></w:r></w:ins>`;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
documentXml = documentXml.replace(placeholder, replacement);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Update document.xml
|
|
165
|
-
zip.updateFile('word/document.xml', Buffer.from(documentXml));
|
|
166
|
-
|
|
167
|
-
// Enable track revisions in settings.xml
|
|
109
|
+
export function enableTrackRevisions(docxPath: string): void {
|
|
110
|
+
const zip = new AdmZip(docxPath);
|
|
168
111
|
const settingsEntry = zip.getEntry('word/settings.xml');
|
|
169
|
-
if (settingsEntry)
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
112
|
+
if (!settingsEntry) return;
|
|
113
|
+
let settingsXml = zip.readAsText(settingsEntry);
|
|
114
|
+
if (settingsXml.includes('w:trackRevisions')) return;
|
|
115
|
+
// trackRevisions must appear early in the ordered settings sequence; placing
|
|
116
|
+
// it right after the opening tag keeps Word from rejecting the schema order.
|
|
117
|
+
settingsXml = settingsXml.replace(/(<w:settings[^>]*>)/, '$1<w:trackRevisions/>');
|
|
118
|
+
if (!settingsXml.includes('<w:trackRevisions/>')) {
|
|
119
|
+
// No opening tag matched (unexpected) — fall back to before the close tag.
|
|
120
|
+
settingsXml = settingsXml.replace('</w:settings>', '<w:trackRevisions/></w:settings>');
|
|
178
121
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
zip.writeZip(outputPath);
|
|
182
|
-
|
|
183
|
-
return { success: true, message: `Created ${outputPath} with track changes` };
|
|
122
|
+
zip.updateFile('word/settings.xml', Buffer.from(settingsXml, 'utf-8'));
|
|
123
|
+
zip.writeZip(docxPath);
|
|
184
124
|
}
|
|
185
125
|
|
|
186
126
|
/**
|
|
187
|
-
* Build a Word document with track changes from annotated markdown
|
|
127
|
+
* Build a standalone Word document with track changes from annotated markdown.
|
|
128
|
+
*
|
|
129
|
+
* Used by `rev apply <md> <docx>` for a single markdown file outside a rev
|
|
130
|
+
* project (no crossref/citeproc/reference-doc). Comments are dropped — use the
|
|
131
|
+
* project build (`rev build docx --show-changes`) for the full filter chain and
|
|
132
|
+
* threaded comments.
|
|
188
133
|
*
|
|
189
134
|
* @param mdPath - Path to markdown file with CriticMarkup
|
|
190
135
|
* @param docxPath - Output path for Word document
|
|
191
|
-
* @param options -
|
|
136
|
+
* @param options - Author name for the revisions
|
|
192
137
|
* @returns Result with success status and message
|
|
193
138
|
*/
|
|
194
139
|
export async function buildWithTrackChanges(
|
|
195
140
|
mdPath: string,
|
|
196
141
|
docxPath: string,
|
|
197
|
-
options:
|
|
142
|
+
options: NativeTrackChangeOptions = {}
|
|
198
143
|
): Promise<ApplyResult> {
|
|
199
|
-
const { author = 'Author' } = options;
|
|
200
|
-
|
|
201
144
|
if (!fs.existsSync(mdPath)) {
|
|
202
145
|
return { success: false, message: `File not found: ${mdPath}` };
|
|
203
146
|
}
|
|
204
147
|
|
|
148
|
+
const { author = 'Author' } = options;
|
|
205
149
|
const content = fs.readFileSync(mdPath, 'utf-8');
|
|
150
|
+
const { text: converted, stats } = criticToNativeTrackChanges(content, { author });
|
|
206
151
|
|
|
207
|
-
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
// If no annotations, just build normally
|
|
211
|
-
if (markers.length === 0) {
|
|
212
|
-
try {
|
|
213
|
-
execSync(`pandoc "${mdPath}" -o "${docxPath}"`, { encoding: 'utf-8' });
|
|
214
|
-
return { success: true, message: `Created ${docxPath}` };
|
|
215
|
-
} catch (err) {
|
|
216
|
-
const error = err as Error;
|
|
217
|
-
return { success: false, message: error.message };
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Write prepared content to temp file
|
|
222
|
-
const tempDir = path.dirname(mdPath);
|
|
223
|
-
const tempMd = path.join(tempDir, `.temp-${Date.now()}.md`);
|
|
224
|
-
const tempDocx = path.join(tempDir, `.temp-${Date.now()}.docx`);
|
|
152
|
+
const total = stats.insertions + stats.deletions + stats.substitutions;
|
|
153
|
+
const tempMd = path.join(path.dirname(mdPath), `.temp-tc-${process.pid}.md`);
|
|
225
154
|
|
|
226
155
|
try {
|
|
227
|
-
fs.writeFileSync(tempMd,
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
// Apply track changes
|
|
233
|
-
const result = await applyTrackChangesToDocx(tempDocx, markers, docxPath);
|
|
234
|
-
|
|
235
|
-
// Clean up temp files
|
|
236
|
-
fs.unlinkSync(tempMd);
|
|
237
|
-
fs.unlinkSync(tempDocx);
|
|
238
|
-
|
|
239
|
-
return result;
|
|
156
|
+
fs.writeFileSync(tempMd, converted, 'utf-8');
|
|
157
|
+
execSync(`pandoc "${tempMd}" -o "${docxPath}"`, { encoding: 'utf-8' });
|
|
158
|
+
if (total > 0) enableTrackRevisions(docxPath);
|
|
159
|
+
return { success: true, message: `Created ${docxPath} with track changes`, stats };
|
|
240
160
|
} catch (err) {
|
|
241
|
-
// Clean up on error
|
|
242
|
-
if (fs.existsSync(tempMd)) fs.unlinkSync(tempMd);
|
|
243
|
-
if (fs.existsSync(tempDocx)) fs.unlinkSync(tempDocx);
|
|
244
161
|
const error = err as Error;
|
|
245
162
|
return { success: false, message: error.message };
|
|
163
|
+
} finally {
|
|
164
|
+
try { fs.unlinkSync(tempMd); } catch { /* best-effort cleanup */ }
|
|
246
165
|
}
|
|
247
166
|
}
|
package/lib/types.ts
CHANGED
|
@@ -489,18 +489,6 @@ export interface TrackChangesResult {
|
|
|
489
489
|
stats: { insertions: number; deletions: number };
|
|
490
490
|
}
|
|
491
491
|
|
|
492
|
-
// ============================================
|
|
493
|
-
// TrackChanges
|
|
494
|
-
// ============================================
|
|
495
|
-
|
|
496
|
-
export interface TrackChangeMarker {
|
|
497
|
-
id: number;
|
|
498
|
-
type: 'insert' | 'delete' | 'substitute' | 'comment';
|
|
499
|
-
content: string;
|
|
500
|
-
author: string;
|
|
501
|
-
replacement?: string;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
492
|
// ============================================
|
|
505
493
|
// Spelling
|
|
506
494
|
// ============================================
|
package/mkdocs.yml
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
site_name: docrev
|
|
2
|
-
site_url: https://gillescolling.com/docrev
|
|
3
|
-
site_description: CLI for writing documents in Markdown while collaborating with Word users.
|
|
4
|
-
site_author: Gilles Colling
|
|
5
|
-
repo_url: https://github.com/gcol33/docrev
|
|
6
|
-
repo_name: gcol33/docrev
|
|
7
|
-
|
|
8
|
-
theme:
|
|
9
|
-
name: material
|
|
10
|
-
palette:
|
|
11
|
-
- scheme: default
|
|
12
|
-
primary: custom
|
|
13
|
-
accent: custom
|
|
14
|
-
toggle:
|
|
15
|
-
icon: material/brightness-7
|
|
16
|
-
name: Switch to dark mode
|
|
17
|
-
- scheme: slate
|
|
18
|
-
primary: custom
|
|
19
|
-
accent: custom
|
|
20
|
-
toggle:
|
|
21
|
-
icon: material/brightness-4
|
|
22
|
-
name: Switch to light mode
|
|
23
|
-
font:
|
|
24
|
-
text: Roboto
|
|
25
|
-
code: Roboto Mono
|
|
26
|
-
features:
|
|
27
|
-
- navigation.tabs
|
|
28
|
-
- navigation.top
|
|
29
|
-
- navigation.instant
|
|
30
|
-
- search.highlight
|
|
31
|
-
- content.code.copy
|
|
32
|
-
icon:
|
|
33
|
-
repo: fontawesome/brands/github
|
|
34
|
-
|
|
35
|
-
nav:
|
|
36
|
-
- Home: index.md
|
|
37
|
-
- Get Started: workflow.md
|
|
38
|
-
- Commands: commands.md
|
|
39
|
-
- Configuration: configuration.md
|
|
40
|
-
- Troubleshooting: troubleshooting.md
|
|
41
|
-
|
|
42
|
-
markdown_extensions:
|
|
43
|
-
- pymdownx.highlight:
|
|
44
|
-
anchor_linenums: true
|
|
45
|
-
- pymdownx.superfences
|
|
46
|
-
- pymdownx.inlinehilite
|
|
47
|
-
- pymdownx.tabbed:
|
|
48
|
-
alternate_style: true
|
|
49
|
-
- admonition
|
|
50
|
-
- pymdownx.details
|
|
51
|
-
- attr_list
|
|
52
|
-
- md_in_html
|
|
53
|
-
- toc:
|
|
54
|
-
permalink: true
|
|
55
|
-
|
|
56
|
-
extra_css:
|
|
57
|
-
- stylesheets/extra.css
|
|
58
|
-
|
|
59
|
-
extra:
|
|
60
|
-
social:
|
|
61
|
-
- icon: fontawesome/brands/github
|
|
62
|
-
link: https://github.com/gcol33/docrev
|
|
63
|
-
- icon: fontawesome/brands/npm
|
|
64
|
-
link: https://www.npmjs.com/package/docrev
|
|
1
|
+
site_name: docrev
|
|
2
|
+
site_url: https://gillescolling.com/docrev
|
|
3
|
+
site_description: CLI for writing documents in Markdown while collaborating with Word users.
|
|
4
|
+
site_author: Gilles Colling
|
|
5
|
+
repo_url: https://github.com/gcol33/docrev
|
|
6
|
+
repo_name: gcol33/docrev
|
|
7
|
+
|
|
8
|
+
theme:
|
|
9
|
+
name: material
|
|
10
|
+
palette:
|
|
11
|
+
- scheme: default
|
|
12
|
+
primary: custom
|
|
13
|
+
accent: custom
|
|
14
|
+
toggle:
|
|
15
|
+
icon: material/brightness-7
|
|
16
|
+
name: Switch to dark mode
|
|
17
|
+
- scheme: slate
|
|
18
|
+
primary: custom
|
|
19
|
+
accent: custom
|
|
20
|
+
toggle:
|
|
21
|
+
icon: material/brightness-4
|
|
22
|
+
name: Switch to light mode
|
|
23
|
+
font:
|
|
24
|
+
text: Roboto
|
|
25
|
+
code: Roboto Mono
|
|
26
|
+
features:
|
|
27
|
+
- navigation.tabs
|
|
28
|
+
- navigation.top
|
|
29
|
+
- navigation.instant
|
|
30
|
+
- search.highlight
|
|
31
|
+
- content.code.copy
|
|
32
|
+
icon:
|
|
33
|
+
repo: fontawesome/brands/github
|
|
34
|
+
|
|
35
|
+
nav:
|
|
36
|
+
- Home: index.md
|
|
37
|
+
- Get Started: workflow.md
|
|
38
|
+
- Commands: commands.md
|
|
39
|
+
- Configuration: configuration.md
|
|
40
|
+
- Troubleshooting: troubleshooting.md
|
|
41
|
+
|
|
42
|
+
markdown_extensions:
|
|
43
|
+
- pymdownx.highlight:
|
|
44
|
+
anchor_linenums: true
|
|
45
|
+
- pymdownx.superfences
|
|
46
|
+
- pymdownx.inlinehilite
|
|
47
|
+
- pymdownx.tabbed:
|
|
48
|
+
alternate_style: true
|
|
49
|
+
- admonition
|
|
50
|
+
- pymdownx.details
|
|
51
|
+
- attr_list
|
|
52
|
+
- md_in_html
|
|
53
|
+
- toc:
|
|
54
|
+
permalink: true
|
|
55
|
+
|
|
56
|
+
extra_css:
|
|
57
|
+
- stylesheets/extra.css
|
|
58
|
+
|
|
59
|
+
extra:
|
|
60
|
+
social:
|
|
61
|
+
- icon: fontawesome/brands/github
|
|
62
|
+
link: https://github.com/gcol33/docrev
|
|
63
|
+
- icon: fontawesome/brands/npm
|
|
64
|
+
link: https://www.npmjs.com/package/docrev
|