Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/command/check/check-render.ts
6450 views
1
/*
2
* check-render.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
7
import { render } from "../render/render-shared.ts";
8
import type { RenderServiceWithLifetime } from "../render/types.ts";
9
10
/**
11
* Options for test-rendering a document during check operations
12
*/
13
export interface CheckRenderOptions {
14
/** Markdown content to render */
15
content: string;
16
/** Language identifier (e.g., "python", "r", "julia") */
17
language: string;
18
/** Render services for temp file management and rendering */
19
services: RenderServiceWithLifetime;
20
}
21
22
/**
23
* Result of a check render operation
24
*/
25
export interface CheckRenderResult {
26
/** Whether the render succeeded */
27
success: boolean;
28
/** Error if render failed */
29
error?: Error;
30
}
31
32
/**
33
* Test-render a document for validation during check operations
34
*
35
* Creates a temporary file with the provided content, renders it with
36
* appropriate engine settings, and returns success/failure status.
37
* Used by checkInstallation implementations to verify engines work.
38
*/
39
export async function checkRender(
40
options: CheckRenderOptions,
41
): Promise<CheckRenderResult> {
42
const { content, services } = options;
43
44
// Create temporary file
45
const tempFile = services.temp.createFile({ suffix: ".qmd" });
46
47
// Write content to file
48
Deno.writeTextFileSync(tempFile, content);
49
50
// Render with appropriate flags
51
const result = await render(tempFile, {
52
services,
53
flags: { quiet: true, executeDaemon: 0 },
54
});
55
56
// Return simplified result
57
return {
58
success: !result.error,
59
error: result.error,
60
};
61
}
62
63