예제 #1
0
def to_html(stream):
    """Transform an stream of markdown into safe HTML."""
    config = {
        'safe_mode': 'escape',
        'enable_attributes': False,
    }
    stream = force_text(stream)
    return sanitize(markdown.markdown(stream, ['nl2br'], **config))
예제 #2
0
def clean_stream(stream):
    parser = HTMLParser.HTMLParser()
    replacement_list = [
        ('<p></p>', ''),
    ]
    stream = unicode(parser.unescape(force_text(stream)))
    stream = sanitizer.sanitize(stream)
    for o, d in replacement_list:
        stream = stream.replace(o, d)
    return stream
예제 #3
0
 def clean_content(self):
     if 'content' in self.cleaned_data:
         return sanitizer.sanitize(self.cleaned_data['content'])
예제 #4
0
 def test_valid_text_is_not_modified(self):
     text = u'<p>Hello!</p>'
     output = sanitizer.sanitize(text)
     eq_(output, '<p>Hello!</p>')
예제 #5
0
 def test_script_tags_are_removed(self):
     text = u'<script>alert(0);</script>'
     output = sanitizer.sanitize(text)
     eq_(output, u'alert(0);')
예제 #6
0
 def test_harmful_link_is_removed(self):
     text = u'<a href="javascript:alert(0);">Link</a>'
     output = sanitizer.sanitize(text)
     eq_(output, '<a>Link</a>')
예제 #7
0
 def test_invalid_tag_is_removed(self):
     text = u'<p><font size="20">Hello!</font></p>'
     output = sanitizer.sanitize(text)
     eq_(output, '<p>Hello!</p>')
예제 #8
0
 def save(self, *args, **kwargs):
     if self.body:
         self.body = sanitizer.sanitize(self.body)
     return super(Snippet, self).save(*args, **kwargs)