diff options
author | vrbaskiz <vrbaskiz@gmail.com> | 2017-03-31 17:47:10 +0200 |
---|---|---|
committer | Val Neekman <un33kvu@gmail.com> | 2017-03-31 11:47:10 -0400 |
commit | 750c737b37a7261ef551f9ab013dfb0b1b3eb29a (patch) | |
tree | 197bd7f50dfcf9fc0b75c6b99f56a5b24d3d26be /slugify | |
parent | 3f7ce8791dc676216c6bd9f0757262cf6bc210f1 (diff) | |
download | python-slugify-750c737b37a7261ef551f9ab013dfb0b1b3eb29a.tar.gz |
Added possibility to include custom regex as allowed characters (#36)
Added possibility to allow custom regex as allowed characters.
Diffstat (limited to 'slugify')
-rw-r--r-- | slugify/slugify.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/slugify/slugify.py b/slugify/slugify.py index 327f2c1..20f1ed8 100644 --- a/slugify/slugify.py +++ b/slugify/slugify.py @@ -71,7 +71,7 @@ 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=()): + separator='-', save_order=False, stopwords=(), allowed_characters=None): """ Make a slug from the given text. :param text (str): initial text @@ -131,7 +131,11 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w # replace unwanted characters text = NUMBERS_PATTERN.sub('', text) - text = ALLOWED_CHARS_PATTERN.sub('-', text) + print(text) + if allowed_characters: + text = re.sub(allowed_characters, '-', text) + else: + text = ALLOWED_CHARS_PATTERN.sub('-', text) # remove redundant - text = DUPLICATE_DASH_PATTERN.sub('-', text).strip('-') |