From e2e6f74d42a9de64f0cc7bab2255ad9d40f558a3 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Thu, 26 Nov 2020 14:21:37 -0600 Subject: [PATCH] Don't error on w/o class in replace_failed_smilies_with_alt_textreplace_failed_smilies_with_alt_text --- .../adapters/base_xenforoforum_adapter.py | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/fanficfare/adapters/base_xenforoforum_adapter.py b/fanficfare/adapters/base_xenforoforum_adapter.py index 63129a70..ad17f621 100644 --- a/fanficfare/adapters/base_xenforoforum_adapter.py +++ b/fanficfare/adapters/base_xenforoforum_adapter.py @@ -778,18 +778,19 @@ class BaseXenForoForumAdapter(BaseSiteAdapter): if self.getConfig('replace_failed_smilies_with_alt_text'): for img in soup.find_all('img',src=re.compile(r'(^data:image|(failedtoload|clear.png)$)')): # logger.debug("replace_failed_smilies_with_alt_text img: %s"%img) - clses = unicode(img['class']) # stringify list. - if img.has_attr('alt') and ('mceSmilie' in clses or 'smilie--sprite' in clses): - ## Change the img to a span containing the alt - ## text, remove attrs. This is a one-way change. - img.name='span' - img.string = img['alt'].replace('`','') # no idea why some have ` - # not valid attrs on span. - del img['alt'] - if img.has_attr('src'): - del img['src'] - if img.has_attr('longdesc'): - del img['longdesc'] + if img.has_attr('class'): + clses = unicode(img['class']) # stringify list. + if img.has_attr('alt') and ('mceSmilie' in clses or 'smilie--sprite' in clses): + ## Change the img to a span containing the alt + ## text, remove attrs. This is a one-way change. + img.name='span' + img.string = img['alt'].replace('`','') # no idea why some have ` + # not valid attrs on span. + del img['alt'] + if img.has_attr('src'): + del img['src'] + if img.has_attr('longdesc'): + del img['longdesc'] return super(BaseXenForoForumAdapter, self)._do_utf8FromSoup(url,soup,fetch,allow_replace_br_with_p) # from https://daviseford.com/blog/2017/04/27/python-string-to-title-including-punctuation.html