-
Notifications
You must be signed in to change notification settings - Fork 347
/
Copy pathtypes.ts
288 lines (246 loc) · 6.64 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
* types.ts
*
* Copyright (C) 2020-2022 Posit Software, PBC
*/
import { Document } from "../../core/deno-dom.ts";
import {
Format,
PandocFlags,
QuartoFilter,
QuartoFilterEntryPoint,
} from "../../config/types.ts";
import {
ExecuteResult,
ExecutionEngine,
ExecutionTarget,
} from "../../execute/types.ts";
import { Metadata } from "../../config/types.ts";
import { ProjectContext } from "../../project/types.ts";
import { TempContext } from "../../core/temp-types.ts";
import { ExtensionContext } from "../../extension/types.ts";
import { kPositionedRefs } from "../../config/constants.ts";
import { NotebookContext } from "../../render/notebook/notebook-types.ts";
import { Lifetime } from "../../core/lifetimes.ts";
// options for render
export interface RenderOptions {
services: RenderServices;
flags?: RenderFlags;
pandocArgs?: string[];
progress?: boolean;
useFreezer?: boolean;
devServerReload?: boolean;
previewServer?: boolean;
setProjectDir?: boolean;
forceClean?: boolean;
echo?: boolean;
warning?: boolean;
quietPandoc?: boolean;
}
export interface RenderServices {
temp: TempContext;
extension: ExtensionContext;
notebook: NotebookContext;
}
export interface RenderServiceWithLifetime extends RenderServices {
cleanup: () => void;
lifetime?: Lifetime;
}
// context for render
export interface RenderContext {
target: ExecutionTarget;
options: RenderOptions;
engine: ExecutionEngine;
format: Format;
libDir: string;
project: ProjectContext;
active: boolean;
}
export interface RunPandocResult {
inputMetadata: Metadata;
inputTraits: PandocInputTraits;
resources: string[];
postprocessors?: Array<
(
output: string,
) => Promise<{ supporting?: string[]; resources?: string[] } | void>
>;
htmlPostprocessors: Array<HtmlPostProcessor>;
htmlFinalizers?: Array<(doc: Document) => Promise<void>>;
}
export interface PandocInputTraits {
[kPositionedRefs]?: boolean;
}
export type HtmlPostProcessor = (
doc: Document,
options: {
inputMetadata: Metadata;
inputTraits: PandocInputTraits;
renderedFormats: RenderedFormat[];
quiet?: boolean;
},
) => Promise<HtmlPostProcessResult>;
export interface HtmlPostProcessResult {
// Relative paths to resources
resources: string[];
// Supporting files should be absolute paths to the files or directories
supporting: string[];
}
export interface RenderResourceFiles {
globs: string[];
files: string[];
}
export interface RenderResult {
context?: ProjectContext;
baseDir?: string;
outputDir?: string;
files: RenderResultFile[];
error?: Error;
}
export interface RenderResultFile {
input: string;
markdown: string;
format: Format;
file: string;
isTransient?: boolean;
supporting?: string[];
resourceFiles: string[];
supplemental?: boolean;
}
export interface RenderedFile {
input: string;
markdown: string;
format: Format;
file: string;
supporting?: string[];
resourceFiles: RenderResourceFiles;
selfContained: boolean;
isTransient?: boolean; // from recipe, indicates that this file shouldn't be copied (eg to project destination)
}
export interface RenderExecuteOptions {
resolveDependencies?: boolean;
alwaysExecute?: boolean;
}
export interface ExecutedFile {
context: RenderContext;
recipe: OutputRecipe;
executeResult: ExecuteResult;
resourceFiles: string[];
}
export interface PandocRenderer {
onFilterContexts: (
file: string,
contexts: Record<string, RenderContext>,
files: RenderFile[],
options: RenderOptions,
) => Record<string, RenderContext>;
onBeforeExecute: (format: Format) => RenderExecuteOptions;
onRender: (
format: string,
file: ExecutedFile,
quiet: boolean,
) => Promise<void>;
onPostProcess: (
renderedFormats: RenderedFormat[],
project?: ProjectContext,
) => Promise<void>;
onComplete: (error?: boolean, quiet?: boolean) => Promise<RenderFilesResult>;
}
export interface RenderedFormat {
path: string;
format: Format;
isTransient?: boolean;
}
export interface RenderFile {
path: string;
formats?: string[];
}
export interface RenderFilesResult {
files: RenderedFile[];
error?: Error;
}
// options required to run pandoc
export interface PandocOptions {
// markdown input
markdown: string;
// original source file
source: string;
// output file that will be written
output: string;
// is the keepYaml flag set
keepYaml: boolean;
// mediabag directory
mediabagDir: string;
// lib dir for converstion
libDir: string;
// target format
format: Format;
// command line args for pandoc
args: string[];
// the render services
services: RenderServices;
// extra metadata to merge
metadata?: Metadata;
// optional execution engine
executionEngine?: string;
// optoinal project context
project?: ProjectContext;
// quiet quarto pandoc informational output
quiet?: boolean;
// command line flags (e.g. could be used
// to specify e.g. pdf engine)
flags?: RenderFlags;
// optional offset from file to project dir
offset?: string;
}
// command line flags that we need to inspect
export interface RenderFlags extends PandocFlags {
// quarto flags
outputDir?: string;
siteUrl?: string;
executeDir?: string;
execute?: boolean;
executeCache?: true | false | "refresh";
executeDaemon?: number;
executeDaemonRestart?: boolean;
executeDebug?: boolean;
useFreezer?: boolean;
metadata?: { [key: string]: unknown };
pandocMetadata?: { [key: string]: unknown };
params?: { [key: string]: unknown };
paramsFile?: string;
clean?: boolean;
debug?: boolean;
quiet?: boolean;
version?: string;
}
export interface OutputRecipe {
// --output file that pandoc will produce
output: string;
// are we implementing keepYaml
keepYaml: boolean;
// transformed pandoc args reflecting 'output'
args: string[];
// modifications to format spec
format: Format;
// callback for completing the output recipe (e.g. might run pdflatex, etc.).
// can optionally return an alternate output path. passed the actual
// options used to run pandoc (for deducing e.g. pdf engine options)
complete: (options: PandocOptions) => Promise<string | void>;
// The final output for the recipe (if different than the output itself)
finalOutput?: string;
isOutputTransient?: boolean;
}
export type QuartoFilterSpec = {
// these are filters that will be sent to pandoc directly
quartoFilters: QuartoFilter[];
beforeQuartoFilters: QuartoFilter[];
afterQuartoFilters: QuartoFilter[];
entryPoints: QuartoFilterEntryPoint[];
};
export interface PandocRenderCompletion {
complete: (
outputs: RenderedFormat[],
cleanup?: boolean,
) => Promise<RenderedFile>;
}