Implementation of the Cooklang spec.
Summary
Functions
Parses a Cooklang recipe.
Functions
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"}