diff --git a/pelican/tests/test_utils.py b/pelican/tests/test_utils.py index 3863ba32..b5b8b454 100644 --- a/pelican/tests/test_utils.py +++ b/pelican/tests/test_utils.py @@ -225,11 +225,11 @@ class TestUtils(LoggedTestCase): self.assertEqual( utils.truncate_html_words('�', 20), '�') self.assertEqual( - utils.truncate_html_words('&mdash', 20), '&mdash') + utils.truncate_html_words('&mdash text', 20), '&mdash text') self.assertEqual( - utils.truncate_html_words('Ӓ', 20), 'Ӓ') + utils.truncate_html_words('Ӓ text', 20), 'Ӓ text') self.assertEqual( - utils.truncate_html_words('઼', 20), '઼') + utils.truncate_html_words('઼ text', 20), '઼ text') def test_process_translations(self): fr_articles = [] diff --git a/pelican/utils.py b/pelican/utils.py index ab2e4a6e..f9c5eb3f 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -571,13 +571,12 @@ class _HTMLWordTruncator(HTMLParser): # - `1` (the length of `&`) # - `len(name)` (the length of `mdash`) # - `1` (the length of `;`) - # - `1` (required to go to the start of `suffix`) # # Note that, in case of malformed HTML, the ';' character may # not be present. offset = self.getoffset() - ref_end = offset + len(name) + 1 + 1 + ref_end = offset + len(name) + 1 try: if self.rawdata[ref_end] == ';': @@ -623,7 +622,7 @@ class _HTMLWordTruncator(HTMLParser): char = six.unichr(codepoint) except (ValueError, OverflowError): char = '' - self._handle_ref(name, char) + self._handle_ref('#' + name, char) def truncate_html_words(s, num, end_text='…'):