Return to Snippet

Revision: 46440
at May 19, 2011 16:18 by alvarohurtado84


Initial Code
# -*- 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()

Initial URL
http://www.alvarohurtado.es/

Initial Description
I only did some improvements over another snippet.

Initial Title
Create better Slugs in Python

Initial Tags
python, django

Initial Language
Python