Compare commits
No commits in common. "c3b4e8300e9b175671216925b9616757d2a2318e" and "c0f847aefbeb25b22393634028b5913b1019c5ef" have entirely different histories.
c3b4e8300e
...
c0f847aefb
1 changed files with 5 additions and 21 deletions
|
@ -7,23 +7,6 @@ from bs4 import BeautifulSoup
|
|||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
def is_html(string):
|
||||
'''
|
||||
Check if string is HTML
|
||||
'''
|
||||
soup = BeautifulSoup(string, "html.parser")
|
||||
# Remove leading and trailing white space
|
||||
stripped_string = string.strip()
|
||||
stripped_soup = str(soup).strip()
|
||||
# If the string remained the same after parsing with BeautifulSoup, it's probably not HTML
|
||||
if stripped_string == stripped_soup:
|
||||
return False
|
||||
# If the string changed when parsed by BeautifulSoup, it's probably HTML
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
@register.filter
|
||||
def is_image(file_url):
|
||||
image_extensions = ['.png', '.jpg', '.jpeg', '.gif', '.webp']
|
||||
|
@ -43,13 +26,14 @@ def is_pdf(file_url):
|
|||
|
||||
@register.filter
|
||||
def descriptionHtml2Text(description):
|
||||
if is_html(description):
|
||||
if description.startswith("<div"):
|
||||
cleanHtml = nh3.clean(description)
|
||||
soup = BeautifulSoup(cleanHtml, "html.parser")
|
||||
text = soup.get_text()
|
||||
return text
|
||||
descriptionText = soup.get_text()
|
||||
else:
|
||||
return description
|
||||
descriptionText = description
|
||||
|
||||
return descriptionText
|
||||
|
||||
|
||||
@register.filter
|
||||
|
|
Loading…
Reference in a new issue