示例#1
0
def render_instructions(step):  # TODO deduplicate markdown cleanup code
    instructions = step.instruction

    tags = markdown_tags + [
        'pre', 'table', 'td', 'tr', 'th', 'tbody', 'style', 'thead', 'img'
    ]
    parsed_md = md.markdown(instructions,
                            extensions=[
                                'markdown.extensions.fenced_code',
                                TableExtension(),
                                UrlizeExtension(),
                                MarkdownFormatExtension()
                            ])
    markdown_attrs['*'] = markdown_attrs['*'] + ['class', 'width', 'height']

    instructions = bleach.clean(parsed_md, tags, markdown_attrs)

    ingredients = []

    for i in step.ingredients.all():
        ingredients.append(IngredientObject(i))

    try:
        template = Template(instructions)
        instructions = template.render(ingredients=ingredients)
    except TemplateSyntaxError:
        return _('Could not parse template code.'
                 ) + ' Error: Template Syntax broken'
    except UndefinedError:
        return _('Could not parse template code.') + ' Error: Undefined Error'

    return instructions
示例#2
0
def render_instructions(step):  # TODO deduplicate markdown cleanup code
    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()
                            ])
    markdown_attrs['*'] = markdown_attrs['*'] + ['class']

    instructions = bleach.clean(parsed_md, tags, markdown_attrs)

    ingredients = []

    for i in step.ingredients.all():
        ingredients.append(IngredientObject(i))

    try:
        template = Template(instructions)
        instructions = template.render(ingredients=ingredients)
    except TemplateSyntaxError:
        pass

    return instructions
示例#3
0
def markdown(value):
    tags = markdown_tags + [
        'pre', 'table', 'td', 'tr', 'th', 'tbody', 'style', 'thead'
    ]
    parsed_md = md.markdown(value,
                            extensions=[
                                'markdown.extensions.fenced_code', 'tables',
                                MarkdownFormatExtension()
                            ])
    return bleach.clean(parsed_md, tags, print_attrs, markdown_attrs)
示例#4
0
def markdown(value):
    tags = markdown_tags + [
        'pre', 'table', 'td', 'tr', 'th', 'tbody', 'style', 'thead'
    ]
    parsed_md = md.markdown(value,
                            extensions=[
                                'markdown.extensions.fenced_code', 'tables',
                                UrlizeExtension(),
                                MarkdownFormatExtension()
                            ])
    markdown_attrs['*'] = markdown_attrs['*'] + ['class']
    return bleach.clean(parsed_md, tags, markdown_attrs)