| 1 |
--- |
| 2 |
icon: lucide/link |
| 3 |
--- |
| 4 |
[:octicons-file-code-24:][_slugs]{: .source-link } |
| 5 |
|
| 6 |
# Slugs |
| 7 |
|
| 8 |
## Alternate Slugify |
| 9 |
|
| 10 |
Python Markdown's default slugify used to strip out all Unicode chars. While this is not necessarily true anymore, |
| 11 |
PyMdown Extensions offers a configurable slugify to help those with picker preferences. These are very simple slugify |
| 12 |
options. There are many slugify options out there, some of which are very sophisticated. Some may prefer using one of |
| 13 |
those, but if you just want something simple, this might fill that requirement. |
| 14 |
|
| 15 |
## Using Slugify |
| 16 |
|
| 17 |
`slugify` is a simple Unicode slugify option. It takes various parameters to control how casing is performed in slugs, |
| 18 |
what kind of Unicode normalization is preferred, and whether percent encoding of Unicode is preferred. |
| 19 |
|
| 20 |
The available key word options are found below: |
| 21 |
|
| 22 |
Parameter | Default | Description |
| 23 |
---------------- | -------------- | ----------- |
| 24 |
`case` | `#!py3 'none'` | Control case normalization of characters. See case options below. |
| 25 |
`percent_encode` | `#!py3 False` | Percent encode all Unicode characters after case normalization. |
| 26 |
`normalize` | `#!py3 'NFC'` | Unicode normalization method. For instance, `NFD` will strip diacritics, but `NFC` does not. |
| 27 |
|
| 28 |
Case options are described below: |
| 29 |
|
| 30 |
Option | Description |
| 31 |
------------- | ----------- |
| 32 |
`none` | Performs no case normalization preserving whatever case is provided. |
| 33 |
`lower` | Performs simple lower casing on the slug which will operate on Unicode and ASCII alike. |
| 34 |
`lower-ascii` | Performs simple lower casing on only ASCII upper case characters. |
| 35 |
`fold` | Applies Python's case folding function on the slug. |
| 36 |
|
| 37 |
Configuration is straight forward. Simply import the slug module and configure how you desire the Toc's extension to |
| 38 |
utilize the slugs. |
| 39 |
|
| 40 |
```py |
| 41 |
extension = ['markdown.extensions.toc'] |
| 42 |
extension_configs = { |
| 43 |
'markdown.extensions.toc': { |
| 44 |
"slugify": slugs.slugify(case="lower", percent_encode=True) |
| 45 |
} |
| 46 |
} |
| 47 |
``` |
| 48 |
|
| 49 |
If you are using something like [MkDocs][mkdocs], check out our [FAQ](../faq.md#function-references-in-yaml) which gives |
| 50 |
guidance on how to specify configurable functions in the YAML configuration. |