This page provides a high-level introduction to Quarto CLI's architecture and its major subsystems. It explains how the system is organized into layers, how components interact, and the primary execution flows. For detailed information about specific subsystems, see:
Quarto CLI is a scientific and technical publishing system that converts computational documents (.qmd, .ipynb, .Rmd, .md) into various output formats (HTML, PDF, DOCX, presentations, etc.). It is built on Pandoc and written primarily in TypeScript, running on Deno.
The system orchestrates multiple subsystems to:
Sources: README.md1-30 src/quarto.ts1-240
The following diagram shows the major architectural layers and how they interact, using actual code entities from the codebase:
Sources: src/quarto.ts122-240 src/command/render/cmd.ts23-28 src/command/render/render.ts66-434 src/project/project-context.ts139-573
The system is built around several key TypeScript interfaces that define the data structures flowing through the pipeline:
The ProjectContext interface (src/project/types.ts54-115) is the central data structure for project-level operations:
| Field | Type | Purpose |
|---|---|---|
dir | string | Project root directory |
config | ProjectConfig | Merged configuration from _quarto.yml and profiles |
files | ProjectFiles | Input files, resources, config files |
engines | string[] | Execution engines used in the project |
fileMetadata() | function | Resolves metadata for a specific file |
formatExtras() | function | Project-level format customization |
environment() | function | Execution environment configuration |
The Format interface (src/config/types.ts421-457) represents a resolved output format:
| Field | Type | Purpose |
|---|---|---|
identifier | FormatIdentifier | Format name and variants |
pandoc | FormatPandoc | Pandoc-specific options (to, from, template, etc.) |
execute | FormatExecute | Execution options (cache, eval, echo, etc.) |
render | FormatRender | Render options (keep-tex, keep-md, etc.) |
metadata | Metadata | Document metadata |
formatExtras() | function | Format-specific processing hooks |
The RenderContext interface (defined in src/command/render/types.ts) contains all state for rendering a single document:
target: Input file information (source, input, markdown)format: Resolved Format objectoptions: CLI flags and render optionsproject: Optional ProjectContextengine: Execution engine instancelibDir: Library directory for dependenciesSources: src/project/types.ts54-115 src/config/types.ts421-457 src/command/render/types.ts1-100
The following diagram shows how CLI commands flow to their handlers with specific function references:
Commands are registered in src/command/command.ts and imported by the main CLI. Each command is a Cliffy Command instance:
renderCommand: Defined in src/command/render/cmd.ts23-159previewCommand: Defined in src/command/preview/cmd.tscreate, convert, inspect, run, check, install, publish, etc.The main execution flow in quarto() (src/quarto.ts122-217):
pandoc, typst, run)Sources: src/quarto.ts122-217 src/command/render/cmd.ts23-159 src/command/command.ts1-50
The document rendering pipeline is the core flow for transforming input documents to output formats:
render() (src/command/render/render-shared.ts)
Top-level render orchestrator. Determines if rendering a single file or project, resolves formats, and coordinates execution.
renderFiles() (src/command/render/render-files.ts)
Renders multiple files, handling parallel execution, progress reporting, and dependency tracking.
renderPandoc() (src/command/render/render.ts66-434)
Core function that:
PandocOptionsrunPandoc()PandocRenderCompletionrunPandoc() (src/command/render/pandoc.ts309-1265)
Executes Pandoc with:
execProcess()Sources: src/command/render/render.ts66-434 src/command/render/pandoc.ts309-1265 src/command/render/render-shared.ts1-200
Quarto handles two rendering modes with distinct code paths:
When a ProjectContext exists, rendering goes through src/command/render/project.ts242-701:
project.pre-render scripts (src/command/render/project.ts309-367)ProjectType.preRender() (src/project/types/types.ts35-42)ProjectType.supplementRender() (e.g., listing pages)renderFiles() for all input filesoutput-dir (src/command/render/project.ts496-700)ProjectType.postRender() and project.post-render scriptsFor standalone files (src/command/render/render-shared.ts)):
renderFiles() with single file--output-dir specified)Sources: src/command/render/project.ts242-701 src/command/render/render-shared.ts1-200
Configuration is resolved through multiple layers with specific precedence:
Key configuration constants are defined in src/config/constants.ts1-800:
kMetadataFormat: "format" key for output format specificationkProjectType: "type" key for project typekProjectOutputDir: "output-dir" keykExecuteEnabled, kCache, kFreeze, kEval, kEchokKeepMd, kKeepTex, kCodeFold, kFigAlignkTo, kFrom, kTemplate, kToc, kNumberSectionsSources: src/config/constants.ts1-800 src/project/project-context.ts139-573 src/command/render/render-contexts.ts
Extensions integrate at multiple points:
_extensions/ directoriesdashboard, custom project templates)Extensions contribute via the Extension interface:
contributes.project: Project configurationcontributes.formats: Format definitionscontributes.filters: Lua filter pathscontributes.shortcodes: Shortcode definitionsSources: src/extension/extension.ts1-500 src/project/project-context.ts219-225
| Entry Point | Location | Purpose |
|---|---|---|
quarto() | src/quarto.ts122-217 | Main CLI entry point |
render() | src/command/render/render-shared.ts | Top-level render orchestrator |
renderProject() | src/command/render/project.ts242-701 | Project rendering with hooks |
renderFiles() | src/command/render/render-files.ts | Multi-file rendering |
runPandoc() | src/command/render/pandoc.ts309-1265 | Pandoc execution |
projectContext() | src/project/project-context.ts139-573 | Project context resolution |
executionEngine() | src/execute/engine.ts | Engine resolution |
serveProject() | src/command/preview/preview.ts | Preview server |
Sources: src/quarto.ts1-240 src/command/render/pandoc.ts1-1265 src/project/project-context.ts1-1000
Refresh this wiki
This wiki was recently refreshed. Please wait 1 day to refresh again.