summaryrefslogtreecommitdiff
path: root/slugify/slugify.py
diff options
context:
space:
mode:
authorAndriy Orehov <andriyorehov@gmail.com>2019-01-03 18:28:01 +0200
committerVal Neekman <un33kvu@gmail.com>2019-01-03 11:28:01 -0500
commit646761e5b4c73b9be7285c60eab4e10c30fe32f4 (patch)
tree4c348129e15ad554ef1201c95c4db5be2738bb89 /slugify/slugify.py
parentc357ee590b2e799e62229e656e566cc9b7298498 (diff)
downloadpython-slugify-646761e5b4c73b9be7285c60eab4e10c30fe32f4.tar.gz
add support user-specific replacements (#66)
thx
Diffstat (limited to 'slugify/slugify.py')
-rw-r--r--slugify/slugify.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/slugify/slugify.py b/slugify/slugify.py
index ccd33a8..1544aba 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')