Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_empty(self):
attrs = {}
assert target_blank(attrs) == attrs
def test_mailto(self):
attrs = {(None, 'href'): 'mailto:joe@example.com'}
assert target_blank(attrs) == attrs
def test_stomp_target(self):
attrs = {(None, 'href'): 'http://example.com', (None, 'target'): 'foo'}
assert (
target_blank(attrs) ==
{(None, 'href'): 'http://example.com', (None, 'target'): '_blank'}
)
def test_add_target(self):
attrs = {(None, 'href'): 'http://example.com'}
assert (
target_blank(attrs) ==
{(None, 'href'): 'http://example.com', (None, 'target'): '_blank'}
)
def markdown_filter(text):
text = bleach.clean(text, strip=True)
text = md.reset().convert(text)
return mark_safe(bleach.linkify(text, [nofollow, target_blank]))
def process_text_links(text):
"""Process links in text, adding some attributes and linkifying textual links."""
link_callbacks = [callbacks.nofollow, callbacks.target_blank]
def link_attributes(attrs, new=False):
"""Run standard callbacks except for internal links."""
href_key = (None, "href")
if attrs.get(href_key).startswith("/"):
return attrs
# Run the standard callbacks
for callback in link_callbacks:
attrs = callback(attrs, new)
return attrs
return bleach.linkify(
text,
callbacks=[link_attributes],
parse_email=False,
def __call__(self, rule: Result = None, keys_limit: int = None) -> None:
if rule:
template = self.env.get_template("single-rule.html")
resultHTML = template.render(
rule=rule,
pd=pd,
linkfy_callbacks=[callbacks.target_blank],
keys_limit=keys_limit,
)
else:
template = self.env.get_template("full-report.html")
resultHTML = template.render(
rules=sorted(self.results.values(), key=lambda x: x.outcome.value),
pd=pd,
linkfy_callbacks=[callbacks.target_blank],
keys_limit=keys_limit,
)
# this renders the report as an iframe
# the option was added for generating the docs
template = self.env.get_template("iframe.html")
resultHTML = template.render(html_str=resultHTML)
display_html(resultHTML, raw=True)
'i',
'u',
'center',
'sup',
'sub',
'ul',
'ol',
'li',
'strike'
]
attrs = {
'*': ['style']
}
styles = ['text-align', 'font-weight', 'text-decoration']
cleaned = bleach.clean(html, tags=tags, attributes=attrs, styles=styles, strip=True)
return bleach.linkify(cleaned, callbacks=[nofollow, target_blank], parse_email=True)
'i',
'u',
'center',
'sup',
'sub',
'ul',
'ol',
'li',
'strike'
]
attrs = {
'*': ['style']
}
styles = ['text-align', 'font-weight', 'text-decoration']
cleaned = bleach.clean(html, tags=tags, attributes=attrs, styles=styles, strip=True)
return bleach.linkify(cleaned, callbacks=[nofollow, target_blank], parse_email=True)
:param _cleaner_settings: Constructor kwargs for
:class:`mediadrop.lib.htmlsanitizer.Cleaner`
:type _cleaner_settings: dict
:returns: XHTML
:rtype: unicode
"""
if not string or not string.strip():
# If the string is none, or empty, or whitespace
return u""
if _cleaner_settings is None:
_cleaner_settings = cleaner_settings
callbacks = copy(DEFAULT_CALLBACKS)
add_target_blank = _cleaner_settings.pop('add_target_blank', False)
if add_target_blank:
callbacks.append(target_blank)
# remove carriage return chars; FIXME: is this necessary?
string = string.replace(u"\r", u"")
# remove non-breaking-space characters. FIXME: is this necessary?
string = string.replace(u"\xa0", u" ")
string = string.replace(u" ", u" ")
# replace all blank lines with <br> tags
string = blank_line.sub(u"<br>", string)
# initialize and run the cleaner
string = clean(string, **_cleaner_settings)
# Convert links and add nofolllow and target
string = linkify(string, callbacks=callbacks)