Ticket #1849: collapse-hyphens.diff
File collapse-hyphens.diff, 1.2 KB (added by , 18 years ago) |
---|
-
django/contrib/admin/media/js/urlify.js
10 10 s = s.replace(/[^-A-Z0-9\s]/gi, ''); // remove unneeded chars 11 11 s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces 12 12 s = s.replace(/\s+/g, '-'); // convert spaces to hyphens 13 s = s.replace(/-+/g, '-'); // collapse repeated hyphens 13 14 s = s.toLowerCase(); // convert to lowercase 14 15 return s.substring(0, num_chars);// trim to first num_chars chars 15 16 } 17 No newline at end of file -
django/template/defaultfilters.py
66 66 def slugify(value): 67 67 "Converts to lowercase, removes non-alpha chars and converts spaces to hyphens" 68 68 value = re.sub('[^\w\s-]', '', value).strip().lower() 69 return re.sub('\s+', '-', value) 69 value = re.sub('\s+', '-', value) 70 return re.sub('-+', '-', value) 70 71 71 72 def stringformat(value, arg): 72 73 """