summaryrefslogtreecommitdiff
path: root/slugify
diff options
context:
space:
mode:
Diffstat (limited to 'slugify')
-rw-r--r--slugify/__init__.py2
-rw-r--r--slugify/slugify.py14
2 files changed, 14 insertions, 2 deletions
diff --git a/slugify/__init__.py b/slugify/__init__.py
index 81849b9..7358b99 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__ = '2.0.0'
+__version__ = '2.0.1'
diff --git a/slugify/slugify.py b/slugify/slugify.py
index ccd33a8..59e9672 100644
--- a/slugify/slugify.py
+++ b/slugify/slugify.py
@@ -75,7 +75,8 @@ def smart_truncate(string, max_length=0, word_boundary=False, separator=' ', sav
def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, word_boundary=False,
- separator=DEFAULT_SEPARATOR, save_order=False, stopwords=(), regex_pattern=None, lowercase=True):
+ separator=DEFAULT_SEPARATOR, save_order=False, stopwords=(), regex_pattern=None, lowercase=True,
+ replacements=()):
"""
Make a slug from the given text.
:param text (str): initial text
@@ -89,9 +90,15 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w
:param stopwords (iterable): words to discount
:param regex_pattern (str): regex pattern for allowed characters
:param lowercase (bool): activate case sensitivity by setting it to False
+ :param replacements (iterable): list of replacement rules e.g. [['|', 'or'], ['%', 'percent']]
:return (str):
"""
+ # user-specific replacements
+ if replacements:
+ for old, new in replacements:
+ text = text.replace(old, new)
+
# ensure text is unicode
if not isinstance(text, _unicode_type):
text = _unicode(text, 'utf-8', 'ignore')
@@ -158,6 +165,11 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w
words = [w for w in text.split(DEFAULT_SEPARATOR) if w not in stopwords]
text = DEFAULT_SEPARATOR.join(words)
+ # finalize user-specific replacements
+ if replacements:
+ for old, new in replacements:
+ text = text.replace(old, new)
+
# smart truncate if requested
if max_length > 0:
text = smart_truncate(text, max_length, word_boundary, DEFAULT_SEPARATOR, save_order)