updated vue and vue bootrap + template improvements

This commit is contained in:
vabene1111
2021-01-05 22:53:08 +01:00
parent 738b601462
commit fdeede5717
5 changed files with 46 additions and 20 deletions

View File

@@ -1,24 +1,35 @@
import bleach
import markdown as md
from bleach_whitelist import markdown_tags, markdown_attrs
from jinja2 import Template
from jinja2 import Template, TemplateSyntaxError
from cookbook.helper.mdx_attributes import MarkdownFormatExtension
from cookbook.helper.mdx_urlize import UrlizeExtension
class IngredientObject(object):
amount = None
unit = None
food = None
amount = ""
unit = ""
food = ""
note = ""
def __init__(self, ingredient):
self.amount = f'[[calculateAmount({ingredient.amount})]]'
self.unit = ingredient.unit
if ingredient.no_amount:
self.amount = ""
else:
self.amount = f'[[calculateAmount({ingredient.amount})]]'
if ingredient.unit:
self.unit = ingredient.unit
else:
self.unit = ""
self.food = ingredient.food
self.note = ingredient.note
def __str__(self):
return f'{self.amount} {self.unit} {self.food}'
ingredient = self.amount
if self.unit != "":
ingredient += f' {self.unit}'
return f'{ingredient} {self.food}'
def render_instructions(step): # TODO deduplicate markdown cleanup code
@@ -28,8 +39,11 @@ def render_instructions(step): # TODO deduplicate markdown cleanup code
for i in step.ingredients.all():
ingredients.append(IngredientObject(i))
template = Template(step.instruction)
instructions = template.render(ingredients=ingredients)
try:
template = Template(step.instruction)
instructions = template.render(ingredients=ingredients)
except TemplateSyntaxError:
instructions = step.instruction
tags = markdown_tags + ['pre', 'table', 'td', 'tr', 'th', 'tbody', 'style', 'thead']
parsed_md = md.markdown(instructions, extensions=['markdown.extensions.fenced_code', 'tables', UrlizeExtension(), MarkdownFormatExtension()])