From fff29990d069116349121901504c4ac3706f62d6 Mon Sep 17 00:00:00 2001 From: Tyler Date: Tue, 9 Jul 2024 20:53:42 -0400 Subject: [PATCH] fix: Support ingredients that don't start with `-` (#116) --- src/main.ts | 12 +++++++++--- src/recipe/ingredients.ts | 8 ++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main.ts b/src/main.ts index e351378..f5e8e48 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,8 +19,6 @@ export default class MealPlugin extends Plugin { await initWasm(wasmData); - this.ctx.loadRecipes(undefined); - this.registerEvent( this.app.vault.on('create', (file) => { this.ctx.loadRecipes(file); @@ -92,9 +90,17 @@ export default class MealPlugin extends Plugin { if (get(this.ctx.settings).debugMode) { console.debug('Debug mode enabled'); - this.addCommand({ id: 'reload-recipes', name: 'Reload all recipes' }); + this.addCommand({ + id: 'reload-recipes', + name: 'Reload all recipes', + callback: () => { + this.ctx.loadRecipes(undefined); + }, + }); } + this.ctx.loadRecipes(undefined); + console.info('obisidan-meals plugin loaded'); } diff --git a/src/recipe/ingredients.ts b/src/recipe/ingredients.ts index 11eed9a..7455467 100644 --- a/src/recipe/ingredients.ts +++ b/src/recipe/ingredients.ts @@ -107,8 +107,12 @@ function parseIngredientsRecipemd(ctx: Context, content: string): Ingredient[] { function ParseIngredient(ctx: Context, content: string): Ingredient { // Parse the ingredient line - const linePrefix = '- '; - let ingredientContent = content.substring(content.indexOf(linePrefix) + linePrefix.length); + const linePrefix = '-'; + const prefixIndex = content.indexOf(linePrefix); + let ingredientContent = content; + if (prefixIndex >= 0) { + ingredientContent = ingredientContent.substring(prefixIndex).trim(); + } const doAdvancedParse = get(ctx.settings).advancedIngredientParsing;