forked from CGM_Public/pretix_original
Add rich_text_snippet
This commit is contained in:
@@ -12,19 +12,23 @@ from django.utils.safestring import mark_safe
|
|||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
ALLOWED_TAGS = [
|
ALLOWED_TAGS_SNIPPET = [
|
||||||
'a',
|
'a',
|
||||||
'abbr',
|
'abbr',
|
||||||
'acronym',
|
'acronym',
|
||||||
'b',
|
'b',
|
||||||
'blockquote',
|
|
||||||
'br',
|
'br',
|
||||||
'code',
|
'code',
|
||||||
'em',
|
'em',
|
||||||
'i',
|
'i',
|
||||||
|
'strong',
|
||||||
|
'span',
|
||||||
|
# Update doc/user/markdown.rst if you change this!
|
||||||
|
]
|
||||||
|
ALLOWED_TAGS = ALLOWED_TAGS_SNIPPET + [
|
||||||
|
'blockquote',
|
||||||
'li',
|
'li',
|
||||||
'ol',
|
'ol',
|
||||||
'strong',
|
|
||||||
'ul',
|
'ul',
|
||||||
'p',
|
'p',
|
||||||
'table',
|
'table',
|
||||||
@@ -34,7 +38,6 @@ ALLOWED_TAGS = [
|
|||||||
'td',
|
'td',
|
||||||
'th',
|
'th',
|
||||||
'div',
|
'div',
|
||||||
'span',
|
|
||||||
'hr',
|
'hr',
|
||||||
'h1',
|
'h1',
|
||||||
'h2',
|
'h2',
|
||||||
@@ -95,7 +98,8 @@ def markdown_compile_email(source):
|
|||||||
), parse_email=True)
|
), parse_email=True)
|
||||||
|
|
||||||
|
|
||||||
def markdown_compile(source):
|
def markdown_compile(source, snippet=False):
|
||||||
|
tags = ALLOWED_TAGS_SNIPPET if snippet else ALLOWED_TAGS
|
||||||
return bleach.clean(
|
return bleach.clean(
|
||||||
markdown.markdown(
|
markdown.markdown(
|
||||||
source,
|
source,
|
||||||
@@ -104,7 +108,8 @@ def markdown_compile(source):
|
|||||||
'markdown.extensions.nl2br'
|
'markdown.extensions.nl2br'
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
tags=ALLOWED_TAGS,
|
strip=snippet,
|
||||||
|
tags=tags,
|
||||||
attributes=ALLOWED_ATTRIBUTES,
|
attributes=ALLOWED_ATTRIBUTES,
|
||||||
protocols=ALLOWED_PROTOCOLS,
|
protocols=ALLOWED_PROTOCOLS,
|
||||||
)
|
)
|
||||||
@@ -122,3 +127,17 @@ def rich_text(text: str, **kwargs):
|
|||||||
parse_email=True
|
parse_email=True
|
||||||
)
|
)
|
||||||
return mark_safe(body_md)
|
return mark_safe(body_md)
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def rich_text_snippet(text: str, **kwargs):
|
||||||
|
"""
|
||||||
|
Processes markdown and cleans HTML in a text input.
|
||||||
|
"""
|
||||||
|
text = str(text)
|
||||||
|
body_md = bleach.linkify(
|
||||||
|
markdown_compile(text, snippet=True),
|
||||||
|
callbacks=DEFAULT_CALLBACKS + ([safelink_callback] if kwargs.get('safelinks', True) else [abslink_callback]),
|
||||||
|
parse_email=True
|
||||||
|
)
|
||||||
|
return mark_safe(body_md)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ from pretix.base.services.cart import (
|
|||||||
get_fees, set_cart_addons, update_tax_rates,
|
get_fees, set_cart_addons, update_tax_rates,
|
||||||
)
|
)
|
||||||
from pretix.base.services.orders import perform_order
|
from pretix.base.services.orders import perform_order
|
||||||
|
from pretix.base.templatetags.rich_text import rich_text_snippet
|
||||||
from pretix.base.views.tasks import AsyncAction
|
from pretix.base.views.tasks import AsyncAction
|
||||||
from pretix.multidomain.urlreverse import eventreverse
|
from pretix.multidomain.urlreverse import eventreverse
|
||||||
from pretix.presale.forms.checkout import (
|
from pretix.presale.forms.checkout import (
|
||||||
@@ -664,7 +665,7 @@ class ConfirmStep(CartMixin, AsyncAction, TemplateFlowStep):
|
|||||||
v = _('Yes')
|
v = _('Yes')
|
||||||
elif v is False:
|
elif v is False:
|
||||||
v = _('No')
|
v = _('No')
|
||||||
ctx['contact_info'].append((value.label, v))
|
ctx['contact_info'].append((rich_text_snippet(value.label), v))
|
||||||
|
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user