docrev 0.9.18 → 0.10.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.
@@ -0,0 +1,201 @@
1
+ --[[
2
+ docrev macro filter.
3
+
4
+ Reads a JSON sidecar describing one-argument LaTeX-style macros and expands
5
+ them per output FORMAT. Used for the built-in \tofill{X} (bold orange [X]
6
+ placeholder) and any user-declared macros from rev.yaml.
7
+
8
+ Sidecar path is passed via the DOCREV_MACROS_FILE environment variable, set
9
+ by build.ts before spawning pandoc. Env vars (not metadata) because pandoc's
10
+ filter traversal runs RawInline/RawBlock BEFORE Meta, so by the time we'd
11
+ read metadata the inline expansions have already happened.
12
+
13
+ Why raw OpenXML for docx? Pandoc 3.x's docx writer does NOT honor
14
+ `Span{style="color: #..."}` — those spans render as plain text with no
15
+ <w:color> run property. So for docx we emit raw <w:r> nodes directly. Same
16
+ reasoning for the pptx-color-filter.
17
+
18
+ For latex/pdf/beamer the markdown source already contains \tofill{X} as a raw
19
+ LaTeX inline; we leave it alone because build.ts injects a \providecommand
20
+ into header-includes. For html we emit a raw <span> with inline style. For
21
+ everything else (markdown, gfm, plain) we degrade to **bold [X]** so the
22
+ placeholder never silently disappears.
23
+ ]]
24
+
25
+ local json = require('pandoc.json')
26
+
27
+ local macros_by_name = {}
28
+
29
+ local function load_sidecar()
30
+ local path = os.getenv('DOCREV_MACROS_FILE')
31
+ if not path or path == '' then
32
+ return
33
+ end
34
+ local fh = io.open(path, 'r')
35
+ if not fh then
36
+ io.stderr:write('docrev macro-filter: cannot read sidecar: ' .. path .. '\n')
37
+ return
38
+ end
39
+ local content = fh:read('*a')
40
+ fh:close()
41
+ local ok, parsed = pcall(json.decode, content)
42
+ if not ok or type(parsed) ~= 'table' or type(parsed.macros) ~= 'table' then
43
+ io.stderr:write('docrev macro-filter: malformed sidecar JSON\n')
44
+ return
45
+ end
46
+ for _, m in ipairs(parsed.macros) do
47
+ if type(m) == 'table' and type(m.name) == 'string' then
48
+ macros_by_name[m.name] = m
49
+ end
50
+ end
51
+ end
52
+
53
+ load_sidecar()
54
+
55
+ local function xml_escape(s)
56
+ return (s:gsub('&', '&amp;'):gsub('<', '&lt;'):gsub('>', '&gt;'))
57
+ end
58
+
59
+ local function html_escape(s)
60
+ return (s
61
+ :gsub('&', '&amp;')
62
+ :gsub('<', '&lt;')
63
+ :gsub('>', '&gt;')
64
+ :gsub('"', '&quot;'))
65
+ end
66
+
67
+ -- Resolve effective style for a macro in the current pandoc format.
68
+ -- Per-format entry wins over `default` (replacement, not merge — matches
69
+ -- macros.ts semantics).
70
+ local function pick_style(macro, format)
71
+ if macro.formats and macro.formats[format] then
72
+ return macro.formats[format]
73
+ end
74
+ return macro.default or {}
75
+ end
76
+
77
+ -- Build the inside of the bracket: [prefix][arg][suffix], optionally without
78
+ -- brackets when style.bracket == false.
79
+ local function compose_text(style, arg)
80
+ local prefix = style.prefix or ''
81
+ local suffix = style.suffix or ''
82
+ local inner = prefix .. arg .. suffix
83
+ if style.bracket == false then
84
+ return inner
85
+ end
86
+ return '[' .. inner .. ']'
87
+ end
88
+
89
+ local function render_docx_run(style, arg)
90
+ local rpr = {}
91
+ if style.color then
92
+ table.insert(rpr, '<w:color w:val="' .. style.color .. '"/>')
93
+ end
94
+ if style.bold then
95
+ table.insert(rpr, '<w:b/>')
96
+ end
97
+ if style.italic then
98
+ table.insert(rpr, '<w:i/>')
99
+ end
100
+ local rpr_xml = ''
101
+ if #rpr > 0 then
102
+ rpr_xml = '<w:rPr>' .. table.concat(rpr) .. '</w:rPr>'
103
+ end
104
+ local text = xml_escape(compose_text(style, arg))
105
+ return '<w:r>' .. rpr_xml ..
106
+ '<w:t xml:space="preserve">' .. text .. '</w:t></w:r>'
107
+ end
108
+
109
+ local function render_html(style, arg)
110
+ local css = {}
111
+ if style.color then
112
+ table.insert(css, 'color:#' .. style.color)
113
+ end
114
+ if style.bold then
115
+ table.insert(css, 'font-weight:bold')
116
+ end
117
+ if style.italic then
118
+ table.insert(css, 'font-style:italic')
119
+ end
120
+ local text = html_escape(compose_text(style, arg))
121
+ if #css == 0 then
122
+ return '<span>' .. text .. '</span>'
123
+ end
124
+ return '<span style="' .. table.concat(css, ';') .. '">' .. text .. '</span>'
125
+ end
126
+
127
+ -- Fallback path: produce native pandoc inlines so the macro never silently
128
+ -- disappears in markdown/gfm/plain output. Used when the current format has
129
+ -- no native rich-text path (or we couldn't open the sidecar).
130
+ local function fallback_inlines(style, arg)
131
+ local doc = pandoc.read(compose_text(style, arg), 'markdown')
132
+ local inlines = pandoc.utils.blocks_to_inlines(doc.blocks)
133
+ if style.bold then
134
+ inlines = { pandoc.Strong(inlines) }
135
+ end
136
+ if style.italic then
137
+ inlines = { pandoc.Emph(inlines) }
138
+ end
139
+ return inlines
140
+ end
141
+
142
+ -- Match `\NAME{...}` (with balanced braces inside the argument is NOT
143
+ -- supported — the use case is plain placeholder text, mirroring the reference
144
+ -- filter; users who need nested braces should use a different mechanism).
145
+ local function parse_call(text)
146
+ local name, arg = text:match('^\\([A-Za-z][A-Za-z0-9]*)%s*{(.*)}%s*$')
147
+ if name and arg and macros_by_name[name] then
148
+ return name, arg
149
+ end
150
+ return nil, nil
151
+ end
152
+
153
+ local function expand_inline(el)
154
+ if el.format ~= 'tex' and el.format ~= 'latex' then
155
+ return nil
156
+ end
157
+ local name, arg = parse_call(el.text)
158
+ if not name then return nil end
159
+ local macro = macros_by_name[name]
160
+ local style = pick_style(macro, FORMAT)
161
+
162
+ if FORMAT == 'docx' then
163
+ return pandoc.RawInline('openxml', render_docx_run(style, arg))
164
+ elseif FORMAT == 'html' or FORMAT == 'html4' or FORMAT == 'html5' or FORMAT == 'chunkedhtml' then
165
+ return pandoc.RawInline('html', render_html(style, arg))
166
+ elseif FORMAT == 'latex' or FORMAT == 'beamer' or FORMAT == 'context' then
167
+ -- Leave the raw LaTeX as-is. build.ts injects \providecommand into
168
+ -- header-includes, so the LaTeX engine renders it directly.
169
+ return nil
170
+ else
171
+ return fallback_inlines(style, arg)
172
+ end
173
+ end
174
+
175
+ local function expand_block(el)
176
+ if el.format ~= 'tex' and el.format ~= 'latex' then
177
+ return nil
178
+ end
179
+ local name, arg = parse_call(el.text)
180
+ if not name then return nil end
181
+ local macro = macros_by_name[name]
182
+ local style = pick_style(macro, FORMAT)
183
+
184
+ if FORMAT == 'docx' then
185
+ return pandoc.RawBlock('openxml', '<w:p>' .. render_docx_run(style, arg) .. '</w:p>')
186
+ elseif FORMAT == 'html' or FORMAT == 'html4' or FORMAT == 'html5' or FORMAT == 'chunkedhtml' then
187
+ return pandoc.RawBlock('html', '<p>' .. render_html(style, arg) .. '</p>')
188
+ elseif FORMAT == 'latex' or FORMAT == 'beamer' or FORMAT == 'context' then
189
+ return nil
190
+ else
191
+ return pandoc.Para(fallback_inlines(style, arg))
192
+ end
193
+ end
194
+
195
+ function RawInline(el)
196
+ return expand_inline(el)
197
+ end
198
+
199
+ function RawBlock(el)
200
+ return expand_block(el)
201
+ end
package/lib/macros.ts ADDED
@@ -0,0 +1,273 @@
1
+ /**
2
+ * Placeholder/highlight macros for docrev.
3
+ *
4
+ * Users write `\tofill{X}` (or any custom macro they declare) in markdown
5
+ * source and the build pipeline expands it per output format:
6
+ *
7
+ * - docx: raw OpenXML run with explicit color + bold (Span+style is NOT
8
+ * honored by pandoc's docx writer, so we emit raw <w:r> nodes).
9
+ * - pdf / tex / beamer: a `\providecommand` is injected via header-includes,
10
+ * so the LaTeX command works directly. `\providecommand` means the user
11
+ * can still override with `\renewcommand` in their own preamble.
12
+ * - html: raw HTML span with inline style.
13
+ * - everything else (markdown, gfm, etc.): bold [X] fallback. Never silently
14
+ * dropped.
15
+ *
16
+ * The mechanism is generic: `\tofill` is the first built-in. Users can add
17
+ * their own macros under `macros:` in rev.yaml, and override the built-in by
18
+ * declaring a macro with the same name.
19
+ */
20
+
21
+ import * as fs from 'fs';
22
+ import * as path from 'path';
23
+ import { fileURLToPath } from 'url';
24
+
25
+ // =============================================================================
26
+ // Types
27
+ // =============================================================================
28
+
29
+ /**
30
+ * Per-format rendering rules for a macro.
31
+ *
32
+ * Fields are independent — set any subset. Unset fields fall back to defaults
33
+ * (no color, no bold, no italic, bracket wrap on, etc.).
34
+ */
35
+ export interface MacroFormatStyle {
36
+ /** Hex color without '#' (e.g. "C2410C"). */
37
+ color?: string;
38
+ /** Wrap the rendered content in bold. */
39
+ bold?: boolean;
40
+ /** Wrap the rendered content in italic. */
41
+ italic?: boolean;
42
+ /** Wrap the content in [...] brackets. Default: true. */
43
+ bracket?: boolean;
44
+ /** Optional literal prefix string inside the brackets (e.g. "NOTE: "). */
45
+ prefix?: string;
46
+ /** Optional literal suffix string inside the brackets. */
47
+ suffix?: string;
48
+ }
49
+
50
+ /**
51
+ * Macro definition. `name` is the LaTeX command name without the leading
52
+ * backslash (e.g. "tofill" → \tofill{...}). `formats` holds per-format rules;
53
+ * a missing format key inherits from `default`.
54
+ */
55
+ export interface MacroDef {
56
+ name: string;
57
+ /** Default rendering rules; used when a format-specific override is absent. */
58
+ default?: MacroFormatStyle;
59
+ /** Per-format overrides, keyed by pandoc format (docx, pdf, html, ...). */
60
+ formats?: Record<string, MacroFormatStyle>;
61
+ }
62
+
63
+ /**
64
+ * Built-in macros shipped with docrev. The first entry is the original use
65
+ * case: \tofill{X} → bold orange [X] placeholder.
66
+ */
67
+ export const BUILTIN_MACROS: MacroDef[] = [
68
+ {
69
+ name: 'tofill',
70
+ default: { color: 'C2410C', bold: true, bracket: true },
71
+ },
72
+ ];
73
+
74
+ // =============================================================================
75
+ // Validation
76
+ // =============================================================================
77
+
78
+ const MACRO_NAME_RE = /^[A-Za-z][A-Za-z0-9]*$/;
79
+ const HEX_COLOR_RE = /^[0-9A-Fa-f]{6}$/;
80
+
81
+ /**
82
+ * Validate a user-declared macro entry. Returns a list of error strings;
83
+ * empty means the macro is valid.
84
+ */
85
+ export function validateMacro(macro: unknown): string[] {
86
+ const errors: string[] = [];
87
+
88
+ if (!macro || typeof macro !== 'object' || Array.isArray(macro)) {
89
+ return ['macro must be an object'];
90
+ }
91
+ const m = macro as Partial<MacroDef>;
92
+
93
+ if (!m.name || typeof m.name !== 'string') {
94
+ errors.push('macro.name is required');
95
+ } else if (!MACRO_NAME_RE.test(m.name)) {
96
+ errors.push(`macro.name "${m.name}" must match [A-Za-z][A-Za-z0-9]*`);
97
+ }
98
+
99
+ const checkStyle = (style: unknown, key: string): void => {
100
+ if (style === undefined) return;
101
+ if (!style || typeof style !== 'object' || Array.isArray(style)) {
102
+ errors.push(`${key} must be an object`);
103
+ return;
104
+ }
105
+ const s = style as MacroFormatStyle;
106
+ if (s.color !== undefined && (typeof s.color !== 'string' || !HEX_COLOR_RE.test(s.color))) {
107
+ errors.push(`${key}.color must be a 6-digit hex string without '#' (got "${s.color}")`);
108
+ }
109
+ for (const flag of ['bold', 'italic', 'bracket'] as const) {
110
+ if (s[flag] !== undefined && typeof s[flag] !== 'boolean') {
111
+ errors.push(`${key}.${flag} must be a boolean`);
112
+ }
113
+ }
114
+ for (const text of ['prefix', 'suffix'] as const) {
115
+ if (s[text] !== undefined && typeof s[text] !== 'string') {
116
+ errors.push(`${key}.${text} must be a string`);
117
+ }
118
+ }
119
+ };
120
+
121
+ checkStyle(m.default, 'macro.default');
122
+ if (m.formats !== undefined) {
123
+ if (!m.formats || typeof m.formats !== 'object' || Array.isArray(m.formats)) {
124
+ errors.push('macro.formats must be an object keyed by format name');
125
+ } else {
126
+ for (const [fmt, style] of Object.entries(m.formats)) {
127
+ checkStyle(style, `macro.formats.${fmt}`);
128
+ }
129
+ }
130
+ }
131
+
132
+ return errors;
133
+ }
134
+
135
+ // =============================================================================
136
+ // Merge
137
+ // =============================================================================
138
+
139
+ /**
140
+ * Merge built-in macros with user-declared macros. User entries override
141
+ * built-ins by `name` (case-sensitive). Invalid entries are dropped with a
142
+ * console warning so a malformed user macro never silently disables the
143
+ * built-in.
144
+ */
145
+ export function mergeMacros(userMacros: unknown): MacroDef[] {
146
+ const builtins = new Map<string, MacroDef>();
147
+ for (const m of BUILTIN_MACROS) builtins.set(m.name, m);
148
+
149
+ if (!userMacros) return [...builtins.values()];
150
+ if (!Array.isArray(userMacros)) {
151
+ console.warn('macros: rev.yaml `macros` must be a list; ignoring');
152
+ return [...builtins.values()];
153
+ }
154
+
155
+ for (const raw of userMacros) {
156
+ const errors = validateMacro(raw);
157
+ if (errors.length > 0) {
158
+ console.warn(`macros: skipping invalid macro: ${errors.join('; ')}`);
159
+ continue;
160
+ }
161
+ const def = raw as MacroDef;
162
+ builtins.set(def.name, def);
163
+ }
164
+
165
+ return [...builtins.values()];
166
+ }
167
+
168
+ // =============================================================================
169
+ // LaTeX preamble generation (PDF / tex / beamer)
170
+ // =============================================================================
171
+
172
+ /**
173
+ * Build the LaTeX color spec for a style. Returns the wrapping LaTeX with a
174
+ * `#1` placeholder where the argument lands.
175
+ */
176
+ function latexCommandBody(style: MacroFormatStyle): string {
177
+ const prefix = style.prefix ? escapeLatex(style.prefix) : '';
178
+ const suffix = style.suffix ? escapeLatex(style.suffix) : '';
179
+ const inner = `${prefix}#1${suffix}`;
180
+ const bracketed = style.bracket === false ? inner : `[${inner}]`;
181
+
182
+ let body = bracketed;
183
+ if (style.italic) body = `\\textit{${body}}`;
184
+ if (style.bold) body = `\\textbf{${body}}`;
185
+ if (style.color) body = `\\textcolor[HTML]{${style.color.toUpperCase()}}{${body}}`;
186
+ return body;
187
+ }
188
+
189
+ /**
190
+ * Generate `\providecommand` definitions for all macros. `\providecommand`
191
+ * means user-supplied `\renewcommand` (in a custom header-includes file) still
192
+ * wins, preserving backwards compat with existing projects.
193
+ *
194
+ * Returns an empty string when the macro list is empty.
195
+ */
196
+ export function generateLatexPreamble(macros: MacroDef[]): string {
197
+ const lines: string[] = ['% docrev: placeholder macros'];
198
+ // \textcolor in [HTML]{...} requires xcolor with the [HTML] option.
199
+ lines.push('\\PassOptionsToPackage{HTML}{xcolor}');
200
+ // Some templates already load xcolor; \usepackage tolerates duplicates with
201
+ // the same options.
202
+ lines.push('\\usepackage[HTML]{xcolor}');
203
+
204
+ for (const m of macros) {
205
+ const style = pickStyle(m, 'latex');
206
+ const body = latexCommandBody(style);
207
+ lines.push(`\\providecommand{\\${m.name}}[1]{${body}}`);
208
+ }
209
+
210
+ return lines.join('\n');
211
+ }
212
+
213
+ function escapeLatex(s: string): string {
214
+ // Conservative escape — these are user-authored short literals (prefix/suffix).
215
+ return s
216
+ .replace(/\\/g, '\\textbackslash{}')
217
+ .replace(/([&%$#_{}])/g, '\\$1')
218
+ .replace(/~/g, '\\textasciitilde{}')
219
+ .replace(/\^/g, '\\textasciicircum{}');
220
+ }
221
+
222
+ // =============================================================================
223
+ // Style resolution per format
224
+ // =============================================================================
225
+
226
+ /**
227
+ * Resolve the effective style for a macro in a given pandoc format. Per-format
228
+ * override wins over the macro's default; both can be partial — fields are
229
+ * not merged across `default` and `formats[fmt]` (the format-specific entry
230
+ * replaces `default` entirely when present), keeping rev.yaml semantics
231
+ * predictable.
232
+ *
233
+ * Falls back to `default` when no `formats[fmt]` exists, and to an empty
234
+ * style ({}) when neither is set.
235
+ */
236
+ export function pickStyle(macro: MacroDef, format: string): MacroFormatStyle {
237
+ const fmt = macro.formats?.[format];
238
+ if (fmt) return fmt;
239
+ return macro.default ?? {};
240
+ }
241
+
242
+ // =============================================================================
243
+ // Lua filter sidecar
244
+ // =============================================================================
245
+
246
+ /**
247
+ * Serialize the macro list to a compact JSON sidecar consumed by the lua
248
+ * filter at build time. The lua filter reads this file at startup and uses it
249
+ * to expand `\tofill{X}` (or any other declared macro) per FORMAT.
250
+ *
251
+ * Returns the absolute path to the written sidecar.
252
+ */
253
+ export function writeMacrosSidecar(directory: string, macros: MacroDef[]): string {
254
+ const sidecarPath = path.join(directory, '.macros.json');
255
+ fs.writeFileSync(sidecarPath, JSON.stringify({ macros }), 'utf-8');
256
+ return sidecarPath;
257
+ }
258
+
259
+ /**
260
+ * Resolve the absolute path to the bundled lua filter. Works both from source
261
+ * (`lib/macro-filter.lua`) and from the compiled package (`dist/lib/...`)
262
+ * because the postbuild script copies .lua files alongside the .js output.
263
+ */
264
+ export function getMacroFilterPath(): string {
265
+ // import.meta.url points to the running file: lib/macros.ts in source,
266
+ // dist/lib/macros.js when published. The filter sits next to it.
267
+ //
268
+ // Use fileURLToPath so paths with spaces (Windows: "C:\Users\Gilles Colling\…")
269
+ // resolve correctly. The naive `new URL(...).pathname` returns URL-encoded
270
+ // `%20` segments and fs.existsSync silently fails.
271
+ const here = path.dirname(fileURLToPath(import.meta.url));
272
+ return path.join(here, 'macro-filter.lua');
273
+ }
package/lib/schema.ts CHANGED
@@ -218,6 +218,40 @@ export const revYamlSchema: Schema = {
218
218
  },
219
219
  additionalProperties: true,
220
220
  },
221
+ macros: {
222
+ type: 'array',
223
+ description: 'Placeholder/highlight macros (e.g. \\tofill{X}). Built-in macros are merged automatically; entries here add new macros or override built-ins by name.',
224
+ items: {
225
+ type: 'object',
226
+ properties: {
227
+ name: {
228
+ type: 'string',
229
+ description: 'Macro command name without leading backslash, e.g. "tofill" for \\tofill{...}',
230
+ pattern: '^[A-Za-z][A-Za-z0-9]*$',
231
+ },
232
+ default: {
233
+ type: 'object',
234
+ description: 'Default rendering rules across formats',
235
+ properties: {
236
+ color: { type: 'string', pattern: '^[0-9A-Fa-f]{6}$' },
237
+ bold: { type: 'boolean' },
238
+ italic: { type: 'boolean' },
239
+ bracket: { type: 'boolean', default: true },
240
+ prefix: { type: 'string' },
241
+ suffix: { type: 'string' },
242
+ },
243
+ additionalProperties: false,
244
+ },
245
+ formats: {
246
+ type: 'object',
247
+ description: 'Per-format overrides (keys: docx, pdf, latex, html, ...)',
248
+ additionalProperties: true,
249
+ },
250
+ },
251
+ required: ['name'],
252
+ additionalProperties: false,
253
+ },
254
+ },
221
255
  },
222
256
  additionalProperties: true,
223
257
  };
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docrev",
3
- "version": "0.9.18",
3
+ "version": "0.10.0",
4
4
  "description": "Academic paper revision workflow: Word ↔ Markdown round-trips, DOI validation, reviewer comments",
5
5
  "type": "module",
6
6
  "types": "dist/lib/types.d.ts",
@@ -6,14 +6,20 @@
6
6
  * tsc compiles bin/rev.ts → dist/bin/rev.js but:
7
7
  * 1. Preserves the #!/usr/bin/env tsx shebang (needs to be node)
8
8
  * 2. Relative paths like '../package.json' break (bin/ → dist/bin/ adds a level)
9
+ *
10
+ * Also copies non-TS asset files (lua filters) from lib/ to dist/lib/ so the
11
+ * compiled output can locate them via `import.meta.url`. Without this step
12
+ * the lua filters live in lib/ in the published tarball while the runtime
13
+ * looks for them in dist/lib/.
9
14
  */
10
15
 
11
- import { readFileSync, writeFileSync } from 'fs';
16
+ import { readFileSync, writeFileSync, readdirSync, copyFileSync, mkdirSync, existsSync } from 'fs';
12
17
  import { join, dirname } from 'path';
13
18
  import { fileURLToPath } from 'url';
14
19
 
15
20
  const __dirname = dirname(fileURLToPath(import.meta.url));
16
- const revPath = join(__dirname, '..', 'dist', 'bin', 'rev.js');
21
+ const projectRoot = join(__dirname, '..');
22
+ const revPath = join(projectRoot, 'dist', 'bin', 'rev.js');
17
23
 
18
24
  let content = readFileSync(revPath, 'utf-8');
19
25
 
@@ -26,3 +32,16 @@ content = content.replace("'../package.json'", "'../../package.json'");
26
32
 
27
33
  writeFileSync(revPath, content, 'utf-8');
28
34
  console.log('postbuild: fixed dist/bin/rev.js (shebang + paths)');
35
+
36
+ // Copy lua filter assets so import.meta.url resolves them at runtime.
37
+ const libDir = join(projectRoot, 'lib');
38
+ const distLibDir = join(projectRoot, 'dist', 'lib');
39
+ if (!existsSync(distLibDir)) {
40
+ mkdirSync(distLibDir, { recursive: true });
41
+ }
42
+ for (const entry of readdirSync(libDir)) {
43
+ if (entry.endsWith('.lua')) {
44
+ copyFileSync(join(libDir, entry), join(distLibDir, entry));
45
+ console.log(`postbuild: copied ${entry} → dist/lib/`);
46
+ }
47
+ }