strip trailing and leading extra dashes

those are introduced if non-word characters are found, and are ugly
This commit is contained in:
Antoine Beaupré 2017-07-18 16:33:22 -04:00
parent 914dba4152
commit 5ef68783a8
No known key found for this signature in database
GPG key ID: 792152527B75921E

View file

@ -236,12 +236,13 @@ def slug(text):
2. shift everything to lowercase
3. strip whitespace
4. replace other non-word characters with dashes
5. strip extra dashes
This somewhat duplicates the :func:`Google.slugify` function but
slugify is not as generic as this one, which can be reused
elsewhere.
"""
return re.sub(r'\W+', '-', unidecode(text).lower().strip())
return re.sub(r'\W+', '-', unidecode(text).lower().strip()).strip('-')
class Backend(object):