super basic templating working

This commit is contained in:
vabene1111
2021-01-05 21:46:24 +01:00
parent f26b09cc0a
commit ee707eba5c
4 changed files with 26 additions and 2 deletions

View File

@@ -0,0 +1,19 @@
import bleach
import markdown as md
from bleach_whitelist import markdown_tags, markdown_attrs
from jinja2 import Template
from cookbook.helper.mdx_attributes import MarkdownFormatExtension
from cookbook.helper.mdx_urlize import UrlizeExtension
def render_instructions(step): # TODO deduplicate markdown cleanup code
template = Template(step.instruction)
instructions = template.render(ingredients=step.ingredients.all())
tags = markdown_tags + ['pre', 'table', 'td', 'tr', 'th', 'tbody', 'style', 'thead']
parsed_md = md.markdown(instructions, extensions=['markdown.extensions.fenced_code', 'tables', UrlizeExtension(), MarkdownFormatExtension()])
markdown_attrs['*'] = markdown_attrs['*'] + ['class']
return bleach.clean(parsed_md, tags, markdown_attrs)