Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- from unicodedata import normalize
- _punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.:]+')
- def slugify(text, delim='-'):
- """Generates an slightly worse ASCII-only slug."""
- result = []
- for word in _punct_re.split(text.lower()):
- word = normalize('NFKD', word).encode('ascii', 'ignore')
- word = word.decode('utf-8')
- if word:
- result.append(word)
- return delim.join(result)
- '''
- > print (slugify('zażółć gęślą jaźń'))
- > 'zazolc-gesla-jazn'
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement