Skip to content

Commit

Permalink
Merge pull request #535 from Crozzers/fix-non-ascii-header-ids
Browse files Browse the repository at this point in the history
Update `_slugify` to use utf-8 encoding (issue #534)
  • Loading branch information
nicholasserra authored Nov 9, 2023
2 parents 958eea4 + 756e024 commit b15d37d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [pull #527] Fix base64 images being corrupted in safe mode (issue #526)
- [pull #529] Add `breaks` extra with ability to hard break on backslashes (issue #525)
- [pull #532] Fix #493 persisting when `code-friendly` extra enabled
- [pull #535] Update `_slugify` to use utf-8 encoding (issue #534)

## python-markdown2 2.4.10

Expand Down
2 changes: 1 addition & 1 deletion lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2843,7 +2843,7 @@ def _slugify(value):
From Django's "django/template/defaultfilters.py".
"""
import unicodedata
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode()
value = unicodedata.normalize('NFKD', value).encode('utf-8', 'ignore').decode()
value = _slugify_strip_re.sub('', value).strip().lower()
return _slugify_hyphenate_re.sub('-', value)
## end of http://code.activestate.com/recipes/577257/ }}}
Expand Down
2 changes: 1 addition & 1 deletion test/tm-cases/header_ids_4.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- -*- coding: utf-8 -*- -->

<h1 id="fruit-really-likes">Fruit заголовок <em>really</em> likes</h1>
<h1 id="fruit-заголовок-really-likes">Fruit заголовок <em>really</em> likes</h1>

<ul>
<li>apples</li>
Expand Down
4 changes: 2 additions & 2 deletions test/tm-cases/toc_4.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1 id="python">Python</h1>

<h2 id="-1">蟒蛇</h2>
<h2 id="蟒蛇">蟒蛇</h2>

<ul>
<li>外形特性</li>
Expand All @@ -9,7 +9,7 @@ <h2 id="-1">蟒蛇</h2>

<h2 id="markdown">Markdown</h2>

<h2 id="-2">标记语言</h2>
<h2 id="标记语言">标记语言</h2>

<ul>
<li>类型</li>
Expand Down
4 changes: 2 additions & 2 deletions test/tm-cases/toc_4.toc_html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<ul>
<li><a href="#python">Python</a>
<ul>
<li><a href="#-1">蟒蛇</a></li>
<li><a href="#蟒蛇">蟒蛇</a></li>
<li><a href="#markdown">Markdown</a></li>
<li><a href="#-2">标记语言</a></li>
<li><a href="#标记语言">标记语言</a></li>
</ul></li>
</ul>

0 comments on commit b15d37d

Please sign in to comment.