Skip to content

Commit 7790c06

Browse files
committed
Release notes and cleanup.
1 parent f0b1360 commit 7790c06

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

docs/change_log/release-3.3.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ The following new features have been included in the 3.3 release:
8181
maintain the current behavior in the rebuilt Markdown in HTML extension. A few random
8282
edge-case bugs (see the included tests) were resolved in the process (#803).
8383

84+
* An alternate method `markdown.extensions.headerid.slugify_unicode` has been included
85+
with the [Table of Contents](../extensions/toc.md) extension which supports Unicode
86+
characters in table fo contents slugs. The old `markdown.extensions.headerid.slugify`
87+
method which removes non-ASCII characters remains the default. Import and pass
88+
`markdown.extensions.headerid.slugify_unicode` to the `slugify` configuration option
89+
to use the new behavior.
90+
8491
## Bug fixes
8592

8693
The following bug fixes are included in the 3.3 release:

docs/extensions/toc.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ The following options are provided to configure the output:
202202

203203
The callable must return a string appropriate for use in HTML `id` attributes.
204204

205-
An alternate version of the default callable supporting Unicode strings is also provided as `markdown.extensions.headerid.slugify_unicode`.
205+
An alternate version of the default callable supporting Unicode strings is also
206+
provided as `markdown.extensions.headerid.slugify_unicode`.
206207

207208
* **`separator`**:
208209
Word separator. Character which replaces white space in id. Defaults to "`-`".

markdown/extensions/toc.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,16 @@
2323
import xml.etree.ElementTree as etree
2424

2525

26-
def _slugify(value, separator, encoding='ascii'):
26+
def slugify(value, separator, encoding='ascii'):
27+
""" Slugify a string, to make it URL friendly. """
2728
value = unicodedata.normalize('NFKD', value).encode(encoding, 'ignore')
2829
value = re.sub(r'[^\w\s-]', '', value.decode(encoding)).strip().lower()
29-
return re.sub(r'[%s\s]+' % separator, separator, value)
30-
31-
32-
def slugify(value, separator):
33-
""" Slugify a string, to make it URL friendly. """
34-
return _slugify(value, separator)
30+
return re.sub(r'[{}\s]+'.format(separator), separator, value)
3531

3632

3733
def slugify_unicode(value, separator):
38-
""" Slugify a string, to make it URL friendly. """
39-
return _slugify(value, separator, 'utf-8')
34+
""" Slugify a string, to make it URL friendly while preserving Unicode characters. """
35+
return slugify(value, separator, 'utf-8')
4036

4137

4238
IDCOUNT_RE = re.compile(r'^(.*)_([0-9]+)$')

0 commit comments

Comments
 (0)