fix: unparsed ingredients poorly formatted when fed to NLP parser (#7086)

Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
Co-authored-by: Michael Genson <genson.michael@gmail.com>
This commit is contained in:
Gabriel Barbosa Soares
2026-03-26 20:19:10 +00:00
committed by GitHub
parent 449e3baa07
commit 4dd8d836e1
3 changed files with 133 additions and 3 deletions

View File

@@ -142,8 +142,24 @@ export function useIngredientTextParser() {
return sanitizeIngredientHTML(text);
};
function ingredientToParserString(ingredient: RecipeIngredient): string {
if (ingredient.originalText) {
return ingredient.originalText;
}
// If the ingredient has no unit and no food, it's unparsed — the note
// contains the full ingredient text. Using parseIngredientText would
// incorrectly prepend the quantity (e.g. "1 1/2 cup apples").
if (!ingredient.unit && !ingredient.food) {
return ingredient.note || "";
}
return parseIngredientText(ingredient, 1, false) ?? "";
}
return {
useParsedIngredientText,
parseIngredientText,
ingredientToParserString,
};
}