PurgeAttributes.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:Anki-Addons 作者: searene 项目源码 文件源码
def purgeAttributes(self, mime, _old):
    html = mime.html()
    soup = BeautifulSoup(html)
    newMime = QMimeData()
    for tag in soup.recursiveChildGenerator():
        # remove attributes in the list
        index = -1
        try:
            for key, value in tag.attrs:
                index += 1
                if key != 'style':
                    continue
                new = value.split(';')
                new = ';'.join([s for s in new
                    if s.split(':')[0].strip() not in REMOVE_ATTRIBUTES])
                tag.attrs[index] = (u'style', new)
        except AttributeError: 
            # 'NavigableString' object has no attribute 'attrs'
            pass

    # assign the modified html to new Mime
    newMime.setHtml(str(soup).decode('utf8'))

    # default _processHtml method
    return _old(self, newMime)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号