def render_open(self, parser, node_index): contents = self.get_contents(parser) self.skip_contents(parser) # Validate url to avoid any XSS attacks if self.params: url = self.params.strip() else: url = strip_bbcode(contents) url = url.replace(u'"', u"%22").strip() if not url: return u'' try: scheme, netloc, path, params, query, fragment = urlparse(url) if not scheme: url = u'http://' + url scheme, netloc, path, params, query, fragment = urlparse(url) except ValueError: return u'' if scheme.lower() not in (u'http', u'https', u'ftp'): return u'' return u'<img class="img-responsive" src="%s"></img>' % PostMarkup.standard_replace_no_break( url)
def test_strip_bbcode(self): """Test strip_bbcode function""" tests = [(u"[b]Not bold[/b]", u"Not bold"), (u"Just text", u"Just text"), (u"[b][i][url][url=test]", u"")] for test, result in tests: self.assertEqual(postmarkup.strip_bbcode(test), result)
def render_open(self, parser, node_index): contents = self.get_contents(parser) self.skip_contents(parser) contents = postmarkup.strip_bbcode(contents).replace(u'"', "%22") if self.params in self.valid_params: return u'<img class="float-%s" src="%s" alt="%s">' % (self.params, contents, contents) else: return u'<img src="%s" alt="%s">' % (contents, contents)
def strip_bbcode(value): """ Strips BBCode tags from a string By using the postmark lib from: @see: http://code.google.com/p/postmarkup/ """ try: from postmarkup import strip_bbcode except ImportError: if settings.DEBUG: raise template.TemplateSyntaxError, "Error in {% bbcode %} filter: The Python postmarkup library isn't installed." return force_unicode(value) else: return mark_safe(strip_bbcode(value))
def render_quote(input, strip=False): patterns = { '&[rl]dquo;': '"', '<': '<', '>': '>' } if strip: input = strip_bbcode(spoiler(input, True)) for pat, repl in patterns.items(): input = re.sub(pat, '', input) else: input = render_bbcode(spoiler(input)) for pat, repl in patterns.items(): input = re.sub(pat, repl, input) return input.strip()
def render_open(self, parser, node_index): contents = self.get_contents(parser) contents = strip_bbcode(contents) self.skip_contents(parser) return clean_html(contents)
def process_text(self, archive, context, text, target, options): return postmarkup.strip_bbcode(text)
def process_text(self, text, target, options): return postmarkup.strip_bbcode(text)