Skip to content

Commit

Permalink
Add 'strip_html_tags' function to util module
Browse files Browse the repository at this point in the history
  • Loading branch information
crwood committed May 22, 2019
1 parent 7de275c commit a849ffe
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions gridsync/util.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

from binascii import hexlify, unhexlify
from html.parser import HTMLParser


B58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
Expand Down Expand Up @@ -57,3 +58,21 @@ def humanized_list(list_, kind='files'):
return "{}, {}, and {}".format(*list_)
return "{}, {}, and {} other {}".format(list_[0], list_[1],
len(list_) - 2, kind)


class _TagStripper(HTMLParser):
def __init__(self):
super().__init__()
self.data = []

def handle_data(self, data):
self.data.append(data)

def get_data(self):
return ''.join(self.data)


def strip_html_tags(s):
ts = _TagStripper()
ts.feed(s)
return ts.get_data()

0 comments on commit a849ffe

Please sign in to comment.