Skip to content

Commit

Permalink
fix: Support ingredients that don't start with - (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmayoff authored Jul 10, 2024
1 parent ce81bc5 commit fff2999
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
}

Expand Down
8 changes: 6 additions & 2 deletions src/recipe/ingredients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit fff2999

Please sign in to comment.