Skip to content

Commit

Permalink
Fix #2982: Improve _HTMLWordTruncator (#3002)
Browse files Browse the repository at this point in the history
  • Loading branch information
manhhomienbienthuy committed Jul 11, 2022
1 parent 5c222ef commit d5d7920
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Release type: minor

* Use JSON values for extra settings in Invoke tasks template (#2994)
* Add content tag for links, which can help with things like Twitter social cards (#3001)
* Improve word count behavior when generating summary (#3002)
5 changes: 5 additions & 0 deletions pelican/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ def test_truncate_html_words(self):
'Ты мелькнула, ты предстала, Снова сердце задрожало,', 3
),
'Ты мелькнула, ты' + ' …')
self.assertEqual(
utils.truncate_html_words(
'Trong đầm gì đẹp bằng sen', 4
),
'Trong đầm gì đẹp' + ' …')

# Words enclosed or intervaled by HTML tags.
self.assertEqual(
Expand Down
5 changes: 1 addition & 4 deletions pelican/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,7 @@ def posixize_path(rel_path):

class _HTMLWordTruncator(HTMLParser):

_word_regex = re.compile(r"(({SBC})({SBC}|-|')*)|{DBC}".format(
# SBC means Latin-like characters. A word contains a few characters.
# ASCII |Extended Latin | Cyrillic
SBC="[0-9a-zA-Z]|[\u00C0-\u024f]|[\u0400-\u04FF]",
_word_regex = re.compile(r"{DBC}|(\w[\w'-]*)".format(
# DBC means CJK-like characters. An character can stand for a word.
DBC=("([\u4E00-\u9FFF])|" # CJK Unified Ideographs
"([\u3400-\u4DBF])|" # CJK Unified Ideographs Extension A
Expand Down

0 comments on commit d5d7920

Please sign in to comment.