Skip to content

Improve cream.util.string.slugify #3

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))

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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