From 750c737b37a7261ef551f9ab013dfb0b1b3eb29a Mon Sep 17 00:00:00 2001 From: vrbaskiz Date: Fri, 31 Mar 2017 17:47:10 +0200 Subject: Added possibility to include custom regex as allowed characters (#36) Added possibility to allow custom regex as allowed characters. --- slugify/slugify.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'slugify') 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('-') -- cgit v1.2.1