Skip to main content

Fork of un33k/python-slugify to fix issue #68

Project description

permissive-slugify

Fork of un33k/python-slugify to fix issue 68.

License Version
Travis CI Coverage
AppVeyor Supported versions
Wheel Implementation
Status Downloads
Show your support

Improvements

  • Support for extras_require and cmdclass
  • Refactored
  • Deploy from Travis CI
  • Added Appveyor Integration
  • Uses pytest
  • Uses CodeCov

How to install

By default, permissive-slugify uses Unidecode as decoder which is GPL-licensed.

pip install permissive-slugify

Specifying decoder

You can specify which decoder will be used:

  • Unidecode - (GPL-licensed).

    pip install permissive-slugify[unidecode]
    easy_install permissive-slugify[unidecode]
    
  • text-unidecode (GPL & Perl Artistic)

    pip install permissive-slugify[text-unidecode]
    easy_install permissive-slugify[text-unidecode]
    

How to use

# -*- coding: utf-8 -*-
from slugify import slugify

txt = "This is a test ---"
slug = slugify(txt)
assert slug == "this-is-a-test"

txt = '影師嗎'
slug = slugify(txt)
assert slug == "ying-shi-ma"

txt = 'C\'est déjà l\'été.'
slug = slugify(txt)
assert slug == "c-est-deja-l-ete"

txt = 'Nín hǎo. Wǒ shì zhōng guó rén'
slug = slugify(txt)
assert slug == "nin-hao-wo-shi-zhong-guo-ren"

txt = 'Компьютер'
slug = slugify(txt)
assert slug == "kompiuter"

txt = 'jaja---lol-méméméoo--a'
slug = slugify(txt, max_length=9)
assert slug == "jaja-lol"

txt = 'jaja---lol-méméméoo--a'
slug = slugify(txt, max_length=15, word_boundary=True)
assert slug == "jaja-lol-a"

txt = 'jaja---lol-méméméoo--a'
slug = slugify(txt, max_length=20, word_boundary=True, separator=".")
assert slug == "jaja.lol.mememeoo.a"

txt = 'one two three four five'
slug = slugify(txt, max_length=13, word_boundary=True, save_order=True)
assert slug == "one-two-three"

txt = 'the quick brown fox jumps over the lazy dog'
slug = slugify(txt, stopwords=['the'])
assert slug == 'quick-brown-fox-jumps-over-lazy-dog'

txt = 'the quick brown fox jumps over the lazy dog in a hurry'
slug = slugify(txt, stopwords=['the', 'in', 'a', 'hurry'])
assert slug == 'quick-brown-fox-jumps-over-lazy-dog'

txt = 'thIs Has a stopword Stopword'
slug = slugify(txt, stopwords=['Stopword'], lowercase=False)
assert slug == 'thIs-Has-a-stopword'

txt = "___This is a test___"
regex_pattern = r'[^-a-z0-9_]+'
slug = slugify(txt, regex_pattern=regex_pattern)
assert slug == "___this-is-a-test___"

txt = "___This is a test___"
regex_pattern = r'[^-a-z0-9_]+'
slug = slugify(txt, separator='_', regex_pattern=regex_pattern)
assert slug != "_this_is_a_test_"

txt = '10 | 20 %'
slug = slugify(txt, replacements=[['|', 'or'], ['%', 'percent']])
assert slug == "10-or-20-percent"

References

Author

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

permissive-slugify-1.0.0.tar.gz (6.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page