Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion slugify/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def parse_args(argv):
help="""Additional replacement rules e.g. "|->or", "%%->percent".""")
parser.add_argument("--allow-unicode", action='store_true', default=False,
help="Allow unicode characters")
parser.add_argument("--replace-ambiguous-characters", action='store_true',
default=False, help="Replace ambiguous characters with their closest ASCII equivalent")

args = parser.parse_args(argv[1:])

Expand Down Expand Up @@ -76,7 +78,8 @@ def slugify_params(args):
stopwords=args.stopwords,
lowercase=args.lowercase,
replacements=args.replacements,
allow_unicode=args.allow_unicode
allow_unicode=args.allow_unicode,
replace_ambiguous_characters=args.replace_ambiguous_characters
)


Expand Down
9 changes: 8 additions & 1 deletion slugify/slugify.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
except ImportError:
import unidecode

from .special import AMBIGUOUS_CHARACTERS

__all__ = ['slugify', 'smart_truncate']


Expand Down Expand Up @@ -66,7 +68,7 @@ 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,
replacements=(), allow_unicode=False):
replacements=(), allow_unicode=False, replace_ambiguous_characters=False):
"""
Make a slug from the given text.
:param text (str): initial text
Expand All @@ -82,6 +84,7 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w
:param lowercase (bool): activate case sensitivity by setting it to False
:param replacements (iterable): list of replacement rules e.g. [['|', 'or'], ['%', 'percent']]
:param allow_unicode (bool): allow unicode characters
:param replace_ambiguous_characters (bool): replace characters that can be confused with others
:return (str):
"""

Expand All @@ -97,6 +100,10 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w
# replace quotes with dashes - pre-process
text = QUOTE_PATTERN.sub(DEFAULT_SEPARATOR, text)

# replace ambiguous characters
if replace_ambiguous_characters:
text = ''.join(chr(AMBIGUOUS_CHARACTERS.get(str(ord(c)), ord(c))) for c in text)

# decode unicode
if not allow_unicode:
text = unidecode.unidecode(text)
Expand Down
Loading