Skip to content

Improve cream.util.string.slugify #3

Open
@kkris

Description

@kkris

I would like to use this little snippet from Armin Ronacher, because it produces real nice slugs and e.g. converts ö to oe instead of o or -- like it is doing now.
But to use this we need http://pypi.python.org/pypi/translitcodec as a dependency.

import re
import translitcodec

_punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+')


def slugify(text, delim=u'-'):
    """Generates an ASCII-only slug."""
    result = []
    for word in _punct_re.split(text.lower()):
        word = word.encode('translit/long')
        if word:
            result.append(word)
    return unicode(delim.join(result))

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions