Skip to content

hilli/cooklang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CI - Build and Test

cooklang

Go implementation of a cooklang parser.

Features

  • ✅ Full Cooklang specification compliance
  • 🖼️ Automatic image detection - Auto-discovers recipe images matching filename patterns
  • 📝 Frontmatter CRUD operations - Programmatically edit recipe metadata
  • 🧮 Unit conversion system with metric/imperial/US systems
  • 📋 Shopping list generation from multiple recipes
  • 🎨 Multiple output formats (Cooklang, Markdown, HTML, JSON)
  • 🔧 Extended mode with ingredient/cookware annotations
  • ⚖️ Recipe scaling and ingredient consolidation
  • 🛠️ Comprehensive CLI tool

Usage Examples

The library includes comprehensive, runnable examples demonstrating all major features. See docs/EXAMPLES.md for a complete list.

Quick example:

package main

import (
    "fmt"
    "log"
    "github.com/hilli/cooklang"
)

func main() {
    recipeText := `---
title: Pasta Aglio e Olio
servings: 2
---
Cook @pasta{400%g} in salted water for ~{10%minutes}.
Meanwhile, heat @olive oil{4%tbsp} and sauté @garlic{3%cloves}.
Toss everything together and serve.`

    recipe, err := cooklang.ParseString(recipeText)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Recipe: %s (serves %.0f)\n", recipe.Title, recipe.Servings)
    
    // Get shopping list
    shoppingList, _ := recipe.GetCollectedIngredientsMap()
    for ingredient, quantity := range shoppingList {
        fmt.Printf("- %s: %s\n", ingredient, quantity)
    }
}

Known Usages

Projects using this library:

Using this library? Open a PR to add your project!

Cooklang specification

See the Cooklang specification for details.

Extended Syntax

This parser supports additional syntax extensions beyond the base Cooklang specification:

Ingredient Annotations

Ingredients can have annotations in parentheses to specify preparation notes or state:

@milk{1%l}(cold)

The annotation (cold) is stored as the ingredient's value field.

Cookware Annotations

Similarly, cookware items can have annotations for usage hints:

#pan{}(for frying)

Named Timers

Timers can have descriptive multi-word names:

~roast time{4%hours}

Comment Preservation

Comments are preserved as a distinct type in the parsed output rather than being discarded:

-- This is a comment

Comments are accessible with type: comment and their text in the value field.

Developing

Prerequisites (Well, not really)

This project uses a Taskfile for convenience. Install by running:

go install tool

Running Tests

Run all tests with:

task test

Test the specification specifically with:

task test-spec

Lint the stuff:

task lint

About

Go implementation of a cooklang parser.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks