Cooklang Specification & Syntax Reference
Just heads up, that not all latest language features supported in the apps yet. You can track progress at https://github.com/orgs/cooklang/projects/4
- About Cooklang
- The .cook Recipe Specification
- Conventions (shopping lists, pantry, scaling, pictures, canonical metadata)
- Advanced
- Projects Which Use Cooklang
- Syntax Highlighting
About Cooklang
Cooklang is the markup language at the center of an open-source ecosystem for cooking and recipe management. In Cooklang, each text file is a recipe written as plain-english instructions with markup syntax to add machine-parsible information about required ingredients, cookware, time, and metadata.
The .cook recipe specification
Below is the specification for defining a recipe in Cooklang.
Ingredients
To define an ingredient, use the @ symbol. If the ingredient's name contains multiple words, indicate the end of the name with {}.
To indicate the quantity of an item, place the quantity inside {} after the name.
To use a unit of an item, such as weight or volume, add a % between the quantity and unit.
Now you can try Cooklang and experiment with a few things in the Cooklang Playground!
Steps
Each paragraph in your recipe file is a cooking step. Separate steps with an empty line.
If you want to force a line break within a step, end the line with a backslash \. The backslash will be replaced with a newline character when rendered.
This will render as multiple lines within a single step.
Comments
You can add comments up to the end of the line to Cooklang text with --.
Or block comments with [- comment text -].
Metadata
Recipes are more than just steps and ingredients—they also include context, such as preparation times, authorship, and dietary relevance. You can add metadata to your recipe using YAML front matter, add --- at the beginning of a file and --- at the end of the front matter block.
Cookware
You can define any necessary cookware with #. Like ingredients, you don't need to use braces if it's a single word.
Timer
You can define a timer using ~.
Timers can have a name too:
Applications can use this name in notifications.
Conventions
Beyond the core language, the Cooklang ecosystem has common conventions for file types (.cook for recipes, .menu for meal plans), shopping list configuration, pantry inventory, recipe scaling, adding pictures, and canonical metadata keys. See conventions.md for details.
Advanced
Notes
To include relevant background, insights, or personal anecdotes that aren't part of the cooking steps, use notes. Start a new line with > and add your story. Applications decide whether to show notes in cooking mode, and how.
Consecutive > lines make one note, and the lines are joined into one paragraph.
A note can use three kinds of Markdown formatting:
| You write | It means |
|---|---|
*text* or _text_ | emphasis, usually shown in italics |
**text** or __text__ | strong emphasis, usually shown in bold |
[text](destination) | a link with the given text |
They follow the rules of CommonMark 0.31.2 for emphasis and inline links. A delimiter with nothing to pair with stays as written, so *Use fine sea salt and * Day-old rice works best keep their asterisk, and _ inside a word (tomato_sauce_v2) is text. Formatting can continue from one line of the note to the next, but not into another note. A destination with spaces goes between < and >, and a title after the destination is ignored. Everything else from Markdown (lists, headings, code, images, HTML) is plain text, as are @, # and ~ inside a note. Formatting is read in notes only: steps, metadata, section names and the notes of ingredients and cookware are unchanged.
A backslash makes the next character plain text: 2\*250 g, \_name\_, \[1\]. Comments are removed before formatting is read, so a -- inside a destination needs escaping too (https://example.com/a\--b).
A parsed note is a list of text runs. Each run has a value and, when it applies, strong, emphasis and link (the destination, as written). Joining the value of every run gives the note's plain text, for places where formatting can't be shown, such as speech, search and notifications.
A destination is untrusted input. Applications open http:, https: and mailto: destinations outside the recipe, and resolve a destination without a scheme (that doesn't start with //) like a recipe reference, opening that recipe if it is in the recipe collection. They don't follow a path that leads outside the collection, and show the text of any other link (javascript:, data:, file:, //example.com, an empty destination, or a path that doesn't resolve) as plain text. See proposal 0022 for the details.
Sections
Some recipes are more complex than others and may include components that need to be prepared separately. In such cases, you can use the section syntax, e.g., ==Dough==. The section name and the = symbols after it are optional, and the number of = symbols does not matter.
Short-hand preparations
Many recipes involve repetitive ingredient preparations, such as peeling or chopping. To simplify this, you can define these common preparations directly within the ingredient reference using shorthand syntax:
Referencing other recipes
You can reference other recipes using the existing @ ingredient syntax. The path is relative to the root of the recipes directory, without the .cook extension:
These preparations should be clearly displayed in the ingredient list, allowing you to get everything ready before you start cooking.
Optional ingredients and cookware
To mark an ingredient or a piece of cookware as optional, put ? straight after the @ or #:
The ? is not part of the name. It works with every form of ingredient and cookware: single word (@?chives), multi-word (@?chilli flakes{}), with a quantity (@?chilli flakes{1%pinch}), and recipe references (@?./sauces/chimichurri{}). It must follow the sigil directly: @? thyme is plain text, and a ? anywhere else, as in Did you add the @salt{}?, is ordinary text.
Optionality belongs to each occurrence, not to the ingredient as a whole, so the same ingredient can be required in one step and optional in another. Required and optional amounts are listed separately instead of being added together:
This recipe needs parmesan 100 g, plus parmesan 50 g marked as optional. Optional components scale exactly like required ones.
Applications should mark optional items wherever ingredients and cookware are listed, leave optional ingredients off a shopping list unless the user chooses them (see shopping lists), and not count a missing optional ingredient as missing when matching recipes against a pantry. An optional recipe reference makes every ingredient of the referenced recipe optional.
Ranges
When a recipe isn't exact, give a range: two numbers joined by a dash.
A range is a number, not text, so it can be scaled, added up and converted like any other quantity. Both ends must be numbers (whole numbers, decimals, fractions or mixed numbers like 1 1/2), and the unit after % applies to both. Spaces around the dash are allowed, so {2 - 3} is the same as {2-3}, and so are the en dash and em dash ({2–3}, {2—3}), which phones and word processors often type in place of -. Anything else stays text, as before: {2-}, {1-2-3}, {2-few} and {1-2 handfuls} are text quantities.
The ends are kept as written: {3-2} starts at 3 and ends at 2 (parsers may warn about it), and {2-2} stays a range.
A range scales by multiplying both ends, so for twice the servings @garlic{2-3%cloves} becomes 4–6 cloves. A locked quantity such as @salt{=1-2%tsp} doesn't scale at all. When the same ingredient appears more than once, ranges add end to end and a plain number adds to both ends: @garlic{2} and @garlic{1-2} need 3–4 garlic. Amounts in different units are listed separately, as for any quantity.
Applications should show a range with its unit once (2–3 cloves, ½–1 tsp), and write it back with a plain - and no spaces. When a range is converted to another unit, the unit is picked for the lower end and the upper end is converted to the same unit. A countdown for a timer range starts at the lower end, so the cook checks early and keeps going if needed. See conventions for ranges in shopping lists and pantry matching.
Projects Which Use Cooklang
- Cooklang playground
- Obsidian plugin
- Official command line application
- Community alternative command line application
- Official iOS application
- Official Android application
Syntax Highlighting
- Emacs
- Nano
- SublimeText
- Vim
- VSCode
- More options: See syntax highlighting documentation.
Roadmap
There's a GitHub board where we show what we're working on and what's next https://github.com/orgs/cooklang/projects/4.