🐛 (hopefully) fix markdown in steps

This commit is contained in:
neingeist 2025-06-02 12:06:40 +02:00
parent c48bc068ad
commit 2ac5eebe61
42 changed files with 227 additions and 90 deletions

View file

@ -71,11 +71,14 @@ def format_recipe_to_markdown(recipe):
instructions = recipe['recipeInstructions']
if isinstance(instructions, list):
for i, step in enumerate(instructions, 1):
if isinstance(step, dict):
text = step.get('text', '').strip()
else:
text = str(step).strip()
md.append(f"{i}. {text.replace(chr(10), ' ')}")
assert isinstance(step, dict)
text = step.get('text', '').strip()
# "ingredient-only" steps shouldn't exist, but they do
if not text:
continue
md.append(f"{i}.\n{text}")
else:
for i, line in enumerate(instructions.strip().split('\n'), 1):
if line.strip():