MCPcopy Create free account
hub / github.com/Python-Markdown/markdown / slugify

Function slugify

markdown/extensions/toc.py:38–45  ·  view source on GitHub ↗

Slugify a string, to make it URL friendly.

(value: str, separator: str, unicode: bool = False)

Source from the content-addressed store, hash-verified

36
37
38def slugify(value: str, separator: str, unicode: bool = False) -> str:
39 """ Slugify a string, to make it URL friendly. """
40 if not unicode:
41 # Replace Extended Latin characters with ASCII, i.e. `žlutý` => `zluty`
42 value = unicodedata.normalize('NFKD', value)
43 value = value.encode('ascii', 'ignore').decode('ascii')
44 value = re.sub(r'[^\w\s-]', '', value).strip().lower()
45 return re.sub(r'[{}\s]+'.format(separator), separator, value)
46
47
48def slugify_unicode(value: str, separator: str) -> str:

Callers 1

slugify_unicodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected