A slugifier that works in unicode
Перейти к файлу
Mozilla-GitHub-Standards 74d175dd4c Add Mozilla Code of Conduct file
Fixes #36.

_(Message COC002)_
2021-10-22 16:06:17 -04:00
slugify decode unidecode output 2018-08-16 16:37:58 -03:00
.gitignore python 3.x compatibilit and tox + travis auto tests 2015-06-11 15:22:02 +02:00
.travis.yml Drop python 2.6 support 2017-03-30 16:51:33 -03:00
CODE_OF_CONDUCT.md Add Mozilla Code of Conduct file 2021-10-22 16:06:17 -04:00
LICENSE initial commit where I steal code from amo 2011-03-24 16:09:43 -07:00
MANIFEST.in Markdown everywhere 2011-03-24 16:16:05 -07:00
README.md Fix typos 2016-03-15 04:04:39 -07:00
dev-requirements.txt add tests for only_ascii, lower and spaces combinations 2015-06-11 12:57:14 +02:00
requirements.txt add tests for only_ascii, lower and spaces combinations 2015-06-11 12:57:14 +02:00
setup.py Make Pypi to read the long description as Mardown 2018-12-10 12:17:58 +01:00
tox.ini Drop python 2.6 support 2017-03-30 16:51:33 -03:00

README.md

Unicode Slugify

Unicode Slugify is a slugifier that generates unicode slugs. It was originally used in the Firefox Add-ons web site to generate slugs for add-ons and add-on collections. Many of these add-ons and collections had unicode characters and required more than simple transliteration.

Usage


from slugify import slugify, SLUG_OK

# Default usage : lower, spaces replaced with "-", only alphanum and "-_~" chars, keeps unicode
slugify(u'Bän...g (bang)')
# u'bäng-bang'

# Keep capital letters and spaces
slugify(u'Bän...g (bang)', lower=False, spaces=True)
# u'Bäng bang'

# Replace non ascii chars with their "best" representation
slugify(u'北京 (capital of China)', only_ascii=True)
# u'bei-jing-capital-of-china'

# Allow some extra chars
slugify(u'北京 (capital of China)', ok=SLUG_OK+'()', only_ascii=True)
# u'bei-jing-(capital-of-china)'

# "snake_case" example
def snake_case(s):
    # As "-" is not in allowed Chars, first one (`_`) is used for space replacement
    return slugify(s, ok='_', only_ascii=True)
snake_case(u'北京 (capital of china)')
# u'bei_jing_capital_of_china'

# "CamelCase" example
def camel_case(s):
    return slugify(s.title(), ok='', only_ascii=True, lower=False)
camel_case(u'北京 (capital of china)')
# u'BeiJingCapitalOfChina'

Thanks

Tomaz Solc, unidecode, https://pypi.python.org/pypi/Unidecode