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.
- package/CHANGELOG.md +15 -0
- package/README.md +25 -0
- package/dist/lib/anchor-match.d.ts +1 -1
- package/dist/lib/anchor-match.d.ts.map +1 -1
- package/dist/lib/anchor-match.js +47 -17
- package/dist/lib/anchor-match.js.map +1 -1
- package/dist/lib/build.d.ts +8 -0
- package/dist/lib/build.d.ts.map +1 -1
- package/dist/lib/build.js +58 -2
- package/dist/lib/build.js.map +1 -1
- package/dist/lib/macro-filter.lua +201 -0
- package/dist/lib/macros.d.ts +102 -0
- package/dist/lib/macros.d.ts.map +1 -0
- package/dist/lib/macros.js +218 -0
- package/dist/lib/macros.js.map +1 -0
- package/dist/lib/pptx-color-filter.lua +37 -0
- package/dist/lib/schema.d.ts.map +1 -1
- package/dist/lib/schema.js +34 -0
- package/dist/lib/schema.js.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/lib/anchor-match.ts +49 -17
- package/lib/build.ts +74 -2
- package/lib/macro-filter.lua +201 -0
- package/lib/macros.ts +273 -0
- package/lib/schema.ts +34 -0
- package/mkdocs.yml +64 -64
- package/package.json +1 -1
- package/scripts/postbuild.js +21 -2
- package/issues.md +0 -180
- package/site/assets/extra.css +0 -208
- package/site/commands.html +0 -926
- package/site/configuration.html +0 -469
- package/site/index.html +0 -288
- package/site/troubleshooting.html +0 -461
- package/site/workflow.html +0 -518
|
@@ -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('&', '&'):gsub('<', '<'):gsub('>', '>'))
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
local function html_escape(s)
|
|
60
|
+
return (s
|
|
61
|
+
:gsub('&', '&')
|
|
62
|
+
:gsub('<', '<')
|
|
63
|
+
:gsub('>', '>')
|
|
64
|
+
:gsub('"', '"'))
|
|
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
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
* Per-format rendering rules for a macro.
|
|
22
|
+
*
|
|
23
|
+
* Fields are independent — set any subset. Unset fields fall back to defaults
|
|
24
|
+
* (no color, no bold, no italic, bracket wrap on, etc.).
|
|
25
|
+
*/
|
|
26
|
+
export interface MacroFormatStyle {
|
|
27
|
+
/** Hex color without '#' (e.g. "C2410C"). */
|
|
28
|
+
color?: string;
|
|
29
|
+
/** Wrap the rendered content in bold. */
|
|
30
|
+
bold?: boolean;
|
|
31
|
+
/** Wrap the rendered content in italic. */
|
|
32
|
+
italic?: boolean;
|
|
33
|
+
/** Wrap the content in [...] brackets. Default: true. */
|
|
34
|
+
bracket?: boolean;
|
|
35
|
+
/** Optional literal prefix string inside the brackets (e.g. "NOTE: "). */
|
|
36
|
+
prefix?: string;
|
|
37
|
+
/** Optional literal suffix string inside the brackets. */
|
|
38
|
+
suffix?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Macro definition. `name` is the LaTeX command name without the leading
|
|
42
|
+
* backslash (e.g. "tofill" → \tofill{...}). `formats` holds per-format rules;
|
|
43
|
+
* a missing format key inherits from `default`.
|
|
44
|
+
*/
|
|
45
|
+
export interface MacroDef {
|
|
46
|
+
name: string;
|
|
47
|
+
/** Default rendering rules; used when a format-specific override is absent. */
|
|
48
|
+
default?: MacroFormatStyle;
|
|
49
|
+
/** Per-format overrides, keyed by pandoc format (docx, pdf, html, ...). */
|
|
50
|
+
formats?: Record<string, MacroFormatStyle>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Built-in macros shipped with docrev. The first entry is the original use
|
|
54
|
+
* case: \tofill{X} → bold orange [X] placeholder.
|
|
55
|
+
*/
|
|
56
|
+
export declare const BUILTIN_MACROS: MacroDef[];
|
|
57
|
+
/**
|
|
58
|
+
* Validate a user-declared macro entry. Returns a list of error strings;
|
|
59
|
+
* empty means the macro is valid.
|
|
60
|
+
*/
|
|
61
|
+
export declare function validateMacro(macro: unknown): string[];
|
|
62
|
+
/**
|
|
63
|
+
* Merge built-in macros with user-declared macros. User entries override
|
|
64
|
+
* built-ins by `name` (case-sensitive). Invalid entries are dropped with a
|
|
65
|
+
* console warning so a malformed user macro never silently disables the
|
|
66
|
+
* built-in.
|
|
67
|
+
*/
|
|
68
|
+
export declare function mergeMacros(userMacros: unknown): MacroDef[];
|
|
69
|
+
/**
|
|
70
|
+
* Generate `\providecommand` definitions for all macros. `\providecommand`
|
|
71
|
+
* means user-supplied `\renewcommand` (in a custom header-includes file) still
|
|
72
|
+
* wins, preserving backwards compat with existing projects.
|
|
73
|
+
*
|
|
74
|
+
* Returns an empty string when the macro list is empty.
|
|
75
|
+
*/
|
|
76
|
+
export declare function generateLatexPreamble(macros: MacroDef[]): string;
|
|
77
|
+
/**
|
|
78
|
+
* Resolve the effective style for a macro in a given pandoc format. Per-format
|
|
79
|
+
* override wins over the macro's default; both can be partial — fields are
|
|
80
|
+
* not merged across `default` and `formats[fmt]` (the format-specific entry
|
|
81
|
+
* replaces `default` entirely when present), keeping rev.yaml semantics
|
|
82
|
+
* predictable.
|
|
83
|
+
*
|
|
84
|
+
* Falls back to `default` when no `formats[fmt]` exists, and to an empty
|
|
85
|
+
* style ({}) when neither is set.
|
|
86
|
+
*/
|
|
87
|
+
export declare function pickStyle(macro: MacroDef, format: string): MacroFormatStyle;
|
|
88
|
+
/**
|
|
89
|
+
* Serialize the macro list to a compact JSON sidecar consumed by the lua
|
|
90
|
+
* filter at build time. The lua filter reads this file at startup and uses it
|
|
91
|
+
* to expand `\tofill{X}` (or any other declared macro) per FORMAT.
|
|
92
|
+
*
|
|
93
|
+
* Returns the absolute path to the written sidecar.
|
|
94
|
+
*/
|
|
95
|
+
export declare function writeMacrosSidecar(directory: string, macros: MacroDef[]): string;
|
|
96
|
+
/**
|
|
97
|
+
* Resolve the absolute path to the bundled lua filter. Works both from source
|
|
98
|
+
* (`lib/macro-filter.lua`) and from the compiled package (`dist/lib/...`)
|
|
99
|
+
* because the postbuild script copies .lua files alongside the .js output.
|
|
100
|
+
*/
|
|
101
|
+
export declare function getMacroFilterPath(): string;
|
|
102
|
+
//# sourceMappingURL=macros.d.ts.map
|
|
@@ -0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M,CAIhF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAS3C"}
|
|
@@ -0,0 +1,218 @@
|
|
|
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
|
+
import * as fs from 'fs';
|
|
21
|
+
import * as path from 'path';
|
|
22
|
+
import { fileURLToPath } from 'url';
|
|
23
|
+
/**
|
|
24
|
+
* Built-in macros shipped with docrev. The first entry is the original use
|
|
25
|
+
* case: \tofill{X} → bold orange [X] placeholder.
|
|
26
|
+
*/
|
|
27
|
+
export const BUILTIN_MACROS = [
|
|
28
|
+
{
|
|
29
|
+
name: 'tofill',
|
|
30
|
+
default: { color: 'C2410C', bold: true, bracket: true },
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
// =============================================================================
|
|
34
|
+
// Validation
|
|
35
|
+
// =============================================================================
|
|
36
|
+
const MACRO_NAME_RE = /^[A-Za-z][A-Za-z0-9]*$/;
|
|
37
|
+
const HEX_COLOR_RE = /^[0-9A-Fa-f]{6}$/;
|
|
38
|
+
/**
|
|
39
|
+
* Validate a user-declared macro entry. Returns a list of error strings;
|
|
40
|
+
* empty means the macro is valid.
|
|
41
|
+
*/
|
|
42
|
+
export function validateMacro(macro) {
|
|
43
|
+
const errors = [];
|
|
44
|
+
if (!macro || typeof macro !== 'object' || Array.isArray(macro)) {
|
|
45
|
+
return ['macro must be an object'];
|
|
46
|
+
}
|
|
47
|
+
const m = macro;
|
|
48
|
+
if (!m.name || typeof m.name !== 'string') {
|
|
49
|
+
errors.push('macro.name is required');
|
|
50
|
+
}
|
|
51
|
+
else if (!MACRO_NAME_RE.test(m.name)) {
|
|
52
|
+
errors.push(`macro.name "${m.name}" must match [A-Za-z][A-Za-z0-9]*`);
|
|
53
|
+
}
|
|
54
|
+
const checkStyle = (style, key) => {
|
|
55
|
+
if (style === undefined)
|
|
56
|
+
return;
|
|
57
|
+
if (!style || typeof style !== 'object' || Array.isArray(style)) {
|
|
58
|
+
errors.push(`${key} must be an object`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const s = style;
|
|
62
|
+
if (s.color !== undefined && (typeof s.color !== 'string' || !HEX_COLOR_RE.test(s.color))) {
|
|
63
|
+
errors.push(`${key}.color must be a 6-digit hex string without '#' (got "${s.color}")`);
|
|
64
|
+
}
|
|
65
|
+
for (const flag of ['bold', 'italic', 'bracket']) {
|
|
66
|
+
if (s[flag] !== undefined && typeof s[flag] !== 'boolean') {
|
|
67
|
+
errors.push(`${key}.${flag} must be a boolean`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
for (const text of ['prefix', 'suffix']) {
|
|
71
|
+
if (s[text] !== undefined && typeof s[text] !== 'string') {
|
|
72
|
+
errors.push(`${key}.${text} must be a string`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
checkStyle(m.default, 'macro.default');
|
|
77
|
+
if (m.formats !== undefined) {
|
|
78
|
+
if (!m.formats || typeof m.formats !== 'object' || Array.isArray(m.formats)) {
|
|
79
|
+
errors.push('macro.formats must be an object keyed by format name');
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
for (const [fmt, style] of Object.entries(m.formats)) {
|
|
83
|
+
checkStyle(style, `macro.formats.${fmt}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return errors;
|
|
88
|
+
}
|
|
89
|
+
// =============================================================================
|
|
90
|
+
// Merge
|
|
91
|
+
// =============================================================================
|
|
92
|
+
/**
|
|
93
|
+
* Merge built-in macros with user-declared macros. User entries override
|
|
94
|
+
* built-ins by `name` (case-sensitive). Invalid entries are dropped with a
|
|
95
|
+
* console warning so a malformed user macro never silently disables the
|
|
96
|
+
* built-in.
|
|
97
|
+
*/
|
|
98
|
+
export function mergeMacros(userMacros) {
|
|
99
|
+
const builtins = new Map();
|
|
100
|
+
for (const m of BUILTIN_MACROS)
|
|
101
|
+
builtins.set(m.name, m);
|
|
102
|
+
if (!userMacros)
|
|
103
|
+
return [...builtins.values()];
|
|
104
|
+
if (!Array.isArray(userMacros)) {
|
|
105
|
+
console.warn('macros: rev.yaml `macros` must be a list; ignoring');
|
|
106
|
+
return [...builtins.values()];
|
|
107
|
+
}
|
|
108
|
+
for (const raw of userMacros) {
|
|
109
|
+
const errors = validateMacro(raw);
|
|
110
|
+
if (errors.length > 0) {
|
|
111
|
+
console.warn(`macros: skipping invalid macro: ${errors.join('; ')}`);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const def = raw;
|
|
115
|
+
builtins.set(def.name, def);
|
|
116
|
+
}
|
|
117
|
+
return [...builtins.values()];
|
|
118
|
+
}
|
|
119
|
+
// =============================================================================
|
|
120
|
+
// LaTeX preamble generation (PDF / tex / beamer)
|
|
121
|
+
// =============================================================================
|
|
122
|
+
/**
|
|
123
|
+
* Build the LaTeX color spec for a style. Returns the wrapping LaTeX with a
|
|
124
|
+
* `#1` placeholder where the argument lands.
|
|
125
|
+
*/
|
|
126
|
+
function latexCommandBody(style) {
|
|
127
|
+
const prefix = style.prefix ? escapeLatex(style.prefix) : '';
|
|
128
|
+
const suffix = style.suffix ? escapeLatex(style.suffix) : '';
|
|
129
|
+
const inner = `${prefix}#1${suffix}`;
|
|
130
|
+
const bracketed = style.bracket === false ? inner : `[${inner}]`;
|
|
131
|
+
let body = bracketed;
|
|
132
|
+
if (style.italic)
|
|
133
|
+
body = `\\textit{${body}}`;
|
|
134
|
+
if (style.bold)
|
|
135
|
+
body = `\\textbf{${body}}`;
|
|
136
|
+
if (style.color)
|
|
137
|
+
body = `\\textcolor[HTML]{${style.color.toUpperCase()}}{${body}}`;
|
|
138
|
+
return body;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Generate `\providecommand` definitions for all macros. `\providecommand`
|
|
142
|
+
* means user-supplied `\renewcommand` (in a custom header-includes file) still
|
|
143
|
+
* wins, preserving backwards compat with existing projects.
|
|
144
|
+
*
|
|
145
|
+
* Returns an empty string when the macro list is empty.
|
|
146
|
+
*/
|
|
147
|
+
export function generateLatexPreamble(macros) {
|
|
148
|
+
const lines = ['% docrev: placeholder macros'];
|
|
149
|
+
// \textcolor in [HTML]{...} requires xcolor with the [HTML] option.
|
|
150
|
+
lines.push('\\PassOptionsToPackage{HTML}{xcolor}');
|
|
151
|
+
// Some templates already load xcolor; \usepackage tolerates duplicates with
|
|
152
|
+
// the same options.
|
|
153
|
+
lines.push('\\usepackage[HTML]{xcolor}');
|
|
154
|
+
for (const m of macros) {
|
|
155
|
+
const style = pickStyle(m, 'latex');
|
|
156
|
+
const body = latexCommandBody(style);
|
|
157
|
+
lines.push(`\\providecommand{\\${m.name}}[1]{${body}}`);
|
|
158
|
+
}
|
|
159
|
+
return lines.join('\n');
|
|
160
|
+
}
|
|
161
|
+
function escapeLatex(s) {
|
|
162
|
+
// Conservative escape — these are user-authored short literals (prefix/suffix).
|
|
163
|
+
return s
|
|
164
|
+
.replace(/\\/g, '\\textbackslash{}')
|
|
165
|
+
.replace(/([&%$#_{}])/g, '\\$1')
|
|
166
|
+
.replace(/~/g, '\\textasciitilde{}')
|
|
167
|
+
.replace(/\^/g, '\\textasciicircum{}');
|
|
168
|
+
}
|
|
169
|
+
// =============================================================================
|
|
170
|
+
// Style resolution per format
|
|
171
|
+
// =============================================================================
|
|
172
|
+
/**
|
|
173
|
+
* Resolve the effective style for a macro in a given pandoc format. Per-format
|
|
174
|
+
* override wins over the macro's default; both can be partial — fields are
|
|
175
|
+
* not merged across `default` and `formats[fmt]` (the format-specific entry
|
|
176
|
+
* replaces `default` entirely when present), keeping rev.yaml semantics
|
|
177
|
+
* predictable.
|
|
178
|
+
*
|
|
179
|
+
* Falls back to `default` when no `formats[fmt]` exists, and to an empty
|
|
180
|
+
* style ({}) when neither is set.
|
|
181
|
+
*/
|
|
182
|
+
export function pickStyle(macro, format) {
|
|
183
|
+
const fmt = macro.formats?.[format];
|
|
184
|
+
if (fmt)
|
|
185
|
+
return fmt;
|
|
186
|
+
return macro.default ?? {};
|
|
187
|
+
}
|
|
188
|
+
// =============================================================================
|
|
189
|
+
// Lua filter sidecar
|
|
190
|
+
// =============================================================================
|
|
191
|
+
/**
|
|
192
|
+
* Serialize the macro list to a compact JSON sidecar consumed by the lua
|
|
193
|
+
* filter at build time. The lua filter reads this file at startup and uses it
|
|
194
|
+
* to expand `\tofill{X}` (or any other declared macro) per FORMAT.
|
|
195
|
+
*
|
|
196
|
+
* Returns the absolute path to the written sidecar.
|
|
197
|
+
*/
|
|
198
|
+
export function writeMacrosSidecar(directory, macros) {
|
|
199
|
+
const sidecarPath = path.join(directory, '.macros.json');
|
|
200
|
+
fs.writeFileSync(sidecarPath, JSON.stringify({ macros }), 'utf-8');
|
|
201
|
+
return sidecarPath;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Resolve the absolute path to the bundled lua filter. Works both from source
|
|
205
|
+
* (`lib/macro-filter.lua`) and from the compiled package (`dist/lib/...`)
|
|
206
|
+
* because the postbuild script copies .lua files alongside the .js output.
|
|
207
|
+
*/
|
|
208
|
+
export function getMacroFilterPath() {
|
|
209
|
+
// import.meta.url points to the running file: lib/macros.ts in source,
|
|
210
|
+
// dist/lib/macros.js when published. The filter sits next to it.
|
|
211
|
+
//
|
|
212
|
+
// Use fileURLToPath so paths with spaces (Windows: "C:\Users\Gilles Colling\…")
|
|
213
|
+
// resolve correctly. The naive `new URL(...).pathname` returns URL-encoded
|
|
214
|
+
// `%20` segments and fs.existsSync silently fails.
|
|
215
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
216
|
+
return path.join(here, 'macro-filter.lua');
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=macros.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"macros.js","sourceRoot":"","sources":["../../lib/macros.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAwCpC;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAe;IACxC;QACE,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE;KACxD;CACF,CAAC;AAEF,gFAAgF;AAChF,aAAa;AACb,gFAAgF;AAEhF,MAAM,aAAa,GAAG,wBAAwB,CAAC;AAC/C,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAExC;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAChE,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACrC,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,UAAU,SAAS,CAAC,KAAe,EAAE,MAAc;IACvD,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC;IACpC,IAAI,GAAG;QAAE,OAAO,GAAG,CAAC;IACpB,OAAO,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC;AAC7B,CAAC;AAED,gFAAgF;AAChF,qBAAqB;AACrB,gFAAgF;AAEhF;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAAiB,EAAE,MAAkB;IACtE,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IACzD,EAAE,CAAC,aAAa,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IACnE,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB;IAChC,uEAAuE;IACvE,iEAAiE;IACjE,EAAE;IACF,gFAAgF;IAChF,2EAA2E;IAC3E,mDAAmD;IACnD,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1D,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
-- Pandoc Lua filter to add color support for PPTX
|
|
2
|
+
-- Handles [text]{color=#RRGGBB} syntax
|
|
3
|
+
|
|
4
|
+
function Span(elem)
|
|
5
|
+
local color = elem.attributes['color']
|
|
6
|
+
if color then
|
|
7
|
+
-- Remove # if present
|
|
8
|
+
color = color:gsub('^#', '')
|
|
9
|
+
|
|
10
|
+
-- Create raw OpenXML for colored text
|
|
11
|
+
local content_text = pandoc.utils.stringify(elem.content)
|
|
12
|
+
|
|
13
|
+
-- Check if content has bold
|
|
14
|
+
local is_bold = false
|
|
15
|
+
for _, item in ipairs(elem.content) do
|
|
16
|
+
if item.t == 'Strong' then
|
|
17
|
+
is_bold = true
|
|
18
|
+
content_text = pandoc.utils.stringify(item.content)
|
|
19
|
+
break
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
local bold_attr = ''
|
|
24
|
+
if is_bold then
|
|
25
|
+
bold_attr = ' b="1"'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
-- Return raw OOXML span with color
|
|
29
|
+
local ooxml = string.format(
|
|
30
|
+
'<a:r><a:rPr%s><a:solidFill><a:srgbClr val="%s"/></a:solidFill></a:rPr><a:t>%s</a:t></a:r>',
|
|
31
|
+
bold_attr, color, content_text
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
return pandoc.RawInline('openxml', ooxml)
|
|
35
|
+
end
|
|
36
|
+
return elem
|
|
37
|
+
end
|
package/dist/lib/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../lib/schema.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,UAAU,iBAAiB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,UAAU,gBAAgB;IACxB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,QAAQ,EAAE,iBAAiB,EAAE,CAAC;CAC/B;AAED;;GAEG;AACH,UAAU,MAAM;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAA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U,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,MAwM3B,CAAC;AA6HF;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,gBAAgB,CAkDhF;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE;IAAE,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAAC,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAAC,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;CAAE,GACjG,MAAM,CAuBR"}
|
package/dist/lib/schema.js
CHANGED
|
@@ -168,6 +168,40 @@ export const revYamlSchema = {
|
|
|
168
168
|
},
|
|
169
169
|
additionalProperties: true,
|
|
170
170
|
},
|
|
171
|
+
macros: {
|
|
172
|
+
type: 'array',
|
|
173
|
+
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.',
|
|
174
|
+
items: {
|
|
175
|
+
type: 'object',
|
|
176
|
+
properties: {
|
|
177
|
+
name: {
|
|
178
|
+
type: 'string',
|
|
179
|
+
description: 'Macro command name without leading backslash, e.g. "tofill" for \\tofill{...}',
|
|
180
|
+
pattern: '^[A-Za-z][A-Za-z0-9]*$',
|
|
181
|
+
},
|
|
182
|
+
default: {
|
|
183
|
+
type: 'object',
|
|
184
|
+
description: 'Default rendering rules across formats',
|
|
185
|
+
properties: {
|
|
186
|
+
color: { type: 'string', pattern: '^[0-9A-Fa-f]{6}$' },
|
|
187
|
+
bold: { type: 'boolean' },
|
|
188
|
+
italic: { type: 'boolean' },
|
|
189
|
+
bracket: { type: 'boolean', default: true },
|
|
190
|
+
prefix: { type: 'string' },
|
|
191
|
+
suffix: { type: 'string' },
|
|
192
|
+
},
|
|
193
|
+
additionalProperties: false,
|
|
194
|
+
},
|
|
195
|
+
formats: {
|
|
196
|
+
type: 'object',
|
|
197
|
+
description: 'Per-format overrides (keys: docx, pdf, latex, html, ...)',
|
|
198
|
+
additionalProperties: true,
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
required: ['name'],
|
|
202
|
+
additionalProperties: false,
|
|
203
|
+
},
|
|
204
|
+
},
|
|
171
205
|
},
|
|
172
206
|
additionalProperties: true,
|
|
173
207
|
};
|