def strip_tags(value): """ Returns the given HTML with all tags stripped. We use lxml to strip all js tags and then hand the result to django's strip tags. """ # strip any new lines value = value.strip() if value: partial_strip = LxmlCleaner().clean_html(value) value = _strip_tags(partial_strip) return value
def strip_tags(value): """ Returns the given HTML with all tags stripped. We use lxml to strip all js tags and then hand the result to django's strip tags. """ # strip any new lines if value: value = value.strip() if value: partial_strip = LxmlCleaner().clean_html(value) value = _strip_tags(partial_strip) return value
def strip_tags(value): """ Returns the given HTML with all tags stripped. We use lxml to strip all js tags and then hand the result to django's strip tags. If value isn't valid, just return value since there is no tags to strip. """ if isinstance(value, six.string_types): value = value.strip() try: partial_strip = LxmlCleaner().clean_html(value) except ParseError: # Error could occur because of invalid html document, # including '' values. We don't want to return empty handed. partial_strip = value value = _strip_tags(partial_strip) return value.strip() # clean cases we have <div>\n\n</div> return value