Browse Source

Adds intro text

master
sloum 10 months ago
parent
commit
8799281fbc
2 changed files with 38 additions and 3 deletions
  1. +13
    -1
      README.md
  2. +25
    -2
      recipe

+ 13
- 1
README.md View File

@ -8,8 +8,9 @@
```
@ Meta Information
> Intro Text
% Ingredient
> Instruction
: Instruction
* Note
```
@ -27,6 +28,17 @@ You can include any meta info you want as well. Here is an example of meta infor
All meta fields are optional.
### Intro Text
Intro text is the text that one might write _about_ a recipe, but is not necessarily important to the recipe. It could include historical information, a bit about the cooking experience, or a more literary description of the process than the recipe itself might contain. Each line of text will appear as a paragraph of its own (hwoever that displays in each output medium). The format for intro text is leader (`>`) a tab and the text itself. Nice and simple.
Example:
```
> I am some introductory text.
> I am a separate paragraph.
```
### Ingredient
Ingredients come in four columns: leader, amount, measure, and item. Measure is an optional field, but remember to add a tab to represent it. Any ingredient lines without four columns will be ommitted from output.


+ 25
- 2
recipe View File

@ -4,8 +4,9 @@ import sys, os.path, textwrap
# Constants
META = '@'
INTRO_TEXT = '>'
INGREDIENT = '%'
INSTRUCTION = '>'
INSTRUCTION = ':'
NOTE = '*'
CSS_BODY_BG = '#C7FCC8'
@ -27,7 +28,7 @@ dd {{margin-left: 0;}}
'''
# Global vars
recipe = {'meta': {}, 'ingredients': [], 'instructions': [], 'notes': []}
recipe = {'meta': {}, 'ingredients': [], 'instructions': [], 'notes': [], 'intro_text': []}
print_to_stdout = False
def add_meta(l):
@ -62,6 +63,8 @@ def add_text(l, kind):
recipe['instructions'].append(data[1])
elif data[0] == NOTE:
recipe['notes'].append(data[1])
elif data[0] == INTRO_TEXT:
recipe['intro_text'].append(data[1])
def process_file(path):
if os.path.exists(path):
@ -82,6 +85,8 @@ def process_file(path):
add_text(line, 'instructions')
elif line[0] == NOTE:
add_text(line, 'notes')
elif line[0] == INTRO_TEXT:
add_text(line, 'intro_text')
if not len(recipe['ingredients']) and not len(recipe['instructions']):
print("There was not enough recipe information found in the file", file=sys.stderr)
sys.exit(1)
@ -116,6 +121,9 @@ def output_html(path):
out.append('<dd>{}</dd>'.format(recipe['meta'][key]))
if len(recipe['meta']) > meta_count_needed:
out.append('</dl><hr>')
if len(recipe['intro_text']):
for ins in recipe['intro_text']:
out.append('<p>{}</p>'.format(ins))
if len(recipe['ingredients']):
out.append('<h2>Ingredients</h2>')
out.append('<table id="ingredients" role="presentation">')
@ -153,6 +161,10 @@ def output_markdown(path):
continue
out.append('**{}**: {}'.format(key.title(), recipe['meta'][key]))
out.append('---')
if len(recipe['intro_text']):
for ins in recipe['instructions']:
out.append('{}\n'.format(ins))
out.append('')
if len(recipe['ingredients']):
out.append('## Ingredients\n')
for ingredient in recipe['ingredients']:
@ -185,6 +197,12 @@ def output_plaintext(path):
continue
out.append('{}: {}'.format(key.title(), recipe['meta'][key]))
out.append('')
if len(recipe['intro_text']):
for ln in recipe['intro_text']:
wrapped = textwrap.wrap(ln)
out.extend(wrapped)
out.append('')
out.append('')
if len(recipe['ingredients']):
out.append('== INGREDIENTS ==\n')
for ingredient in recipe['ingredients']:
@ -224,6 +242,11 @@ def output_gemini(path):
continue
out.append('{}: {}'.format(key.upper(), recipe['meta'][key]))
out.append('')
if len(recipe['intro_text']):
for ln in recipe['instructions']:
out.append(ln)
out.append('')
out.append('')
if len(recipe['ingredients']):
out.append('## Ingredients\n')
for ingredient in recipe['ingredients']:


Loading…
Cancel
Save