cooklang / cooklang-ts

Lightweight Cooklang parser implemented in TypeScript
https://cooklang.github.io/cooklang-ts/
MIT License
75 stars 7 forks source link

[BUG] Adding bracket in metadata parses as shoppingList #19

Closed bpevs closed 11 months ago

bpevs commented 1 year ago

Describe the bug Small issue, but if there is a [ in metadata, we parse a recipe as a shopping-list. I see this as a minor bug, but want to double-check it's unexpected before I put in any work to make a fix.

To Reproduce Steps to reproduce the behavior:

// can ignore import syntax; this is standard usage via Deno
import { Parser } from 'npm:@cooklang/cooklang-ts'; 

const parser = new Parser()

console.log(parser.parse(`
>> source: https://www.youtube.com/watch?v=oTyVtAAKPRo
>> tags: [ breakfast ]
>> description: It's scrambled egg, with kimchi, and miso soup
>> servings: 1

Crack @eggs{2} into a #bowl, and beat with chopsticks

Make @Kombu broth (or dashi)

Heat a #small pan{} to high heat with #cooking oil{}

Slowly stir eggs onto pan, cook for about ~{10-15%sec}, then remove and add @sesame oil{} and @kimchi

Stir @miso paste{} into kombu broth, and bring to boil

Pour the soup into the egg-stirring bowl, and top with chopped @scallions

`))

this will produce a result of:

{
  ingredients: [],
  cookwares: [],
  metadata: { source: "https://www.youtube.com/watch?v=oTyVtAAKPRo", tags: "" },
  steps: [],
  shoppingList: {
    " breakfast ": [
      {
        name: ">> description: It's scrambled egg, with kimchi, and miso soup",
        synonym: ""
      },
      { name: ">> servings: 1", synonym: "" }
    ]
  }
}

Expected behavior

Should parse as a recipe (with ingredients, cookwares, and steps instead of `shoppingList:

{
  ingredients: [
    { type: "ingredient", name: "eggs", quantity: 2, units: "" },
    { type: "ingredient", name: "Kombu", quantity: "some", units: "" },
    ...
    {
      type: "ingredient",
      name: "scallions",
      quantity: "some",
      units: ""
    }
  ],
  cookwares: [
    { type: "cookware", name: "bowl,", quantity: 1 },
    { type: "cookware", name: "small pan", quantity: 1 },
    { type: "cookware", name: "cooking oil", quantity: 1 }
  ],
  metadata: {
    source: "https://www.youtube.com/watch?v=oTyVtAAKPRo",
    tags: "[ breakfast ]",
    description: "It's scrambled egg, with kimchi, and miso soup",
    servings: "1"
  },
  shoppingList: {},
...
}
ThatTSGuy commented 11 months ago

Fixed in b95cfd71c45cc83363aea287926445f3cea394ed.

Thanks for contributing!