diff --git a/src/Parser.ts b/src/Parser.ts index a58e332..829988c 100644 --- a/src/Parser.ts +++ b/src/Parser.ts @@ -122,6 +122,7 @@ export default class Parser { parseQuantity(groups.mIngredientQuantity) ?? this.defaultIngredientAmount, units: parseUnits(groups.mIngredientUnits) ?? this.defaultUnits, + ...(groups.mIngredientPreparation ? { preparation: groups.mIngredientPreparation } : null), }; if (this.includeStepNumber) ingredient.step = stepNumber; diff --git a/src/Recipe.ts b/src/Recipe.ts index 4ffc680..7e9c707 100644 --- a/src/Recipe.ts +++ b/src/Recipe.ts @@ -55,6 +55,7 @@ export default class Recipe { stepStr += '{'; if (item.quantity) stepStr += item.quantity; if ('units' in item && item.units) stepStr += '%' + item.units; + if ('preparation' in item && item.preparation) stepStr += `(${item.preparation})` stepStr += '}'; } } diff --git a/src/cooklang.ts b/src/cooklang.ts index 23fb908..dae28c5 100644 --- a/src/cooklang.ts +++ b/src/cooklang.ts @@ -8,6 +8,7 @@ export interface Ingredient { name: string; quantity: string | number; units: string; + preparation?: string; step?: number; } diff --git a/src/tokens.ts b/src/tokens.ts index 80b9164..efc3dde 100644 --- a/src/tokens.ts +++ b/src/tokens.ts @@ -1,6 +1,6 @@ const metadata = /^>>\s*(?.+?):\s*(?.+)/; -const multiwordIngredient = /@(?[^@#~[]+?)\{(?[^]*?)(?:%(?[^}]+?))?\}/; +const multiwordIngredient = /@(?[^@#~[]+?)\{(?[^]*?)(?:%(?[^}]+?))?\}(\((?[^]*?)\))?/; const singleWordIngredient = /@(?[^\s\t\p{Zs}\p{P}]+)/; const multiwordCookware = /#(?[^@#~[]+?)\{(?.*?)\}/; diff --git a/tests/custom.yaml b/tests/custom.yaml index 5aab04c..6158af5 100644 --- a/tests/custom.yaml +++ b/tests/custom.yaml @@ -198,3 +198,16 @@ tests: value: "step" metadata: "source": "example.com" + + testShortHandPreparation: + source: | + @onion{1}(peeled and finely chopped) + result: + steps: + - + - type: ingredient + quantity: 1 + units: "" + name: "onion" + preparation: "peeled and finely chopped" + metadata: []