diff options
| author | Val Neekman <val@neekware.com> | 2016-01-15 22:42:55 -0500 |
|---|---|---|
| committer | Val Neekman <val@neekware.com> | 2016-01-15 22:42:55 -0500 |
| commit | 7044d7a7c32388d557506cec4e174e8050c5666c (patch) | |
| tree | 039ecde7eb8f2929b20a45915827ab9acc2eae02 /slugify | |
| parent | a63ed53616a60addd00dfd8f579c1a531725987f (diff) | |
| download | python-slugify-7044d7a7c32388d557506cec4e174e8050c5666c.tar.gz | |
replace quotes with dashes
Diffstat (limited to 'slugify')
| -rw-r--r-- | slugify/__init__.py | 2 | ||||
| -rw-r--r-- | slugify/slugify.py | 17 |
2 files changed, 12 insertions, 7 deletions
diff --git a/slugify/__init__.py b/slugify/__init__.py index 4dc1be5..8b20b5f 100644 --- a/slugify/__init__.py +++ b/slugify/__init__.py @@ -3,4 +3,4 @@ from .slugify import * __author__ = 'Val Neekman @ Neekware Inc. [@vneekman]' __description__ = 'A Python slugify application that also handles Unicode' -__version__ = '1.1.4' +__version__ = '1.2.0' diff --git a/slugify/slugify.py b/slugify/slugify.py index 9d17d3c..113afdd 100644 --- a/slugify/slugify.py +++ b/slugify/slugify.py @@ -29,7 +29,8 @@ NUMBERS_PATTERN = re.compile('(?<=\d),(?=\d)') def smart_truncate(string, max_length=0, word_boundaries=False, separator=' ', save_order=False): - """Truncate a string. + """ + Truncate a string. :param string (str): string for modification :param max_length (int): output string length :param word_boundaries (bool): @@ -71,7 +72,8 @@ def smart_truncate(string, max_length=0, word_boundaries=False, separator=' ', s def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, word_boundary=False, separator='-', save_order=False, stopwords=()): - """Make a slug from the given text. + """ + Make a slug from the given text. :param text (str): initial text :param entities (bool): :param decimal (bool): @@ -88,11 +90,12 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w if not isinstance(text, _unicode_type): text = _unicode(text, 'utf-8', 'ignore') + # replace quotes with dashes - pre-process text = QUOTE_PATTERN.sub('-', text) - + # decode unicode text = unidecode.unidecode(text) - + # ensure text is still in unicode if not isinstance(text, _unicode_type): text = _unicode(text, 'utf-8', 'ignore') @@ -122,9 +125,11 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w # make the text lowercase text = text.lower() - - # replace unwanted characters + + # remove generated quotes -- post-process text = QUOTE_PATTERN.sub('', text) + + # replace unwanted characters text = NUMBERS_PATTERN.sub('', text) text = ALLOWED_CHARS_PATTERN.sub('-', text) |
