forked from CGM_Public/pretix_original
Parse more nTLDs and gTLDs (Fix #1488)
This commit is contained in:
@@ -3,12 +3,14 @@ import urllib.parse
|
|||||||
import bleach
|
import bleach
|
||||||
import markdown
|
import markdown
|
||||||
from bleach import DEFAULT_CALLBACKS
|
from bleach import DEFAULT_CALLBACKS
|
||||||
|
from bleach.linkifier import build_email_re, build_url_re
|
||||||
from django import template
|
from django import template
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core import signing
|
from django.core import signing
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.http import url_has_allowed_host_and_scheme
|
from django.utils.http import url_has_allowed_host_and_scheme
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
from tlds import tld_set
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
@@ -84,7 +86,12 @@ def abslink_callback(attrs, new=False):
|
|||||||
|
|
||||||
|
|
||||||
def markdown_compile_email(source):
|
def markdown_compile_email(source):
|
||||||
return bleach.linkify(bleach.clean(
|
linker = bleach.Linker(
|
||||||
|
url_re=build_url_re(tlds=tld_set),
|
||||||
|
email_re=build_email_re(tlds=tld_set),
|
||||||
|
parse_email=True
|
||||||
|
)
|
||||||
|
return linker.linkify(bleach.clean(
|
||||||
markdown.markdown(
|
markdown.markdown(
|
||||||
source,
|
source,
|
||||||
extensions=[
|
extensions=[
|
||||||
@@ -95,7 +102,7 @@ def markdown_compile_email(source):
|
|||||||
tags=ALLOWED_TAGS,
|
tags=ALLOWED_TAGS,
|
||||||
attributes=ALLOWED_ATTRIBUTES,
|
attributes=ALLOWED_ATTRIBUTES,
|
||||||
protocols=ALLOWED_PROTOCOLS,
|
protocols=ALLOWED_PROTOCOLS,
|
||||||
), parse_email=True)
|
))
|
||||||
|
|
||||||
|
|
||||||
def markdown_compile(source, snippet=False):
|
def markdown_compile(source, snippet=False):
|
||||||
@@ -121,11 +128,13 @@ def rich_text(text: str, **kwargs):
|
|||||||
Processes markdown and cleans HTML in a text input.
|
Processes markdown and cleans HTML in a text input.
|
||||||
"""
|
"""
|
||||||
text = str(text)
|
text = str(text)
|
||||||
body_md = bleach.linkify(
|
linker = bleach.Linker(
|
||||||
markdown_compile(text),
|
url_re=build_url_re(tlds=tld_set),
|
||||||
|
email_re=build_email_re(tlds=tld_set),
|
||||||
callbacks=DEFAULT_CALLBACKS + ([safelink_callback] if kwargs.get('safelinks', True) else [abslink_callback]),
|
callbacks=DEFAULT_CALLBACKS + ([safelink_callback] if kwargs.get('safelinks', True) else [abslink_callback]),
|
||||||
parse_email=True
|
parse_email=True
|
||||||
)
|
)
|
||||||
|
body_md = linker.linkify(markdown_compile(text))
|
||||||
return mark_safe(body_md)
|
return mark_safe(body_md)
|
||||||
|
|
||||||
|
|
||||||
@@ -135,9 +144,11 @@ def rich_text_snippet(text: str, **kwargs):
|
|||||||
Processes markdown and cleans HTML in a text input.
|
Processes markdown and cleans HTML in a text input.
|
||||||
"""
|
"""
|
||||||
text = str(text)
|
text = str(text)
|
||||||
body_md = bleach.linkify(
|
linker = bleach.Linker(
|
||||||
markdown_compile(text, snippet=True),
|
url_re=build_url_re(tlds=tld_set),
|
||||||
|
email_re=build_email_re(tlds=tld_set),
|
||||||
callbacks=DEFAULT_CALLBACKS + ([safelink_callback] if kwargs.get('safelinks', True) else [abslink_callback]),
|
callbacks=DEFAULT_CALLBACKS + ([safelink_callback] if kwargs.get('safelinks', True) else [abslink_callback]),
|
||||||
parse_email=True
|
parse_email=True
|
||||||
)
|
)
|
||||||
|
body_md = linker.linkify(markdown_compile(text, snippet=True))
|
||||||
return mark_safe(body_md)
|
return mark_safe(body_md)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ dj-static
|
|||||||
csscompressor
|
csscompressor
|
||||||
django-markup
|
django-markup
|
||||||
markdown<=2.2
|
markdown<=2.2
|
||||||
bleach==3.1.*
|
bleach>=3.1.3
|
||||||
sentry-sdk==0.14.*
|
sentry-sdk==0.14.*
|
||||||
babel
|
babel
|
||||||
django-i18nfield>=1.7.0
|
django-i18nfield>=1.7.0
|
||||||
@@ -64,3 +64,4 @@ phonenumberslite==8.11.*
|
|||||||
python-bidi==0.4.* # Support for arabic in reportlab
|
python-bidi==0.4.* # Support for arabic in reportlab
|
||||||
arabic-reshaper==2.0.15 # Support for Aabic in reportlab
|
arabic-reshaper==2.0.15 # Support for Aabic in reportlab
|
||||||
packaging
|
packaging
|
||||||
|
tlds>=2020041600
|
||||||
@@ -120,7 +120,7 @@ setup(
|
|||||||
'csscompressor',
|
'csscompressor',
|
||||||
'django-markup',
|
'django-markup',
|
||||||
'markdown<=2.2',
|
'markdown<=2.2',
|
||||||
'bleach==3.1.*',
|
'bleach>=3.1.3',
|
||||||
'sentry-sdk==0.14.*',
|
'sentry-sdk==0.14.*',
|
||||||
'babel',
|
'babel',
|
||||||
'paypalrestsdk==1.13.*',
|
'paypalrestsdk==1.13.*',
|
||||||
@@ -151,6 +151,7 @@ setup(
|
|||||||
'python-bidi==0.4.*', # Support for Arabic in reportlab
|
'python-bidi==0.4.*', # Support for Arabic in reportlab
|
||||||
'arabic-reshaper==2.0.15', # Support for Arabic in reportlab
|
'arabic-reshaper==2.0.15', # Support for Arabic in reportlab
|
||||||
'packaging',
|
'packaging',
|
||||||
|
'tlds>=2020041600'
|
||||||
],
|
],
|
||||||
extras_require={
|
extras_require={
|
||||||
'dev': [
|
'dev': [
|
||||||
|
|||||||
Reference in New Issue
Block a user