/ Published in: Python
I only did some improvements over another snippet.
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 = ret.strip() ret = re.sub(" ", "_", ret) ret = re.sub("\W", "", ret) ret = re.sub("[ _]+", separator, ret) return ret.strip()
URL: http://www.alvarohurtado.es/