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.
@@ -1,116 +1,116 @@
1
- <!DOCTYPE html>
2
- <html lang="en" data-bs-theme="light">
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <title>$if(pagetitle)$$pagetitle$ — $endif$docrev</title>
7
- <meta name="description" content="CLI for writing documents in Markdown while collaborating with Word users.">
8
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootswatch@5.3.3/dist/sandstone/bootstrap.min.css">
9
- $if(highlighting-css)$
10
- <style>
11
- $highlighting-css$
12
- </style>
13
- $endif$
14
- <link rel="stylesheet" href="assets/extra.css">
15
- </head>
16
- <body>
17
-
18
- <nav class="navbar navbar-expand-lg fixed-top" aria-label="Site navigation">
19
- <div class="container">
20
- <a class="navbar-brand me-2" href="index.html">docrev</a>
21
- <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar-main" aria-controls="navbar-main" aria-expanded="false" aria-label="Toggle navigation">
22
- <span class="navbar-toggler-icon"></span>
23
- </button>
24
- <div class="collapse navbar-collapse" id="navbar-main">
25
- <ul class="navbar-nav me-auto">
26
- <li class="nav-item">
27
- <a class="nav-link$if(active-home)$ active$endif$" $if(active-home)$aria-current="page"$endif$ href="index.html">Home</a>
28
- </li>
29
- <li class="nav-item">
30
- <a class="nav-link$if(active-workflow)$ active$endif$" $if(active-workflow)$aria-current="page"$endif$ href="workflow.html">Get Started</a>
31
- </li>
32
- <li class="nav-item">
33
- <a class="nav-link$if(active-commands)$ active$endif$" $if(active-commands)$aria-current="page"$endif$ href="commands.html">Commands</a>
34
- </li>
35
- <li class="nav-item">
36
- <a class="nav-link$if(active-configuration)$ active$endif$" $if(active-configuration)$aria-current="page"$endif$ href="configuration.html">Configuration</a>
37
- </li>
38
- <li class="nav-item">
39
- <a class="nav-link$if(active-troubleshooting)$ active$endif$" $if(active-troubleshooting)$aria-current="page"$endif$ href="troubleshooting.html">Troubleshooting</a>
40
- </li>
41
- </ul>
42
- <ul class="navbar-nav">
43
- <li class="nav-item">
44
- <button id="theme-toggle" class="btn btn-link nav-link border-0" aria-label="Toggle dark mode">
45
- <svg id="icon-sun" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
46
- <path d="M8 11a3 3 0 1 1 0-6 3 3 0 0 1 0 6m0 1a4 4 0 1 0 0-8 4 4 0 0 0 0 8M8 0a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 0m0 13a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 13m8-5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2a.5.5 0 0 1 .5.5M3 8a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2A.5.5 0 0 1 3 8m10.657-5.657a.5.5 0 0 1 0 .707l-1.414 1.415a.5.5 0 1 1-.707-.708l1.414-1.414a.5.5 0 0 1 .707 0m-9.193 9.193a.5.5 0 0 1 0 .707L3.05 13.657a.5.5 0 0 1-.707-.707l1.414-1.414a.5.5 0 0 1 .707 0m9.193 2.121a.5.5 0 0 1-.707 0l-1.414-1.414a.5.5 0 0 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .707M4.464 4.465a.5.5 0 0 1-.707 0L2.343 3.05a.5.5 0 1 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .707"/>
47
- </svg>
48
- <svg id="icon-moon" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16" style="display:none">
49
- <path d="M6 .278a.768.768 0 0 1 .08.858 7.208 7.208 0 0 0-.878 3.46c0 4.021 3.278 7.277 7.318 7.277.527 0 1.04-.055 1.533-.16a.787.787 0 0 1 .81.316.733.733 0 0 1-.031.893A8.349 8.349 0 0 1 8.344 16C3.734 16 0 12.286 0 7.71 0 4.266 2.114 1.312 5.124.06A.752.752 0 0 1 6 .278"/>
50
- </svg>
51
- </button>
52
- </li>
53
- <li class="nav-item">
54
- <a class="nav-link" href="https://github.com/gcol33/docrev" aria-label="GitHub">
55
- <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 16 16">
56
- <path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8"/>
57
- </svg>
58
- </a>
59
- </li>
60
- <li class="nav-item">
61
- <a class="nav-link" href="https://www.npmjs.com/package/docrev" aria-label="npm">
62
- <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16">
63
- <path d="M0 0v16h16V0zm5.333 13.333H2.667V5.333h2.666v5.334H8V5.333h2.667v8H5.333z"/>
64
- </svg>
65
- </a>
66
- </li>
67
- </ul>
68
- </div>
69
- </div>
70
- </nav>
71
-
72
- <div class="container template-$if(active-home)$home$else$article$endif$">
73
- <div class="row">
74
- <main id="main" class="$if(toc)$col-md-9$else$col-12$endif$">
75
- $body$
76
- </main>
77
- $if(toc)$
78
- <aside class="col-md-3 d-none d-md-block">
79
- <nav id="toc" data-toggle="toc" aria-label="On this page">
80
- <h2 class="h6">On this page</h2>
81
- <div class="toc">$toc$</div>
82
- </nav>
83
- </aside>
84
- $endif$
85
- </div>
86
- </div>
87
-
88
- <footer class="border-top py-3 mt-auto">
89
- <div class="container d-flex justify-content-between align-items-center text-muted" style="font-size:.85rem">
90
- <span>docrev$if(version)$ $version$$endif$</span>
91
- <span>Built with <a href="https://pandoc.org" class="text-muted">pandoc</a></span>
92
- </div>
93
- </footer>
94
-
95
- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
96
- <script>
97
- (function () {
98
- var html = document.documentElement;
99
- var sun = document.getElementById('icon-sun');
100
- var moon = document.getElementById('icon-moon');
101
- function apply(t) {
102
- html.setAttribute('data-bs-theme', t);
103
- sun.style.display = t === 'dark' ? 'none' : '';
104
- moon.style.display = t === 'dark' ? '' : 'none';
105
- }
106
- apply(localStorage.getItem('docrev-theme') || 'light');
107
- document.getElementById('theme-toggle').addEventListener('click', function () {
108
- var next = html.getAttribute('data-bs-theme') === 'dark' ? 'light' : 'dark';
109
- localStorage.setItem('docrev-theme', next);
110
- apply(next);
111
- });
112
- })();
113
- </script>
114
-
115
- </body>
116
- </html>
1
+ <!DOCTYPE html>
2
+ <html lang="en" data-bs-theme="light">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>$if(pagetitle)$$pagetitle$ — $endif$docrev</title>
7
+ <meta name="description" content="CLI for writing documents in Markdown while collaborating with Word users.">
8
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootswatch@5.3.3/dist/sandstone/bootstrap.min.css">
9
+ $if(highlighting-css)$
10
+ <style>
11
+ $highlighting-css$
12
+ </style>
13
+ $endif$
14
+ <link rel="stylesheet" href="assets/extra.css">
15
+ </head>
16
+ <body>
17
+
18
+ <nav class="navbar navbar-expand-lg fixed-top" aria-label="Site navigation">
19
+ <div class="container">
20
+ <a class="navbar-brand me-2" href="index.html">docrev</a>
21
+ <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar-main" aria-controls="navbar-main" aria-expanded="false" aria-label="Toggle navigation">
22
+ <span class="navbar-toggler-icon"></span>
23
+ </button>
24
+ <div class="collapse navbar-collapse" id="navbar-main">
25
+ <ul class="navbar-nav me-auto">
26
+ <li class="nav-item">
27
+ <a class="nav-link$if(active-home)$ active$endif$" $if(active-home)$aria-current="page"$endif$ href="index.html">Home</a>
28
+ </li>
29
+ <li class="nav-item">
30
+ <a class="nav-link$if(active-workflow)$ active$endif$" $if(active-workflow)$aria-current="page"$endif$ href="workflow.html">Get Started</a>
31
+ </li>
32
+ <li class="nav-item">
33
+ <a class="nav-link$if(active-commands)$ active$endif$" $if(active-commands)$aria-current="page"$endif$ href="commands.html">Commands</a>
34
+ </li>
35
+ <li class="nav-item">
36
+ <a class="nav-link$if(active-configuration)$ active$endif$" $if(active-configuration)$aria-current="page"$endif$ href="configuration.html">Configuration</a>
37
+ </li>
38
+ <li class="nav-item">
39
+ <a class="nav-link$if(active-troubleshooting)$ active$endif$" $if(active-troubleshooting)$aria-current="page"$endif$ href="troubleshooting.html">Troubleshooting</a>
40
+ </li>
41
+ </ul>
42
+ <ul class="navbar-nav">
43
+ <li class="nav-item">
44
+ <button id="theme-toggle" class="btn btn-link nav-link border-0" aria-label="Toggle dark mode">
45
+ <svg id="icon-sun" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
46
+ <path d="M8 11a3 3 0 1 1 0-6 3 3 0 0 1 0 6m0 1a4 4 0 1 0 0-8 4 4 0 0 0 0 8M8 0a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 0m0 13a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 13m8-5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2a.5.5 0 0 1 .5.5M3 8a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2A.5.5 0 0 1 3 8m10.657-5.657a.5.5 0 0 1 0 .707l-1.414 1.415a.5.5 0 1 1-.707-.708l1.414-1.414a.5.5 0 0 1 .707 0m-9.193 9.193a.5.5 0 0 1 0 .707L3.05 13.657a.5.5 0 0 1-.707-.707l1.414-1.414a.5.5 0 0 1 .707 0m9.193 2.121a.5.5 0 0 1-.707 0l-1.414-1.414a.5.5 0 0 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .707M4.464 4.465a.5.5 0 0 1-.707 0L2.343 3.05a.5.5 0 1 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .707"/>
47
+ </svg>
48
+ <svg id="icon-moon" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16" style="display:none">
49
+ <path d="M6 .278a.768.768 0 0 1 .08.858 7.208 7.208 0 0 0-.878 3.46c0 4.021 3.278 7.277 7.318 7.277.527 0 1.04-.055 1.533-.16a.787.787 0 0 1 .81.316.733.733 0 0 1-.031.893A8.349 8.349 0 0 1 8.344 16C3.734 16 0 12.286 0 7.71 0 4.266 2.114 1.312 5.124.06A.752.752 0 0 1 6 .278"/>
50
+ </svg>
51
+ </button>
52
+ </li>
53
+ <li class="nav-item">
54
+ <a class="nav-link" href="https://github.com/gcol33/docrev" aria-label="GitHub">
55
+ <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" viewBox="0 0 16 16">
56
+ <path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8"/>
57
+ </svg>
58
+ </a>
59
+ </li>
60
+ <li class="nav-item">
61
+ <a class="nav-link" href="https://www.npmjs.com/package/docrev" aria-label="npm">
62
+ <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16">
63
+ <path d="M0 0v16h16V0zm5.333 13.333H2.667V5.333h2.666v5.334H8V5.333h2.667v8H5.333z"/>
64
+ </svg>
65
+ </a>
66
+ </li>
67
+ </ul>
68
+ </div>
69
+ </div>
70
+ </nav>
71
+
72
+ <div class="container template-$if(active-home)$home$else$article$endif$">
73
+ <div class="row">
74
+ <main id="main" class="$if(toc)$col-md-9$else$col-12$endif$">
75
+ $body$
76
+ </main>
77
+ $if(toc)$
78
+ <aside class="col-md-3 d-none d-md-block">
79
+ <nav id="toc" data-toggle="toc" aria-label="On this page">
80
+ <h2 class="h6">On this page</h2>
81
+ <div class="toc">$toc$</div>
82
+ </nav>
83
+ </aside>
84
+ $endif$
85
+ </div>
86
+ </div>
87
+
88
+ <footer class="border-top py-3 mt-auto">
89
+ <div class="container d-flex justify-content-between align-items-center text-muted" style="font-size:.85rem">
90
+ <span>docrev$if(version)$ $version$$endif$</span>
91
+ <span>Built with <a href="https://pandoc.org" class="text-muted">pandoc</a></span>
92
+ </div>
93
+ </footer>
94
+
95
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
96
+ <script>
97
+ (function () {
98
+ var html = document.documentElement;
99
+ var sun = document.getElementById('icon-sun');
100
+ var moon = document.getElementById('icon-moon');
101
+ function apply(t) {
102
+ html.setAttribute('data-bs-theme', t);
103
+ sun.style.display = t === 'dark' ? 'none' : '';
104
+ moon.style.display = t === 'dark' ? '' : 'none';
105
+ }
106
+ apply(localStorage.getItem('docrev-theme') || 'light');
107
+ document.getElementById('theme-toggle').addEventListener('click', function () {
108
+ var next = html.getAttribute('data-bs-theme') === 'dark' ? 'light' : 'dark';
109
+ localStorage.setItem('docrev-theme', next);
110
+ apply(next);
111
+ });
112
+ })();
113
+ </script>
114
+
115
+ </body>
116
+ </html>
package/issues.md ADDED
@@ -0,0 +1,180 @@
1
+ # docrev — Open Issues
2
+
3
+ Three issues identified during real-world use on the ADAPT proposal build. Working through one by one.
4
+
5
+ Status legend: `[ ]` planned · `[~]` in progress · `[x]` shipped
6
+
7
+ ---
8
+
9
+ ## Issue 1 — Allow custom pandoc filters / args through `rev build` `[x]`
10
+
11
+ ### Problem
12
+
13
+ Source markdown with custom raw-LaTeX commands needs a pandoc filter to convert them for docx (e.g. `\tofill{X}` → bold `[X]`). `rev build docx` has no escape hatch:
14
+
15
+ - `rev build --help` exposes no `--filter` / `--lua-filter` / `--pandoc-arg`.
16
+ - `rev.yaml` exposes `docx.reference` and `docx.keepComments` but no generic pandoc passthrough.
17
+
18
+ Working around it requires letting `rev build` produce `paper.md` as a side effect, then calling pandoc manually — which defeats the point of `rev build`.
19
+
20
+ ### Design (agreed)
21
+
22
+ **rev.yaml**: top-level `pandoc-args` (applied to every format) plus per-format `<format>.pandoc-args` (concatenated *after* the top-level list so format-specific can override):
23
+
24
+ ```yaml
25
+ pandoc-args:
26
+ - --lua-filter=tofill_filter.lua
27
+ docx:
28
+ pandoc-args:
29
+ - --lua-filter=docx_only.lua
30
+ pdf:
31
+ pandoc-args:
32
+ - --variable=papersize:a4
33
+ ```
34
+
35
+ **CLI**: repeatable `--pandoc-arg <arg>` on `rev build`, appended *after* config args so CLI wins:
36
+
37
+ ```bash
38
+ rev build docx --pandoc-arg=--lua-filter=tofill.lua --pandoc-arg=--shift-heading-level-by=1
39
+ ```
40
+
41
+ **Verbose mode**: `rev build --verbose` already exists but doesn't echo the pandoc invocation. Print the full `pandoc <args>` command (one line per format) so users can copy-paste to replicate manually.
42
+
43
+ ### Touch points
44
+
45
+ - `lib/build.ts` — `BuildConfig` + `DEFAULT_CONFIG` (add `pandocArgs: string[]`; add `pandocArgs` to each format config), `buildPandocArgs()` (append top-level then format-specific), `runPandoc()` (echo command under verbose), `loadConfig()` (read hyphenated `pandoc-args` key and map to camelCase `pandocArgs`).
46
+ - `lib/commands/build.ts` — add `--pandoc-arg <arg>` (repeatable via custom collector), forward through `BuildOptions`, ensure CLI args are appended last.
47
+ - `lib/schema.ts` — declare `pandoc-args` (array of strings) at top level and inside each format object.
48
+ - `skill/SKILL.md` + `skill/REFERENCE.md` — document new field and flag with a `--lua-filter=` example.
49
+ - `test/build.test.js` — cover (a) top-level only, (b) format-specific only, (c) both concatenated in order, (d) CLI overrides config.
50
+
51
+ ### Open questions
52
+
53
+ None. Hyphenated YAML key + camelCase TS field is consistent with how the rest of the schema is read (we're already free-form on the JS side, just need a small key transform in `loadConfig`).
54
+
55
+ ---
56
+
57
+ ## Issue 2 — Output filename is auto-truncated mid-word and not configurable `[x]`
58
+
59
+ ### Problem
60
+
61
+ Default output landed at `output/adapt-alien-dark-diversity-across-plant-communitie.docx` — title slugified and hard-truncated at 50 chars (`communitie` missing the trailing `s`). No `-o` flag, no `output:` field in `rev.yaml`.
62
+
63
+ Root cause: `lib/build.ts:1055-1056` (`runPandoc`) and `lib/commands/build.ts:591-592` (`--show-changes` path):
64
+
65
+ ```ts
66
+ const baseName = config.title
67
+ ? config.title.toLowerCase().replace(/[^a-z0-9]+/g, '-').slice(0, 50)
68
+ : 'paper';
69
+ ```
70
+
71
+ `.slice(0, 50)` is a blind cut.
72
+
73
+ ### Design (agreed)
74
+
75
+ **rev.yaml**: per-format `output:` map. Extensions optional — added if missing.
76
+
77
+ ```yaml
78
+ output:
79
+ docx: ADAPT_proposal_draft.docx
80
+ pdf: ADAPT_proposal_draft.pdf
81
+ ```
82
+
83
+ **CLI**: `-o, --output <path>` on `rev build`. When multiple formats are built, applies as basename to all (extension swapped per format); for single-format builds, used verbatim.
84
+
85
+ **Truncation fix**: when no `output:` is configured, slug at last `-` boundary at-or-before 50 chars instead of mid-word. Also bump the cap to 80 — 50 is conservative.
86
+
87
+ **Doc fix**: surface the default `output/` directory in `rev build --help` and SKILL.md "Project Structure" tree (already mentioned in passing — make it explicit).
88
+
89
+ ### Touch points
90
+
91
+ - `lib/build.ts` — `BuildConfig` (`output?: Record<string, string>`), `DEFAULT_CONFIG`, `runPandoc()` (resolve filename: `config.output[format]` → CLI `-o` → slug). Helper: `resolveOutputName(config, format, cliOverride)`.
92
+ - `lib/commands/build.ts` — add `-o, --output <path>` flag, wire into `BuildOptions`; same fix applied to the `--show-changes` branch's `baseName` construction.
93
+ - `lib/schema.ts` — declare `output` as object mapping format → string.
94
+ - `skill/SKILL.md` — "Project Structure" tree explicitly notes `output/`; new `output:` example under config.
95
+ - `test/build.test.js` — cover (a) `output:` per-format honored, (b) `-o` CLI override, (c) word-boundary truncation when title >50 chars.
96
+
97
+ ### Resolved
98
+
99
+ - `-o` relative paths resolve under `outputDir`; absolute paths bypass it. Same rule applies to values in `output:`.
100
+ - Cap raised from 50 → 80 chars; fallback truncates at the last `-` boundary at-or-before the cap so words stay whole (the ADAPT title now slugs cleanly without losing the trailing "s" on "communities").
101
+ - `--show-changes` and `--dual` derived filenames (`-changes.docx`, `_comments.docx`, `_comments.pdf`) follow the chosen base name.
102
+ - Fixed an unrelated misleading example in SKILL.md that showed `output: { docx: { reference-doc: ... } }` — the real config key is `docx.reference` (top-level), not nested under `output:`.
103
+
104
+ ---
105
+
106
+ ## Issue 3 — Raw LaTeX figure blocks silently disappear in docx builds `[x]`
107
+
108
+ ### Problem
109
+
110
+ Source markdown with `\begin{figure}[H]\includegraphics{...}\end{figure}` blocks renders correctly in the PDF target but produces a docx where all figures are silently missing. Pandoc strips the raw LaTeX because docx has no LaTeX rendering pipeline. No warning is emitted.
111
+
112
+ This catches you only on careful inspection — a less careful user would ship a docx with no figures and not notice until a reviewer asks.
113
+
114
+ ### Design (agreed)
115
+
116
+ Three layers, combined:
117
+
118
+ **1. Warn during build (always on).** In `applyFormatTransforms()` for docx, scan for raw LaTeX figure environments (`\begin{figure}` … `\end{figure}` containing `\includegraphics`). Emit:
119
+
120
+ ```
121
+ Warning: 3 raw LaTeX figure block(s) won't render in docx.
122
+ intro.md:42 \begin{figure}[H] ... \includegraphics{figures/map.pdf} ...
123
+ methods.md:118
124
+ results.md:201
125
+ Hint: use ![caption](path){#fig:label width=80%} for format-portable figures, or
126
+ pass --pandoc-arg=--lua-filter=<your.lua> to translate them yourself.
127
+ ```
128
+
129
+ Counted by file/line so the user can jump to fix.
130
+
131
+ **2. Auto-translate the common shape (opt-out via `docx.translateRawFigures: false`).** Convert
132
+
133
+ ```latex
134
+ \begin{figure}[H]
135
+ \centering
136
+ \includegraphics[width=0.8\textwidth]{figures/map.pdf}
137
+ \caption{Map of study sites.}
138
+ \label{fig:map}
139
+ \end{figure}
140
+ ```
141
+
142
+
143
+
144
+ ```markdown
145
+ ![Map of study sites.](figures/map.pdf){#fig:map width=80%}
146
+ ```
147
+
148
+ Cover the 80% case. If the block has anything more exotic (`\subfloat`, `\rotatebox`, multi-`\includegraphics`), skip auto-translate, warn loudly, and leave the block as-is.
149
+
150
+ Width conversion: `0.8\textwidth` → `80%`; bare `8cm` → `8cm`; missing → omit.
151
+
152
+ **3. Document.** SKILL.md "Cross-References" section currently mentions `@fig:label` and `{#fig:label}` but doesn't show how to *insert* a figure. Add:
153
+
154
+ ```markdown
155
+ ![Caption text.](figures/foo.pdf){#fig:foo width=80%}
156
+ ```
157
+
158
+ Note this is the format-portable form. Also mention that raw `\begin{figure}` blocks are PDF-only.
159
+
160
+ ### Touch points
161
+
162
+ - `lib/build.ts` — new helper `detectRawLatexFigures(content): {file?, line, block}[]` and `translateRawLatexFigures(content): {translated, untranslatedCount}`. Wire into `applyFormatTransforms()` for docx (after `convertDynamicRefsToDisplay`).
163
+ - `lib/build.ts` — propagate warnings up via the existing `warnings: string[]` returned by `build()`. `rev build` already prints from there.
164
+ - `lib/commands/build.ts` — surface warnings in normal output (not just verbose).
165
+ - `lib/schema.ts` — declare `docx.translateRawFigures: boolean` (default true).
166
+ - `skill/SKILL.md` — figure-insertion example under "Cross-References".
167
+ - `test/build.test.js` — cover (a) detection counts blocks correctly, (b) auto-translate of `\includegraphics{path}`, (c) auto-translate of `\includegraphics[width=0.8\textwidth]{path}` → `width=80%`, (d) exotic block → not translated, warned, left alone, (e) opt-out via `translateRawFigures: false`.
168
+
169
+ ### Open questions
170
+
171
+ - Should auto-translate also handle bare `\includegraphics{...}` outside a `figure` env? Lean no — keep scope to figure environments. If a user writes raw `\includegraphics` without wrapping, that's a deliberate choice we shouldn't second-guess.
172
+ - Width unit handling: `0.8\textwidth` → `80%` is unambiguous. `\linewidth` → `100%`? Yes. Other relative units → leave raw and warn.
173
+
174
+ ---
175
+
176
+ ## Working order
177
+
178
+ 1. **Issue 1** first — unblocks immediate workflow needs and provides the manual escape hatch for issue 3 even before auto-translate ships.
179
+ 2. **Issue 2** next — small, low-risk, quality-of-life win.
180
+ 3. **Issue 3** last — biggest behavior change; benefits from the verbose pandoc echo (Issue 1) for debugging the lua-filter fallback path.
package/lib/build.ts CHANGED
@@ -14,6 +14,8 @@ import { fileURLToPath } from 'url';
14
14
  import { execSync, spawn, ChildProcess } from 'child_process';
15
15
  import YAML from 'yaml';
16
16
  import { stripAnnotations } from './annotations.js';
17
+ import { criticToNativeTrackChanges, enableTrackRevisions, type NativeTrackChangeStats } from './trackchanges.js';
18
+ import { prepareMarkdownWithMarkers, injectCommentsAtMarkers } from './wordcomments.js';
17
19
  import { buildRegistry, labelToDisplay, detectDynamicRefs, resolveForwardRefs, resolveSupplementaryRefs } from './crossref.js';
18
20
  import { processVariables, hasVariables } from './variables.js';
19
21
  import { processSlideMarkdown, hasSlideSyntax } from './slides.js';
@@ -970,6 +972,190 @@ export function prepareForFormat(
970
972
  return preparedPath;
971
973
  }
972
974
 
975
+ // =============================================================================
976
+ // Reviewed DOCX (track changes + threaded comments in one file)
977
+ // =============================================================================
978
+
979
+ export interface ReviewedDocxOptions {
980
+ /** Final output path for the reviewed docx. */
981
+ outputPath: string;
982
+ /** Author name attached to the tracked revisions. */
983
+ author?: string;
984
+ /**
985
+ * Thread `{>>...<<}` comments into the same file (parent + reply via
986
+ * commentsExtended.xml). When false, comments are stripped and only tracked
987
+ * changes are emitted.
988
+ */
989
+ includeComments?: boolean;
990
+ /**
991
+ * Optional reference docx: realign comment anchors against its text before
992
+ * injecting, matching the `--reference` behaviour of `--dual`. Only used
993
+ * when includeComments is true.
994
+ */
995
+ referencePath?: string | null;
996
+ /** Extra pandoc args (CLI --pandoc-arg), applied to the single pandoc pass. */
997
+ pandocArgs?: string[];
998
+ verbose?: boolean;
999
+ }
1000
+
1001
+ export interface ReviewedDocxResult {
1002
+ success: boolean;
1003
+ error?: string;
1004
+ outputPath: string;
1005
+ stats: NativeTrackChangeStats;
1006
+ /** Number of parent comments threaded (0 when includeComments is false). */
1007
+ commentCount: number;
1008
+ replyCount: number;
1009
+ /** Comments that could not be anchored (markers not found in the docx). */
1010
+ skippedComments: number;
1011
+ /** Realigned comment count when a reference docx was supplied. */
1012
+ realigned?: number;
1013
+ }
1014
+
1015
+ /**
1016
+ * Build a single reviewed docx containing pandoc-native tracked changes and,
1017
+ * optionally, threaded Word comments.
1018
+ *
1019
+ * One pandoc pass through the full rev filter chain (crossref, citeproc,
1020
+ * reference-doc, macros) emits the `w:ins`/`w:del` revisions from native
1021
+ * `.insertion`/`.deletion` spans; the same file is then post-processed to
1022
+ * thread `{>>...<<}` comments (parent + reply). This is the `--dual
1023
+ * --show-changes` artifact: my edits as tracked changes *and* the reviewer's
1024
+ * comments with my replies, in the one file a supervisor opens and hands back.
1025
+ *
1026
+ * @param directory - Project directory
1027
+ * @param paperPath - Combined paper.md (from combineSections)
1028
+ * @param config - Build config
1029
+ * @param options - Output path, author, comment handling
1030
+ */
1031
+ export async function buildReviewedDocx(
1032
+ directory: string,
1033
+ paperPath: string,
1034
+ config: BuildConfig,
1035
+ options: ReviewedDocxOptions
1036
+ ): Promise<ReviewedDocxResult> {
1037
+ const {
1038
+ outputPath,
1039
+ author = 'Author',
1040
+ includeComments = false,
1041
+ referencePath = null,
1042
+ pandocArgs,
1043
+ verbose,
1044
+ } = options;
1045
+
1046
+ const emptyStats: NativeTrackChangeStats = { insertions: 0, deletions: 0, substitutions: 0 };
1047
+
1048
+ let markdown = fs.readFileSync(paperPath, 'utf-8');
1049
+ let realigned: number | undefined;
1050
+
1051
+ // Realign comment anchors from a reference docx (parity with --dual).
1052
+ if (includeComments && referencePath && fs.existsSync(referencePath)) {
1053
+ try {
1054
+ const { realignMarkdown } = await import('./comment-realign.js');
1055
+ const res = await realignMarkdown(referencePath, markdown);
1056
+ if (res.success) {
1057
+ markdown = res.markdown;
1058
+ realigned = res.insertions;
1059
+ }
1060
+ } catch {
1061
+ // Non-fatal — fall back to the anchors already in the markdown.
1062
+ }
1063
+ }
1064
+
1065
+ // 1. CriticMarkup ins/del/subst → pandoc-native track-change spans.
1066
+ const { text: withSpans, stats } = criticToNativeTrackChanges(markdown, { author });
1067
+
1068
+ // 2. Strip remaining annotations (highlights, and comments unless threading
1069
+ // them). The native spans are inert to stripAnnotations — it only touches
1070
+ // CriticMarkup and `.mark` spans, which are gone or preserved as needed.
1071
+ let content = stripAnnotations(withSpans, { keepComments: includeComments });
1072
+
1073
+ // 3. Shared DOCX transforms (author block, @fig: → "Figure 1", raw figures).
1074
+ const registry = buildRegistry(directory, config.sections);
1075
+ content = applyFormatTransforms(content, 'docx', config, registry);
1076
+
1077
+ // 4. Comment markers (parents get ⟦CMS⟧ ranges; replies drop out for later
1078
+ // threading). No-op when not including comments.
1079
+ let comments: ReturnType<typeof prepareMarkdownWithMarkers>['comments'] = [];
1080
+ if (includeComments) {
1081
+ const prepared = prepareMarkdownWithMarkers(content);
1082
+ content = prepared.markedMarkdown;
1083
+ comments = prepared.comments;
1084
+ }
1085
+
1086
+ const preparedPath = path.join(directory, '.paper-reviewed.md');
1087
+ const tempDocx = path.join(directory, '.paper-reviewed.docx');
1088
+
1089
+ try {
1090
+ fs.writeFileSync(preparedPath, content, 'utf-8');
1091
+
1092
+ // 5. Single pandoc pass — emits native tracked changes with full filter chain.
1093
+ const pandocResult = await runPandoc(preparedPath, 'docx', config, {
1094
+ outputPath: tempDocx,
1095
+ pandocArgs,
1096
+ verbose,
1097
+ });
1098
+ if (!pandocResult.success) {
1099
+ return {
1100
+ success: false,
1101
+ error: pandocResult.error,
1102
+ outputPath,
1103
+ stats: emptyStats,
1104
+ commentCount: 0,
1105
+ replyCount: 0,
1106
+ skippedComments: 0,
1107
+ realigned,
1108
+ };
1109
+ }
1110
+
1111
+ const hasTrackChanges = stats.insertions + stats.deletions + stats.substitutions > 0;
1112
+ if (hasTrackChanges) enableTrackRevisions(tempDocx);
1113
+
1114
+ // 6. Thread comments into the same file (or just move it into place).
1115
+ if (comments.length > 0) {
1116
+ const injection = await injectCommentsAtMarkers(tempDocx, comments, outputPath);
1117
+ if (!injection.success) {
1118
+ return {
1119
+ success: false,
1120
+ error: injection.error,
1121
+ outputPath,
1122
+ stats,
1123
+ commentCount: 0,
1124
+ replyCount: 0,
1125
+ skippedComments: 0,
1126
+ realigned,
1127
+ };
1128
+ }
1129
+ return {
1130
+ success: true,
1131
+ outputPath,
1132
+ stats,
1133
+ commentCount: injection.commentCount,
1134
+ replyCount: injection.replyCount ?? 0,
1135
+ skippedComments: injection.skippedComments,
1136
+ realigned,
1137
+ };
1138
+ }
1139
+
1140
+ fs.copyFileSync(tempDocx, outputPath);
1141
+ return {
1142
+ success: true,
1143
+ outputPath,
1144
+ stats,
1145
+ commentCount: 0,
1146
+ replyCount: 0,
1147
+ skippedComments: 0,
1148
+ realigned,
1149
+ };
1150
+ } finally {
1151
+ if (!process.env.DEBUG) {
1152
+ for (const tmp of [preparedPath, tempDocx]) {
1153
+ try { fs.unlinkSync(tmp); } catch { /* best-effort */ }
1154
+ }
1155
+ }
1156
+ }
1157
+ }
1158
+
973
1159
  /**
974
1160
  * Convert @fig:label references to display format (Figure 1)
975
1161
  */