Skip to content

Commit b894caa

Browse files
claude: knitr as discovery engine
1 parent a66cfbe commit b894caa

4 files changed

Lines changed: 249 additions & 179 deletions

File tree

packages/quarto-types/src/quarto-api.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ export interface PreviewServer {
7878
stop: () => Promise<void>;
7979
}
8080

81+
/**
82+
* Temporary context for managing temporary files and directories
83+
*/
84+
export interface TempContext {
85+
/** Create a temporary directory and return its path */
86+
createDir: () => string;
87+
/** Clean up all temporary resources */
88+
cleanup: () => void;
89+
/** Register a cleanup handler */
90+
onCleanup: (handler: VoidFunction) => void;
91+
}
92+
8193
/**
8294
* Global Quarto API interface
8395
*/
@@ -600,6 +612,13 @@ export interface QuartoAPI {
600612
* @param handler - Function to run on cleanup (can be async)
601613
*/
602614
onCleanup: (handler: () => void | Promise<void>) => void;
615+
616+
/**
617+
* Get global temporary context for managing temporary files and directories
618+
*
619+
* @returns Global TempContext instance
620+
*/
621+
tempContext: () => TempContext;
603622
};
604623

605624
/**
@@ -659,6 +678,28 @@ export interface QuartoAPI {
659678
* @param options - Post-processing options including output path and preserve map
660679
*/
661680
postProcessRestorePreservedHtml: (options: PostProcessOptions) => void;
681+
682+
/**
683+
* Convert line/column position to character index
684+
*
685+
* @param text - Text to search in
686+
* @returns Function that converts position to index
687+
*/
688+
lineColToIndex: (
689+
text: string,
690+
) => (position: { line: number; column: number }) => number;
691+
692+
/**
693+
* Create a handler for executing inline code
694+
*
695+
* @param language - Programming language identifier
696+
* @param exec - Function to execute code expression
697+
* @returns Handler function that processes code strings
698+
*/
699+
executeInlineCodeHandler: (
700+
language: string,
701+
exec: (expr: string) => string | undefined,
702+
) => (code: string) => string;
662703
};
663704

664705
/**

src/core/quarto-api.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ import {
6666
*/
6767
export type { PreviewServer };
6868

69+
/**
70+
* Temporary context for managing temporary files and directories
71+
*/
72+
export type { TempContext };
73+
6974
/**
7075
* Global Quarto API interface
7176
*/
@@ -232,6 +237,7 @@ export interface QuartoAPI {
232237
cwd?: string;
233238
}) => PreviewServer;
234239
onCleanup: (handler: () => void | Promise<void>) => void;
240+
tempContext: () => TempContext;
235241
};
236242

237243
/**
@@ -249,6 +255,11 @@ export interface QuartoAPI {
249255
lines: (text: string) => string[];
250256
trimEmptyLines: (lines: string[], trim?: "leading" | "trailing" | "all") => string[];
251257
postProcessRestorePreservedHtml: (options: PostProcessOptions) => void;
258+
lineColToIndex: (text: string) => (position: { line: number; column: number }) => number;
259+
executeInlineCodeHandler: (
260+
language: string,
261+
exec: (expr: string) => string | undefined
262+
) => (code: string) => string;
252263
};
253264

254265
/**
@@ -294,8 +305,11 @@ import type { ProcessResult } from "../core/process-types.ts";
294305
import { asYamlText } from "../core/jupyter/jupyter-fixups.ts";
295306
import { breakQuartoMd } from "../core/lib/break-quarto-md.ts";
296307
import type { QuartoMdChunks, QuartoMdCell } from "../core/lib/break-quarto-md.ts";
297-
import { lines, trimEmptyLines } from "../core/lib/text.ts";
308+
import { lines, trimEmptyLines, lineColToIndex } from "../core/lib/text.ts";
298309
import { md5HashSync } from "../core/hash.ts";
310+
import { executeInlineCodeHandler } from "../core/execute-inline.ts";
311+
import { globalTempContext } from "../core/temp.ts";
312+
import type { TempContext } from "../core/temp-types.ts";
299313

300314
/**
301315
* Global Quarto API implementation
@@ -393,6 +407,7 @@ export const quartoAPI: QuartoAPI = {
393407
execProcess,
394408
runExternalPreviewServer,
395409
onCleanup,
410+
tempContext: globalTempContext,
396411
},
397412

398413
markdown: {
@@ -404,6 +419,8 @@ export const quartoAPI: QuartoAPI = {
404419
lines,
405420
trimEmptyLines,
406421
postProcessRestorePreservedHtml,
422+
lineColToIndex,
423+
executeInlineCodeHandler,
407424
},
408425

409426
crypto: {

src/execute/engine.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { dirAndStem } from "../core/path.ts";
1717
import { metadataAsFormat } from "../config/metadata.ts";
1818
import { kBaseFormat, kEngine } from "../config/constants.ts";
1919

20-
import { knitrEngine } from "./rmd.ts";
20+
import { knitrEngineDiscovery } from "./rmd.ts";
2121
import { jupyterEngineDiscovery } from "./jupyter/jupyter.ts";
2222
import { ExternalEngine } from "../resources/types/schema-types.ts";
2323
import { kMdExtensions, markdownEngineDiscovery } from "./markdown.ts";
@@ -52,8 +52,8 @@ export function executionEngine(name: string) {
5252
return kEngines.get(name);
5353
}
5454

55-
// Register the standard engines
56-
registerExecutionEngine(knitrEngine);
55+
// Register the standard engines with discovery interface
56+
registerExecutionEngine(knitrEngineDiscovery as unknown as ExecutionEngine);
5757

5858
// Register jupyter engine with discovery interface
5959
registerExecutionEngine(jupyterEngineDiscovery as unknown as ExecutionEngine);

0 commit comments

Comments
 (0)