This page provides a high-level overview of the Quarto CLI architecture, explaining its purpose as a document processing and publishing system and describing how major components interact to transform computational documents into various output formats.
For detailed information about specific subsystems, see:
Sources:
Quarto is a scientific publishing system that transforms computational documents (.qmd, .ipynb, .Rmd) into publishable outputs (HTML, PDF, DOCX, presentations, books, and websites). The system is built around a layered architecture with clear separation of concerns:
Architectural Layers:
Core Design Principles:
The system's modularity allows components to be developed, tested, and understood independently while maintaining clear interfaces between layers.
Sources:
This diagram shows the main code entities and how they interact during a typical render operation:
Key Component Interfaces:
| Component | Key Methods/Properties | Responsibility |
|---|---|---|
ProjectContext | dir, config, files, engines | Holds project-level configuration and file lists |
ExecutionEngineInstance | .execute(), .dependencies(), .postprocess() | Runs code and produces markdown output |
Format | pandoc, render, execute, metadata, formatExtras() | Defines all aspects of output format configuration |
ExecuteResult | markdown, includes, metadata, supporting | Contains all outputs from code execution |
PandocOptions | source, format, markdown, args, metadata | Packages all inputs needed for pandoc execution |
RenderedFile | input, file, format, supporting, resourceFiles | Describes a single rendered output file |
RenderResult | files[], context, baseDir, outputDir | Aggregates results from rendering operation |
Sources:
This diagram shows the concrete functions and data structures involved in transforming a source document to output:
Pipeline Stages:
| Stage | Key Functions | Input | Output |
|---|---|---|---|
| Engine Selection | fileExecutionEngine() | File path + extension | ExecutionEngineInstance |
| Target Creation | engine.target() | File path + markdown | ExecutionTarget with kernelspec |
| Code Execution | engine.execute() | ExecutionTarget + Format | ExecuteResult with markdown |
| Format Resolution | metadataAsFormat() | Metadata + format name | Format object |
| Pandoc Prep | generateDefaults(), filterParamsJson() | Format + ExecuteResult | Pandoc defaults + env vars |
| Pandoc Execution | execProcess() with pandocBinaryPath() | Markdown + defaults + filters | Raw output file |
| Post-Processing | htmlPostprocessors[] | Output HTML | Modified HTML with dependencies |
| Finalization | recipe.complete() | Output + supporting files | RenderedFile |
Sources:
The execution engine system uses a discovery pattern where each engine declares what file types and languages it handles.
Key Interfaces:
Engine Discovery Flow:
| Step | Function | Location | Behavior |
|---|---|---|---|
| 1. Registration | executionEngines | engine.ts50-100 | Returns array of all available engines |
| 2. File Claim | fileExecutionEngine() | engine.ts200-250 | Checks each engine's claimsFile() method |
| 3. Language Claim | claimsLanguage() | Engine implementations | Jupyter claims "julia", Knitr claims "r" |
| 4. Instance Launch | engine.launch() | jupyter.ts300-400 rmd.ts100-200 | Creates engine instance with project context |
| 5. Execution | instance.execute() | Engine instance | Runs code, returns ExecuteResult |
Engine Implementations:
kJupyterEngine): Manages Python server at execute/jupyter/jupyter.ts100-500 communicates via WebSocket, handles kernelspecskKnitrEngine): Spawns R process at execute/rmd.ts100-300 uses hooks from resources/rmd/hooks.R1-500kMarkdownEngine): No-op execution for static markdown at execute/markdown.tsSources:
Quarto uses a schema-driven configuration system that generates TypeScript types, JSON schemas, and Zod validators from YAML definitions.
Schema Pipeline:
| Stage | Input | Output | Location |
|---|---|---|---|
| Definition | YAML schema files | Schema objects | resources/schema/definitions.yml |
| TS Generation | Schema objects | TypeScript interfaces | Generated schema-types.ts |
| Zod Generation | Schema objects | Runtime validators | Generated zod/schema-types.ts |
| JSON Schema | Schema objects | JSON Schema | json-schemas.json |
| Intelligence | Schema + docs | Editor completions | yaml-intelligence-resources.json |
Configuration Hierarchy:
Key Configuration Constants:
Configuration keys are defined in config/constants.ts1-300 as exported constants:
kMetadataFormat, kBaseFormat, kTargetFormatkEngine, kEval, kEcho, kOutput, kCache, kFreezekKeepMd, kKeepTex, kCodeFold, kFigAlignkProjectType, kProjectOutputDir, kProjectLibDirConfiguration Resolution:
The metadataAsFormat() function at config/metadata.ts merges configuration from:
_quarto.ymlSources:
The ProjectContext serves as the central coordination point for multi-document projects.
Project Context Structure:
Project Type Implementations:
| Type | Constant | Implementation | Key Features |
|---|---|---|---|
| Website | kWebsite | website/website.ts | Navigation, search, listings, sitemap |
| Book | kBook | book/book.ts | Chapters, cross-references, single/multi-file |
| Default | kDefault | project-default.ts | Basic project with no special structure |
Project Context Creation:
The projectContext() function at project-context.ts138-250 performs:
_quarto.ymlreadAndValidateYamlFromFile()initializeProfileConfig()mergeExtensionMetadata()projectType().create() for type-specific setup.env files via dotenvSetVariables()Project Rendering Flow:
The renderProject() function at render/project.ts1-300 orchestrates:
kProjectPreRender configurationrenderFiles()kProjectPostRender configurationSources:
Formats define how documents are rendered and what features are available.
Format Resolution Process:
Format Structure:
The Format interface at config/types.ts100-300 contains:
pandoc: Options passed directly to pandoc (output format, template, variables)render: Rendering behavior (kKeepMd, kKeepTex, kCodeFold, etc.)execute: Execution options (kEval, kEcho, kCache)language: Localization strings (kTocTitleDocument, kCalloutTipCaption)metadata: Additional metadata forwarded to outputformatExtras: Function returning additional resources, filters, postprocessorsBuilt-in Formats:
| Format | Base | Key Features | Implementation |
|---|---|---|---|
html | HTML5 | Bootstrap, grid layouts, code tools | format/html/ |
revealjs | HTML5 | Slides, transitions, plugins | format/html/format-html-revealjs.ts |
pdf | LaTeX | Academic typesetting, cross-refs | format/pdf/ |
docx | OpenXML | Word documents, reference doc | Pandoc built-in |
typst | Typst | Modern typesetting | format/typst/ |
ipynb | Notebook | Jupyter notebook output | format/ipynb/ |
Format Extras Pattern:
Format extras allow formats to inject additional resources:
Extras are returned by the optional format.formatExtras() function, called at pandoc.ts525-573 and merged into the rendering pipeline.
Sources:
Lua filters transform the Pandoc AST during rendering. Quarto's filter system is organized into phases.
Filter Registration:
The quartoFilters() function at render/filters.ts100-400 returns filter specifications:
Filter Phases:
Filters are organized by their at position (from resources/schema/definitions.yml40-55):
| Phase | Timing | Purpose | Key Filters |
|---|---|---|---|
pre-ast | Before AST loaded | Early transformation | User extensions |
post-ast | After AST loaded | AST preprocessing | User extensions |
pre-quarto | Before Quarto filters | Setup | User extensions |
| Quarto Filters | Main processing | Cross-refs, layouts, callouts | Built-in filters |
post-quarto | After Quarto filters | Customization | User extensions |
pre-render | Before pandoc write | Format prep | User extensions |
post-render | After pandoc write | Post-processing | User extensions |
citeproc | Citation processing | Bibliography | Pandoc built-in |
Key Quarto Filters:
Filter parameters are built at filters.ts200-600 and passed via the QUARTO_FILTER_PARAMS environment variable:
crossrefFilterParams() include crossref metadata, numbering optionslayoutFilterParams() include figure/table layout settingsFilter Parameter Injection:
At pandoc.ts324-358 filter parameters are:
QUARTO_FILTER_PARAMS environment variableSources:
The complete rendering pipeline for a .qmd file:
quarto render document.qmdprojectContext() finds _quarto.yml and loads configurationfileExecutionEngine() selects Jupyter or Knitr based on metadataExecuteResult with markdown and metadatametadataAsFormat() merges format configurationgenerateDefaults() creates pandoc defaults filequartoFilters() builds filter chain and parametersrunPandoc() invokes pandoc with filtersRenderResult returned with file paths and metadataKey Data Structures:
ExecutionTarget: Input file info, metadata, engine selectionExecuteResult: Markdown output, metadata, includes, supporting filesPandocOptions: All options needed for pandoc executionRunPandocResult: Pandoc output, postprocessors, resourcesRenderedFile: Final output path, supporting files, resourcesRenderResult: Collection of rendered files with project contextSources:
Refresh this wiki
This wiki was recently refreshed. Please wait 1 day to refresh again.