/ Published in: Python
A slug function that support acentuation :)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# -*- coding: utf-8 -*- import htmlentitydefs, re def slugfy(text, separator): ret = "" for c in text.lower(): try: ret += htmlentitydefs.codepoint2name[ord(c)] except: ret += c ret = re.sub("([a-zA-Z])(uml|acute|grave|circ|tilde|cedil)", r"\1", ret) ret = re.sub("\W", " ", ret) ret = re.sub(" +", separator, ret) return ret.strip() # usage @ pt_BR print slugfy("Teste de acentuação python", "-")