A slug generator that turns strings into unicode slugs.
Project description
# Uni Slugify
A fork from https://github.com/mozilla/unicode-slugify. Fixes installation issues.
## Usage
```python
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" exemple
def snake_case(s):
# As "-" is not in allowed Chars, first one (`_`) is used for space remplacement
return slugify(s, ok='_', only_ascii=True)
snake_case(u'北京 (capital of china)')
# u'bei_jing_capital_of_china'
# "CamelCase" exemple
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
A fork from https://github.com/mozilla/unicode-slugify. Fixes installation issues.
## Usage
```python
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" exemple
def snake_case(s):
# As "-" is not in allowed Chars, first one (`_`) is used for space remplacement
return slugify(s, ok='_', only_ascii=True)
snake_case(u'北京 (capital of china)')
# u'bei_jing_capital_of_china'
# "CamelCase" exemple
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
uni-slugify-0.1.4.tar.gz
(5.6 kB
view details)
File details
Details for the file uni-slugify-0.1.4.tar.gz
.
File metadata
- Download URL: uni-slugify-0.1.4.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fc8ea1ba697ccdb8404b5f383f2f0fb1b4ec581cb7239154a45acd720e76332 |
|
MD5 | f278b2980e5a2f2273c148ff6058b1d3 |
|
BLAKE2b-256 | 342cee0f4735bcf77b5965ef07c2c366544632ca152f190e6ffaf4bcb1cd1310 |