Introduce CleanChars filter
This commit is contained in:
parent
01954fad4e
commit
081d4f32f0
1 changed files with 15 additions and 0 deletions
|
|
@ -168,6 +168,21 @@ class Attr(_Filter):
|
|||
def __call__(self, item):
|
||||
return item.use_selector(getattr(item, 'obj_%s' % self.name))
|
||||
|
||||
class CleanChars(Filter):
|
||||
"""
|
||||
Remove chars.
|
||||
"""
|
||||
def __init__(self, selector, symbols):
|
||||
super(CleanChars, self).__init__(selector)
|
||||
self.symbols = symbols
|
||||
|
||||
def filter(self, txt):
|
||||
if isinstance(txt, (tuple,list)):
|
||||
txt = ' '.join([t.strip() for t in txt.itertext()])
|
||||
|
||||
for symbol in self.symbols:
|
||||
txt = txt.replace(symbol, '')
|
||||
return txt
|
||||
|
||||
class Regexp(Filter):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue