# `CooklangParser`
[🔗](https://github.com/MikaelFangel/cooklang_parser/blob/v0.1.0/lib/cooklang_parser.ex#L1)

Implementation of the Cooklang spec.

# `parse`

```elixir
@spec parse(String.t()) :: {:ok, keyword()} | {:error, String.t()}
```

Parses a Cooklang recipe.

## Examples

    iex> CooklangParser.parse("Add @salt and @ground black pepper{1/2%tsp}.")
    {:ok,
     [
       step: [
         text: "Add ",
         ingredient: [name: "salt"],
         text: " and ",
         ingredient: [name: "ground black pepper", quantity: 0.5, unit: "tsp"],
         text: "."
       ]
     ]}

    iex> CooklangParser.parse("Fry the @onion{1}(diced) in a #pan{} for ~{5%minutes}.")
    {:ok,
     [
       step: [
         text: "Fry the ",
         ingredient: [name: "onion", quantity: 1, preparation: "diced"],
         text: " in a ",
         cookware: [name: "pan"],
         text: " for ",
         timer: [quantity: 5, unit: "minutes"],
         text: "."
       ]
     ]}

    iex> CooklangParser.parse("---\nservings: 2\n---\n= Sauce\nSimmer. -- stir often")
    {:ok,
     [
       metadata: %{"servings" => 2},
       section: "Sauce",
       step: [text: "Simmer. ", comment: "stir often"]
     ]}

    iex> CooklangParser.parse("---\ntitle: [unclosed\n---")
    {:error, "invalid YAML front matter: Unfinished flow collection"}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
