@gram-lang/renderer
Handles rendering of a CompilationResult (or AnalyzedCompilationResult) to Markdown, HTML, a standalone print-ready HTML document, or plain text. If you are building a custom frontend UI in a component framework (React, Vue, Svelte, etc.), you will typically consume the JSON object directly rather than using this package. See the Building a custom UI guide.
toMarkdown / toHTML / toPrintHTML / toText
Section titled “toMarkdown / toHTML / toPrintHTML / toText”toPrintHTML produces a complete, standalone HTML document (with inline <style>, A4 @page rules, and no external dependencies), suitable for PDF export or paper printing. toHTML produces an HTML fragment intended to be embedded in an existing page layout.
toText writes the recipe as plain text, for a terminal or a plain file: a box with the title, the portions and the times, then the shopping list, the cookware, each section (its ingredients, then its numbered steps), the notes and the nutrition. Nothing is escaped and there is no markup; the words come from @gram-lang/i18n. It is the text format of the recipe view (render("recipe", input, "text")), what gram view shows and gram export --format text writes. Colors are up to the surface, through textStyle:
All four formatters use the same underlying traversal (RenderBackend). This guarantees that nutrition summaries, footnotes, gross purchasing mass badges, and unit warning indicators appear consistently whether targeting Markdown, HTML, print, or plain text.
RendererOptions
Section titled “RendererOptions”| Option | Type | Description |
|---|---|---|
icons | RendererIcons | Overrides default icons (see DEFAULT_ICONS below). |
classes | RendererClasses | Overrides CSS class names applied to generated HTML elements (HTML/print only). |
formatFraction | (value: number) => string | Writes every numeric quantity of the recipe views (steps, section ingredients, shopping list) in place of the default: a whole number, a common kitchen fraction (0.5 → "1/2") or a decimal in the lang of the options (1.5 → "1,5" in French). It receives the number only, so it handles the language itself. Standardized masses, kilograms of the shopping list, nutrition values and the run sheet keep the default. |
formatDuration | (minutes: number) => string | Custom duration formatter (defaults to e.g. 90 → "1 h 30 min", in the lang of the options). |
hideStepQty | boolean | Omits ingredient quantities from the step text (shopping and section ingredient lists retain them). By default, all formats display the quantity immediately after each ingredient, alongside its standardized mass when available: flour (250 ml, ~148 g). In HTML, this is rendered as a <span class="step-quantity"> (classes.stepQuantity), with detailed conversion info in its tooltip. |
miseEnPlace | 'perSection' | 'upfront' | 'perDay' | Scheduling strategy followed by the document: preparation immediately before each section ('perSection', default), grouped upfront at recipe start ('upfront'), or at the start of each working day ('perDay'). Determines the total time displayed in the header. The recipe instructions show no temporal schedule: the detailed timeline and required equipment list reside in the run sheet (runSheet). The timeline is computed on the fly from the tasks graph. |
rests | 'shortest' | 'balanced' | 'longest' | Controls resolution for passive timers defined as ranges (~_{12-24h}): minimum duration ('shortest', default), midpoint ('balanced'), or maximum duration ('longest'). Exact passive timers and active timers are unaffected. Governs the same computed times as miseEnPlace. |
comments | 'show' | 'hide' | Shows ('show', default) or leaves out ('hide') the comments of the recipe (// like this): both standalone notes on their own line and inline comments at the end of a line (rendered as footnotes in recipe views). Applies uniformly across all views, including the run sheet. |
bakersMathOnly | boolean | Shows only baker’s percentages, hiding absolute ingredient quantities. |
interactiveScaling | boolean | v1.4.0 Draws a portions stepper in the hero bar of the HTML recipe, whose buttons work only if the page around it handles them. Scale the recipe before rendering it instead: the view shows the scaled portions and the factor (×1.5) by itself. Removed in 2.0.0. |
nutritionBasis | 'auto' | 'total' | 'perPortion' | 'per100g' | Selects the nutrition calculation basis. 'auto' (default) shows per 100 g and per portion side by side (per portion only when portions are declared), with the whole recipe under them, in the HTML, Markdown and text formats alike. |
interactiveNutrition | boolean | v1.4.0 No longer has any effect: the HTML recipe shows every nutrition basis side by side in a table. Removed in 2.0.0. |
lang | string | BCP-47 language tag (e.g. 'en', 'fr') for UI string localization via @gram-lang/i18n. |
renderId | string | Prefix for footnote anchor IDs — prevents ID collisions when rendering multiple recipes on one page. |
textStyle | TextStyle | Plain text only: how to set parts apart, one function per part (title, heading, dim, ingredient, reference, cookware, timer, action), each taking a piece of text and returning it styled, without changing its visible width (terminal colors, for instance). A part left out stays plain, so the renderer never depends on a terminal library. |
width | number | Plain text only: the width of the title box and of the section rules (default 78, DEFAULT_TEXT_WIDTH). |
Settings
Section titled “Settings”Recipe and view settings are defined once here so that every tool built on Gram provides the same options: CLI flags, editor gram.* configuration keys, and playground settings all derive from these descriptors.
| Export | Description |
|---|---|
VIEW_SETTINGS | View presentation settings: miseEnPlace, rests, comments, nutritionBasis, bakersMathOnly, stepQuantities, clock v1.5.0. |
RECIPE_SETTINGS | Analyzer computation settings (all enabled by default): bakersMath, massStandardization, yieldCalculation, nutritionEstimation. |
SETTINGS | Both view and recipe settings combined in a single list. |
parseViewSettings(raw), parseRecipeSettings(raw) | Parse settings from an arbitrary object, falling back to defaults for any missing or unknown key. |
DEFAULT_VIEW_SETTINGS, DEFAULT_RECIPE_SETTINGS | Default values for all view and recipe settings. |
viewSettingsToRendererOptions(settings) | Converts view settings into RendererOptions. An automatic nutrition basis is omitted, so the nutrition table keeps every basis side by side. |
recipeSettingsToAnalyzerOptions(settings) | Converts recipe settings into analyzer options (enableBakersMath, …). |
Each descriptor exposes its key, kind ("view" or "recipe"), type ("choice" with its values, or "flag"), default, description, and validation/parsing methods (accepts(raw), parse(raw)).
DEFAULT_ICONS provides two full icon sets: DEFAULT_ICONS.html (inline Phosphor SVG elements) and DEFAULT_ICONS.md (emojis). They cover all identifiers in RendererIcons (hourglass, timer, thermometer, caretRight, arrowRight, arrowUDownLeft, arrowElbowDownRight, warning, pencilSimple, minus, plus, clock, clockCounterClockwise, fire, knife, scales, package, info). Any icon can be overridden individually via options.icons.
Formatting utilities
Section titled “Formatting utilities”Low-level utilities used internally by formatters are exported to support building custom renderers adhering to language conventions:
formatUsageQuantity v1.5.0
Section titled “formatUsageQuantity ”formatUsageQuantity writes the amount of an ingredient, a reference or a shopping-list entry the one way the views do, from its terms (parts, or qty / unit): as written when Gram changed nothing (1 cup + 1 tbsp), worked out when the recipe is scaled or for a shopping list (2 cup + 2 tbsp, never 34 tbsp; ranges by their bounds). gram shop and gram scale use it too. See scaling sums of quantities.
The run sheet
Section titled “The run sheet”From the RunSheet object returned by runSheet() (@gram-lang/scheduler) and the compiled recipe, the renderer outputs the run sheet in four distinct formats and exposes underlying extraction helpers:
The run sheet for a recipe without an explicit target serving time is obtained via runSheet(compiled.schedule, { graph: compiled.tasks }) (or from layout(...).schedule): days are labeled relatively (D-2, D-1, Day D), time slots represent relative wait durations, and no absolute clock margins are computed.
RunSheetRenderOptions
Section titled “RunSheetRenderOptions”| Option | Type | Description |
|---|---|---|
lang | string | Language code ('en', 'fr') for labels and date formatting. |
roundTo | number | Display only: rounding of times to minute intervals (default: 5). Internal computations remain exact. |
formatDuration | (minutes: number) => string | Custom duration formatter. |
hourCycle v1.5.0 | 'h23' | 'h12' | How times of day are written: 'h23' (default, 13:00) or 'h12' (1:00 PM, its marks in the language of lang). Also read by describeServeTimes() and describeEarliestServe(). prepareViews() resolves it from the clock setting. |
comments | 'show' | 'hide' | Shows (default) or leaves out the comments of the recipe in the steps. When enabled, a standalone note sits beneath its step and an end-of-line note remains within the sentence in parentheses; HTML formatting styles both in small, muted text. |
RunSheetModel
Section titled “RunSheetModel”describeRunSheet() returns:
| Field | Description |
|---|---|
title, subtitle, summary | “Run sheet — Entremets”, “For Saturday, October 17 at 20:00 · 6 portions”, “3 days · 3 visits to the kitchen · 45m of work in all”. |
problems | Contextual diagnostics reported when scheduling constraints could not be met (one descriptive sentence per problem). |
schedule[] | Multi-day schedule summary: one entry per active kitchen visit (kind: 'visit'), background thread ('thread'), and the final service ('serve'), containing day, time, and text. |
days[] | Per-day details: header (heading), time slot (slot), adjusted wait notices (notices), and visits (visits[]), each with slot, anticipation margin (margin), required items (kit[], groups of lines, filled in perDay and upfront modes), the sections to cook (program[]: a section, its steps[] as the recipe numbers them with their action, HTML, Markdown and text, the time it starts (startTime, with a serving time), a continued flag when it goes on from an earlier visit, its source file (origin) when imported, a reference such as steps 1 to 3, and in perSection mode its own kit[] for mise en place), and unattended background tasks (leaving[]). |
events[] | One calendar event per visit (start, end in UTC, title, description), for a plan with a serving time. |
visitKit(), sectionProgram() and sectionSteps()
Section titled “visitKit(), sectionProgram() and sectionSteps()”Three high-level extraction helpers used by the run sheet are exported to simplify custom UI implementations:
The reader’s clock v1.5.0
Section titled “The reader’s clock ”The clock view setting ('auto', '12h', '24h', default 'auto') says how the run sheet and the serving time suggestions write the time of day. It is the reader’s clock, not the recipe’s: 'auto' follows the region of the reader’s locale, which prepareViews() takes as its locale option ('en-US', 'fr-FR'), separate from lang, the language of the words. A locale whose region writes 12 hours (en-US, en-CA, en-AU, en-IN) reads 1:00 PM; any other, a locale without a region ('en') and no locale at all read 13:00. The renderer never guesses the reader: a surface passes their locale (the playground navigator.language, the CLI and the language server systemLocale(process.env, process.platform)). The data stays local ISO (serveAt: "2026-10-11T13:00") whatever the clock.
| Export | Description |
|---|---|
resolveHourCycle(clock, locale) | 'h12' or 'h23': the clock the setting names, else ('auto') the one of locale. |
hourCycleOf(locale) | The clock of a locale, 'h23' when it names no region or cannot be read; a POSIX locale (en_US.UTF-8) is read as its BCP 47 tag. |
systemLocale(env, platform?) | The locale of a machine: the first of LC_ALL, LC_TIME, LANG that is set (C and POSIX name none); on Windows (platform: 'win32'), the runtime’s. |
chooseClock(...choices) | The first clock actually chosen, 'auto' meaning not chosen: chooseClock(flag, projectSetting). |
formatClock(hhmm, hourCycle, lang?) | "13:05" written on a clock: as it is in 24 hours, "1:05 PM" in 12. |
clockFormatOptions(hourCycle) | The Intl.DateTimeFormat options of a time of day on that clock, for a format that also writes a date. |
Nothing is invented: names and quantities are those of the .gram file, and the run sheet writes the steps out as the recipe has them. The mode of the kit (perSection, perDay, upfront) is read from RunSheet.recipes[].miseEnPlace (also carried by RunSheetModel.miseEnPlace): the renderer has no option for it. describeServeTimes() and describeEarliestServe() put the result of findServeTimes() and earliestServe() in words the same way.
Gantt chart (toGanttHTML & attachGanttInteractivity) v1.4.0
Section titled “Gantt chart (toGanttHTML & attachGanttInteractivity) ”GanttRenderOptions
Section titled “GanttRenderOptions”| Option | Type | Description |
|---|---|---|
lang | string | Language code for localized UI strings. |
gapThresholdMinutes | number | Minimum idle period before visual compression applies (default: 60). Infinity disables compression. |
compressedGapSize | number | Virtual minute width to which compressed idle gaps are shrunk (default: 20). |
miseEnPlace | 'perSection' | 'upfront' | 'perDay' | Preparation placement strategy (default: 'perSection'). |
rests | 'shortest' | 'balanced' | 'longest' | Elasticity for range-based passive timers (default: 'shortest'). |
quiet | boolean | Skips the one-time deprecation notice. |
GanttInteractivityOptions
Section titled “GanttInteractivityOptions”| Option | Type | Description |
|---|---|---|
timeMode | 'forward' | 'reverse' | 'target' | Timeline display mode: elapsed time (T+), countdown (T-), or clock time anchored to serve time. |
targetTime | string | Target serve time in "HH:MM" format. |
isCompactMode | boolean | Toggles compact vertical row height. |